mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2014
Posts: 52
P
Babel fish
OP Offline
Babel fish
P
Joined: Mar 2014
Posts: 52
hi.
i want my twitch bot to giveaway something with a special keyword (that shouldnt be the problem, i think i will be able to make it on my own). right after chosing someone it should read a hashtable or .txt file and check if the person is in it.

now to the part thats too hard for me.
https://github.com/justintv/Twitch-API/b...schannelstarget

there is a url that checks if someone is following a channel or not.
if someone is not following it will display
Code:
{"error":"Not Found","status":404,"message":"_user_ is not following _channel_"}


i modified a script that gets random facts from a website.
will this work?
Code:
alias twitchfollow {
  if ($sock(twitchfollow)) { sockclose twitchfollow}
  %twitch1 = https://api.twitch.tv/kraken/users/
  %twitch2 = $nick
  %twitch3 = /follows/channels/_channel_
  sockopen twitchfollow %twitch1 $+ %nick $+ %twitch3 80
}

on *:sockopen:twitchfollow: {
  if ($sockerr) { 
    msg $chan problem encountered, pls try again
    sockclose twitchfollow
  }
  else {
    sockwrite -n $sockname GET / HTTP/1.0
    sockwrite -n $sockname Host: %twitch1 $+ %nick $+ %twitch3 $+ $crlf $+ $crlf
  }
}
on *:sockread:twitchfollow : {
  if ($sockerr) {
    msg $chan problem encountered, pls try again
    sockclose twitchfollow 
  }
  else {
    sockread %twitchinfo
    [color:#FF0000](if ..status != 404)[/color] {
      set %twitchfollow $left($htmlfree(%twitchinfo),-6)
    }
  }
}
on *:sockclose:twitchfollow : {
  if (%twitchfollow) {
    if ($hget(followers,$nick) = 0) {
      hadd -m followers $nick 1
    }
}
  unset %twitchinfo %twitchfollow 
}
alias htmlfree { return $regsubex($$1-,/^[^<]*>|<[^>]*>|<[^>]*$/g,) }



if this code is somewhat ok and is doing ok, i need help retrieving the information of the website. i highlighted "the problem" red. how can i check if it says 404 after "status":?
it could be possible if it only checks the first few letters, because when someone is following, the site will give out something else:
Code:
{"created_at":"2014-04-15T18:39:19Z","_links":{"self":"https://api.twitch.tv/kraken and so on..


i hope you guys understand what i mean :p
thanks in advance

Joined: Apr 2014
Posts: 191
B
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
I dont know how you would parse the data, so the code just show the output.

Code:
alias twitchfollow {
  if !$2 { echo -ag syntax: twitchfollow <nick> <#channel> | return }
  if $exists(temp.txt) { .remove temp.txt }
  sockclose twitchfollow
  sockopen -e twitchfollow api.twitch.tv 443
  sockmark twitchfollow $1 $2
}

on *:sockopen:twitchfollow: {
  if ($sockerr) { 
    echo -ag problem encountered, pls try again
  }
  else {
    tokenize 32 $sock($sockname).mark
    sockwrite -n $sockname GET $+(/kraken/users/,$1,/follows/channels/,$2) HTTP/1.1
    sockwrite -n $sockname Host: api.twitch.tv
    sockwrite -n $sockname Accept: application/vnd.twitchtv.v2+json 
    sockwrite -n $sockname Connection: close
    sockwrite -n $sockname $crlf
  }
}
on *:sockread:twitchfollow: {
  if ($sockerr) {
    echo -ag problem encountered, pls try again
  }
  else {
    var %r
    sockread %r 
    while %r { sockread %r } 
    sockread &r 
    while $bvar(&r,0) { 
      bwrite temp.txt -1 -1 &r
      sockread &r
    }
  }
}
on *:sockclose:twitchfollow: {
  if $exists(temp.txt) { run temp.txt }
  else { echo -ag Error: $sock($sockname) unable to retrieve data.. }
}



Link Copied to Clipboard