mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2015
Posts: 8
A
aborge Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Jan 2015
Posts: 8
Hello!
I have made a twitchbot that you can add/delete custom commands to stored in a file. Instead of posting all commands in the twitch chat I want it to post them to hastebin. I have managed to do so, and I save the link to a global variable. The problem is however that my bot post the previous link to twitchchat instead of the newest. after my bot posts in twitchchat, i check my global variables and %hastelink is the newest link. Somehow my bot posts the old link before it gets updated.
Here is some of my code:

Code:
;## the http alias is working as intended and post the variable,  then find the key using socketread and sets the link to a global variable.
/http post http://hastebin.com/documents/ %allcoms
msg $chan Volcania Custom commands: %hastelink


I can add the socketread too so you see how i set the global variable:
Code:
on *:sockread:http.*:{
  var %http.read
  sockread %http.read
  tokenize 32 %http.read
  if (!$1) return
  .signal -n http $1-
  if (HTTP/1.* 200 OK iswm $1-) echo $color(info) -s HTTP $hget(http,method) request to $hget(http,url) successful!

  while ($sockbr) {
    if (*{"key":* iswm %http.read) {
      unset %hastelink
      unset %hastekey
      set %hastekey $gettok($gettok(%http.read,4,34),1,44)
      set %hastelink http://hastebin.com/ $+ %hastekey
      echo -s Key : %hastelink
    }
    sockread %http.read
  }
}


Joined: Jun 2014
Posts: 248
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
You need to post the whole script if you want it troubleshooted.

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
From his first code I'll assume he's calling the http alias and then immediately trying to message the channel. It doesn't work like that, none of the socket events have run at that point.

Joined: Jan 2015
Posts: 8
A
aborge Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Jan 2015
Posts: 8
Hey! And thank you for your reply.
Alright, i didnt know that the socket events have not run at that point. I can post the whole code to you.

Yes i am calling the http alias and message the channel after that. Can you tell me another way to first run the alias which starts all the socket events, and then message the channel after the global variable %hastelink is updated with the new link?


Here is all of the code for the http post script file. In another file I have the "on text" event that is calling the http alias as you see in my first post
Code:
Code:
on *:sockopen:http.*:{
  if (!$window(@http)) window -ek0 @http
  if ($sockerr) || (!$sock($sockname)) return
  if (/* !iswm $http.parse($hget(http,url)).path) { var %path / $+ $http.parse($hget(http,url)).path }
  else { var %path $http.parse($hget(http,url)).path }
  sockwrite -n $sockname $hget(http,method) %path HTTP/1.1
  sockwrite -n $sockname Accept: */*
  sockwrite -n $sockname Content-Type: application/x-www-form-urlencoded
  sockwrite -n $sockname User-Agent: mIRC $version
  sockwrite -n $sockname Host: $http.parse($hget(http,url)).host
  sockwrite -n $sockname Content-Length: $len( $hget(http,data) )
  sockwrite -n $sockname Connection: Keep-Alive
  sockwrite -n $sockname Cache-Control: no-cache
  sockwrite -n $sockname
  if ($hget(http,method) == post) { sockwrite -n $sockname $hget(http,data) }
  sockwrite -n $sockname $crlf $+ $crlf
}
on *:sockread:http.*:{
  var %http.read
  sockread %http.read
  tokenize 32 %http.read
  if (!$1) return
  .signal -n http $1-
  if (HTTP/1.* 200 OK iswm $1-) echo $color(info) -s HTTP $hget(http,method) request to $hget(http,url) successful!

  while ($sockbr) {
    if (*{"key":* iswm %http.read) {
      unset %hastelink
      var %hastekey = $gettok($gettok(%http.read,4,34),1,44)
      set %hastelink http://hastebin.com/ $+ %hastekey
      echo -s Key : %hastelink
    }
    sockread %http.read
  }
}
on 1:sockclose:http.*:{
  .signal -n http Connection to $sock($sockname).ip has been closed remotely
}

alias http {
  if (!$regex($1-,(post|get) http://(.+)/(.*))) {
    echo $color(info) -at Usage: /http <post|get> <url> [data]
    echo $color(info) -at url has to match http://*/* and must not contain spaces!
    return
  }
  hadd -m http url $2
  hadd -m http method $upper($1)
  if ($3) hadd http data $3-
  if ($sock($+(http.,$1))) .sockclose $+(http.,$1)
  sockopen $+(http.,$1) $http.parse($2).host 80
}
alias http.parse {
  if ($regex($1-,^http://([^/]+)(/.*))) {
    if ($prop == host) return $regml(1)
    if ($prop == path) return $iif(($regml(2)),$regml(2),/)
  }
}
on *:SIGNAL:http:{

  /*
  if (!$window(@http)) window -ek0 @http
  echo @http < $1-
  */
  /*
  write http.log $1-
  */
}


Last edited by aborge; 14/01/15 11:44 PM.
Joined: Jan 2015
Posts: 8
A
aborge Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Jan 2015
Posts: 8
Originally Posted By: Loki12583
From his first code I'll assume he's calling the http alias and then immediately trying to message the channel. It doesn't work like that, none of the socket events have run at that point.


Hey, dont know if u saw my new message! Do you have any solution?

Joined: Sep 2014
Posts: 259
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
Use something like .timer 1 1 msg #

Or if that doens't work, split the alias in two aliases and use a timer before running the 2nd part

Joined: Jun 2014
Posts: 248
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
Send the message after you set the global variable?

Joined: Jan 2015
Posts: 8
A
aborge Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Jan 2015
Posts: 8
Originally Posted By: Belhifet
Send the message after you set the global variable?


thats what i do but it doesnt work

Joined: Jan 2015
Posts: 8
A
aborge Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Jan 2015
Posts: 8
Originally Posted By: Sakana
Use something like .timer 1 1 msg #

Or if that doens't work, split the alias in two aliases and use a timer before running the 2nd part


I tried the timer, but that didnt work.
what do you mean by the splitting?
what part of the alias should I put in each other alias? Do you mean the http alias, then a timer, then the message alias where it only sends the message to chat?

Joined: Sep 2014
Posts: 259
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
Do the msg # under the sockread event? Otherwise I think you need to do something like

Code:
alias test { 
http
.timer 1 2 test2
}

alias test2 {

msg #

}

Last edited by Sakana; 18/01/15 02:46 PM.
Joined: Jan 2015
Posts: 8
A
aborge Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
A
Joined: Jan 2015
Posts: 8
Tried that thing, but didnt work

However I got it to work by putting the msg into the socketread and made a global variable for the current channel that I can put in there instead of msg $chan or msg #

Thank you


Link Copied to Clipboard