mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2007
Posts: 280
Fjord artisan
OP Offline
Fjord artisan
Joined: Jan 2007
Posts: 280
I'm wondering how to read (every 15 minutes) the random message from http://www.randommessages.com/ using sockets.

This is what I got so far:

Code:
alias ver {
  timer 1 1 sockclose random 
  timer 1 1 sockopen random randommessages.com 80
  inc %socket 1
  msg #dj-serv socket read %socket
}

on *:sockopen:random:{ 
  sockwrite -n $sockname GET / HTTP/1.1 
  sockwrite -n $sockname Host: randommessages.com $+ $str($crlf ,2)
}
on *:sockread:random:{ 
  sockread %temp 
  if <h1> isin %temp { timer 1 1 msg #dj-serv found <h1> ! | timer 1 1 msg #dj-serv I want that h1 line here :( something with $matchtok ?  } 
}



I've made this using a tutorial xD, just now have to get the rest of it, the random message between <h1> and </h1>

Last edited by DuXxXieJ; 21/07/11 07:42 PM.

Squee whenever a squee squee's. Squee whenever a squee does not squee.
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Code:
alias ver {
  sockclose random 
  sockopen random randommessages.com 80
}
on *:sockopen:random:{ 
  sockwrite -n $sockname GET / HTTP/1.1 
  sockwrite -n $sockname Host: randommessages.com $+ $str($crlf ,2)
}
on *:sockread:random:{
  var %temp 
  sockread %temp 
  if (<h1> isin %temp) {
    msg #dj-serv $gettok($mid(%temp,1,-5),-1,62)
  }
}

Joined: Jan 2007
Posts: 280
Fjord artisan
OP Offline
Fjord artisan
Joined: Jan 2007
Posts: 280
Code:

ON *:TEXT:*:#DJ-Serv:{
if $1 == .random {
  timer 1 1 sockclose random 
  timer 1 1 sockopen random randommessages.com 80
}
}

on *:sockopen:random:{ 
  sockwrite -n $sockname GET / HTTP/1.1 
  sockwrite -n $sockname Host: randommessages.com $+ $str($crlf ,2)
}
on *:sockread:random:{ 
  if ($sockerr) { halt }
  else {
    var %sockreader
    sockread %sockreader
    if (<h1>*</h1>* iswm %sockreader) {
      tokenize 32 %sockreader
      msg #dj-serv $remove($1-,<h1>,</h1>) 
      sockclose random
    }
  }
}



I've got it, it works, just maybe not as it should be, but it does.

Maybe any ideas to improve it? I'm a beginner


Squee whenever a squee squee's. Squee whenever a squee does not squee.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Why are you using tokenize? It isn't giving you any benefit.


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
I don't know why all the timers are needed. You don't really need to tokenize:
Code:
on *:sockread:random:{
  if ($sockerr) { halt }
  else {
  var %sockreader
  sockread %sockreader
  if (<h1> isin %sockreader) {
    msg #dj-serv $remove($v2,<h1>,</h1>)
    sockclose random 
  }
 }
}

Last edited by Tomao; 21/07/11 08:31 PM.
Joined: Jan 2007
Posts: 280
Fjord artisan
OP Offline
Fjord artisan
Joined: Jan 2007
Posts: 280
Okay thanks, I just want it to have it say the random message in a delay of 30 minutes. I can't get that work, my bot is freaking out when I try the timers, any idea?

ex.

on start { do something to make it open the socket every 30 minutes and then halt }

or something

Last edited by DuXxXieJ; 21/07/11 09:35 PM.

Squee whenever a squee squee's. Squee whenever a squee does not squee.
Joined: Jan 2007
Posts: 280
Fjord artisan
OP Offline
Fjord artisan
Joined: Jan 2007
Posts: 280
@Riamsus, I don't know, I just got it from a tutorial.


Squee whenever a squee squee's. Squee whenever a squee does not squee.
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Originally Posted By: DuXxXieJ
I just want it to have it say the random message in a delay of 30 minutes.
Code:
on me:*:quit: .timerrandom off
on me:*:part:#: .timerrandom off
on me:*:join:#: .timerrandom 0 1800 random
alias -l random {
  sockclose random 
  sockopen random randommessages.com 80
}
on *:sockopen:random:{ 
  sockwrite -n $sockname GET / HTTP/1.1 
  sockwrite -n $sockname Host: randommessages.com $+ $str($crlf ,2)
}
on *:sockread:random:{
  if ($sockerr) { halt }
  else {
  var %sockreader
  sockread %sockreader
  if (<h1> isin %sockreader) {
    msg #dj-serv $remove($v2,<h1>,</h1>)
    sockclose random 
  }
 }
}
When you join, the timer will start every 30 mins to trigger the socket.

Last edited by Tomao; 21/07/11 10:09 PM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
So that you understand, /tokenize lets you take data and separate it into parts, where each part is separated by the character you specify. For example, you can split "a,list,of,words" into $1 through $4 by using /tokenize 44 and that data (44 refers to $chr(44), which is a comma). $1 would then be "a", $2 would be "list", etc. This can be useful when you need to work with specific parts of the data, or to use each part individually (or in groups).

The way you used it, you were separating the variable's data into parts (separated by spaces) and then working with $1-. $1- is every part. If you are going to use every part, there's no need to split it up. $remove() works on the %variable just fine without needing to make the variable into $1-.

I'd recommend reading some about the various token commands. They are very useful and aren't too difficult to learn.

/help token identifiers
/help /tokenize


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard