|
crreep
|
crreep
|
Hello,
I'm trying to make a script which will take data from a webpage and post it on irc.
I've managed to do it, but im not able to make it repeat its job multiple times.
This is what i tried:
alias mib { var %i = 0 %bitka = $1 while (%i <= 4) { $myb(%bitka) inc %i 1 } }
Alias "myb" works, it gets the data and posts it.
I tried to make it repeat what alias "myb" does 5 times, but it does it only once. Idealy i want it to keep posting that data until i turn it off, but i wanted to go with baby steps. Not successfuly though.
Help is appreciated. Thanks.
Last edited by crreep; 16/03/11 09:58 PM.
|
|
|
|
Joined: Sep 2005
Posts: 2,630
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,630 |
Please show us your myb alias.
|
|
|
|
crreep
|
crreep
|
alias myb {
set %tempchan $chan
%bitka = $1
set %kuda a
if ($sock(myb)) { .sockclose myb }
.sockopen myb www.erepublik.com 80
}
on *:sockopen:myb:{
.sockwrite -n $sockname GET /en/military/battle-log/ $+ %bitka HTTP/1.1
.sockwrite -n $sockname Host: www.erepublik.com
.sockwrite -n $sockname $crlf
}
on 1:SOCKREAD:myb: {
.sockread -f %temp
set %buffer %temp
while ($sockbr != 0) {
.sockread -f %temp
%buffer = %buffer %temp
}
if ($pos(%buffer,domination,1) > 0) {
%bi = $pos(%buffer,domination,1) + $len(domination)
%ei = $pos(%buffer,att,1)
%kuda = $mid(%buffer,$calc(%bi + 2),$calc(%ei - %bi - 4))
}
if (%kuda != a) {
if ($sock(myb)) { .sockclose myb }
msg %tempchan %bitka $+ : $left($calc(100 - %kuda),6) $+ % - $+ $chr(32) $+ $left(%kuda,6) $+ %
}
}
|
|
|
|
crreep
|
crreep
|
Made some tests, and it seems while loop in "mib" is too fast. Alias myb cant follow it. Tried using timer command but failed. Is there a way to slow the script down?
|
|
|
|
Joined: Sep 2005
Posts: 2,630
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,630 |
Why not start the next socket when you close the current one? alias myb {
set %tempchan $chan
%bitka = $1
set %kuda a
set %myb.i 5
if ($sock(myb)) { .sockclose myb }
.sockopen myb www.erepublik.com 80
}
on *:sockopen:myb:{
.sockwrite -n $sockname GET /en/military/battle-log/ $+ %bitka HTTP/1.1
.sockwrite -n $sockname Host: www.erepublik.com
.sockwrite -n $sockname $crlf
}
on 1:SOCKREAD:myb: {
.sockread -f %temp
set %buffer %temp
while ($sockbr != 0) {
.sockread -f %temp
%buffer = %buffer %temp
}
if ($pos(%buffer,domination,1) > 0) {
%bi = $pos(%buffer,domination,1) + $len(domination)
%ei = $pos(%buffer,att,1)
%kuda = $mid(%buffer,$calc(%bi + 2),$calc(%ei - %bi - 4))
}
if (%kuda != a) {
if ($sock(myb)) {
.sockclose myb
if (%myb.i) {
sockopen myb www.erepublik.com 80
dec %myb.i
}
}
msg %tempchan %bitka $+ : $left($calc(100 - %kuda),6) $+ % - $+ $chr(32) $+ $left(%kuda,6) $+ %
}
}
|
|
|
|
crreep
|
crreep
|
Thank you hixxy, but it seems that script is still too fast. It posts only one message. EDIT: i seem to have messed something up on first try, your solution works too hixxy, although its a bit too fast for what i need Ive managed to work something around with timers though.
alias myb {
set %tempchan $chan
%bitka = $1
set %kuda a
if ($sock(myb)) { .sockclose myb }
.sockopen myb www.erepublik.com 80
var %wait = 0
var %bleh = 0
while (%bleh <= 4) {
inc %wait 1
.timer 1 %wait mab
inc %bleh 1
}
}
alias mab {
if ($sock(myb)) { .sockclose myb }
.sockopen myb www.erepublik.com 80
} I would appreciate some help with making that alias repeat its job until i stop it. I would like some help with "stopping it" part. If it cant be done, any insight on how to do it by for example .start and .stop commands if i install it on a bot. Thanks EDIT: I found a "cheat". I set it to do a very high number of repetitions and just stop it by turning the timer off. While loop cant be stopped since it executes too fast but timer continues running. alias endit {
timer* off
}
Last edited by crreep; 17/03/11 12:54 AM.
|
|
|
|
Joined: Oct 2004
Posts: 8,061
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,061 |
You can use hixxy's code to start it after closing the socket. Just put a timer on the sockopen he put near the end of the script. .timermyb 0 5 sockopen myb www.erepublik.com 80 You can adjust the 5 to whatever number of seconds you want to let it wait before repeating. Then, to end the timer, use: /timermyb off
|
|
|
|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
You may not need a timer to open another socket. You can use the sockclose event to open a new one, along with the use of .sockwrite -n $sockname Connection: close Then: on 1:SOCKCLOSE:myb:{ sockopen myb http://www.erepublik.com 80 ....
|
|
|
|
Joined: Sep 2005
Posts: 2,630
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,630 |
You could just add a delay to the code I gave you in this: alias myb {
set %tempchan $chan
%bitka = $1
set %kuda a
set %myb.i 5
if ($sock(myb)) { .sockclose myb }
.sockopen myb www.erepublik.com 80
}
on *:sockopen:myb:{
.sockwrite -n $sockname GET /en/military/battle-log/ $+ %bitka HTTP/1.1
.sockwrite -n $sockname Host: www.erepublik.com
.sockwrite -n $sockname $crlf
}
on 1:SOCKREAD:myb: {
.sockread -f %temp
set %buffer %temp
while ($sockbr != 0) {
.sockread -f %temp
%buffer = %buffer %temp
}
if ($pos(%buffer,domination,1) > 0) {
%bi = $pos(%buffer,domination,1) + $len(domination)
%ei = $pos(%buffer,att,1)
%kuda = $mid(%buffer,$calc(%bi + 2),$calc(%ei - %bi - 4))
}
if (%kuda != a) {
if ($sock(myb)) {
.sockclose myb
if (%myb.i) {
.timer 1 $calc(6 - %myb.i) sockopen myb www.erepublik.com 80
dec %myb.i
}
}
msg %tempchan %bitka $+ : $left($calc(100 - %kuda),6) $+ % - $+ $chr(32) $+ $left(%kuda,6) $+ %
}
} This line: .timer 1 $calc(6 - %myb.i) sockopen myb www.erepublik.com 80 Will make sure the next socket is called with a 1 second delay after the current one.
|
|
|
|
Joined: Oct 2004
Posts: 8,061
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,061 |
You may not need a timer to open another socket. Right, but the OP said it was faster than he wanted. The timer allows slowing it down.
|
|
|
|
|