mIRC Homepage
Posted By: Joveice I need help with reading info from site - 27/07/15 05:04 PM
i found this site http://albinstuff.net/twitch2.php?id=joveice&follows=am3ricanjackal who post True or False
and i want to make a command !check $nick and i want it to say If he is follower or not
http://albinstuff.net/twitch2.php?id=$NameTocheckiffollows&follows=$Channeltofollow

anyone that could help with socketopen and all this?
Posted By: Wims Re: I need help with reading info from site - 27/07/15 05:36 PM
Code:
on *:text:!check &:#:{
  var %n 1,%s
  while ($sock(isfollowing $+ %n)) inc %n
  %s = isfollowing $+ %n
  sockclose %n
  sockopen %n albinstuff.net 80
  sockmark %n $2 $chan 
}
on *:sockopen:isfollowing*:{
  tokenize 32 $sock($sockname).mark
  if ($sockerr) msg $2 Can't connect to website
  else {
    var %s sockwrite -n $sockname
    %s GET /twitch2.php?id=joveice&follows= $+ $urlencode($1)
    %s Host: albinstuff.net
    %s
  }
}

on *:sockread:isfollowing*:{
  var %a
  tokenize 32 $sock($sockname).mark
  if ($sockerr) msg $2 An error occured while reading.
  else {
    if (!$3) {
      sockread %a
      if (!$sockbr) return
      if (%a == $null) sockmark $sockname $1-2 1
    }
    else {
     sockread -f %a
     if ($sockbr) msg $2 Result for $1: %a
    }
  }
}
alias -l urlencode return $regsubex($1, /(\W)/g, $+(%, $base($asc(\t), 10, 16, 2)))

I didn't try it.
Posted By: Joveice Re: I need help with reading info from site - 27/07/15 08:58 PM
Does not look like it works
tryed !check , !check joveice !check am3ricanjackal
it does not output any text in mirc or the channel, tho it does not have any error messages in mirc
Originally Posted By: Wims
Code:
on *:text:!check &:#:{
  var %n 1,%s
  while ($sock(isfollowing $+ %n)) inc %n
  %s = isfollowing $+ %n
  sockclose %n
  sockopen %n albinstuff.net 80
  sockmark %n $2 $chan 
}
on *:sockopen:isfollowing*:{
  tokenize 32 $sock($sockname).mark
  if ($sockerr) msg $2 Can't connect to website
  else {
    var %s sockwrite -n $sockname
    %s GET /twitch2.php?id=joveice&follows= $+ $urlencode($1)
    %s Host: albinstuff.net
    %s
  }
}

on *:sockread:isfollowing*:{
  var %a
  tokenize 32 $sock($sockname).mark
  if ($sockerr) msg $2 An error occured while reading.
  else {
    if (!$3) {
      sockread %a
      if (!$sockbr) return
      if (%a == $null) sockmark $sockname $1-2 1
    }
    else {
     sockread -f %a
     if ($sockbr) msg $2 Result for $1: %a
    }
  }
}
alias -l urlencode return $regsubex($1, /(\W)/g, $+(%, $base($asc(\t), 10, 16, 2)))

I didn't try it.
Posted By: Wims Re: I need help with reading info from site - 27/07/15 11:02 PM
I made an unfortunate typo
Code:
sockclose %n
sockopen %n albinstuff.net 80
sockmark %n $2 $chan 
Change %n by %s

Also, what should !check, without a name (or two) after it, do?
I didn't realize you wanted the id= parameter to be dynamic
You need to describe how you want the on text event to work, because it looks like you want to be able to omit some parameters.
Posted By: Joveice Re: I need help with reading info from site - 28/07/15 11:37 AM
Ok what i want is on !check <name> it will check <name> with $chan if it follows it so it works on the channel its on, Etc im in my channel and i do !check test, if test now follows me it will output test is a follower if not: test does not follow and i do want it to be if true then it makes %istrue = true or %istrue = false. so i can add stuff like if (%istrue == false {
somthing
}
Let me know if you need more info or that i need to explain it on another way
Originally Posted By: Wims
I made an unfortunate typo
Code:
sockclose %n
sockopen %n albinstuff.net 80
sockmark %n $2 $chan 
Change %n by %s

Also, what should !check, without a name (or two) after it, do?
I didn't realize you wanted the id= parameter to be dynamic
You need to describe how you want the on text event to work, because it looks like you want to be able to omit some parameters.
Posted By: Wims Re: I need help with reading info from site - 28/07/15 03:49 PM
Code:
on *:text:!check &:#:{
  var %n 1,%s
  while ($sock(isfollowing $+ %n)) inc %n
  %s = isfollowing $+ %n
  sockclose %s
  sockopen %s albinstuff.net 80
  sockmark %s $2 $chan 
}
on *:sockopen:isfollowing*:{
  tokenize 32 $sock($sockname).mark
  if ($sockerr) msg $2 Can't connect to website
  else {
    var %s sockwrite -n $sockname
    %s GET $+(/twitch2.php?id=,$urlencode($1),&follows=,$urlencode($2))
    %s Host: albinstuff.net
    %s
  }
}

on *:sockread:isfollowing*:{
  var %a
  tokenize 32 $sock($sockname).mark
  if ($sockerr) msg $2 An error occured while reading.
  else {
    if (!$3) {
      sockread %a
      if (!$sockbr) return
      if (%a == $null) sockmark $sockname $1-2 1
    }
    else {
      sockread -f %a
      if ($sockbr) {
        if (%a == true) msg $2 $1 is a follower
        else msg $2 $1 is not a follower
      }
    }
  }
}
alias -l urlencode return $regsubex($1, /(\W)/g, $+(%, $base($asc(\t), 10, 16, 2)))

That should do it, however I didn't set any %istrue variable because it wouldn't make sense to do so (or it doesn't make sense to me), because that true/false value could change with the next check I suppose.
If you want to do more than sending a message to the channel according to the result, do so in the on sockread event:
Code:
if (%a == true) {
 msg $2 $1 is a follower
 set %istrue true
}
else {
 msg $2 $1 is not a follower
 set %istrue false
}
Posted By: Plornt Re: I need help with reading info from site - 28/07/15 08:48 PM
I suspect that theres still a small detail that OP left out (not sure if I am remembering twitches IRC incorrectly though). The channel on twitch IRC has a # prepended to it. So you may need to change:

Code:
%s GET $+(/twitch2.php?id=,$urlencode($1),&follows=,$urlencode($2))


To:

Code:
%s GET $+(/twitch2.php?id=,$urlencode($1),&follows=,$urlencode($right($2,$calc($len($2) - 1))))


If Wims code doesnt work.
Posted By: Wims Re: I need help with reading info from site - 28/07/15 09:02 PM
Good point, I'm lucky that http://albinstuff.net/twitch2.php?id=joveice&follows=am3ricanjackal and http://albinstuff.net/twitch2.php?id=joveice&follows=#am3ricanjackal return the same, the removal of the # is handled by the website :p
Posted By: Plornt Re: I need help with reading info from site - 28/07/15 09:11 PM
Originally Posted By: Wims
Good point, I'm lucky that http://albinstuff.net/twitch2.php?id=joveice&follows=am3ricanjackal and http://albinstuff.net/twitch2.php?id=joveice&follows=#am3ricanjackal return the same, the removal of the # is handled by the website :p


Aha! Fair enough :P Just thought I'd put in a mention just in case. Nice work anyhow.
Posted By: Joveice Re: I need help with reading info from site - 02/08/15 12:10 AM
I might have been unclear, if so im sorry.
when i do !check test2 i want it to check if test2 follows my channel, (the channel the command is triggered in)
Right now the !check returns Is following to what ever i put in to it, so im not sure whats wrong, could you please look over it ?:)
Posted By: Joveice Re: I need help with reading info from site - 03/08/15 03:46 PM
Originally Posted By: Plornt
I suspect that theres still a small detail that OP left out (not sure if I am remembering twitches IRC incorrectly though). The channel on twitch IRC has a # prepended to it. So you may need to change:

Code:
%s GET $+(/twitch2.php?id=,$urlencode($1),&follows=,$urlencode($2))


To:

Code:
%s GET $+(/twitch2.php?id=,$urlencode($1),&follows=,$urlencode($right($2,$calc($len($2) - 1))))


If Wims code doesnt work.

ok thank you this works!
© mIRC Discussion Forums