mIRC Homepage
Posted By: DuXxXieJ randommessages.com socket read - 21/07/11 05:56 PM
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>
Posted By: Tomao Re: randommessages.com socket read - 21/07/11 08:20 PM
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)
  }
}
Posted By: DuXxXieJ Re: randommessages.com socket read - 21/07/11 08:23 PM
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
Posted By: Riamus2 Re: randommessages.com socket read - 21/07/11 08:29 PM
Why are you using tokenize? It isn't giving you any benefit.
Posted By: Tomao Re: randommessages.com socket read - 21/07/11 08:30 PM
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 
  }
 }
}
Posted By: DuXxXieJ Re: randommessages.com socket read - 21/07/11 09:34 PM
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
Posted By: DuXxXieJ Re: randommessages.com socket read - 21/07/11 09:35 PM
@Riamsus, I don't know, I just got it from a tutorial.
Posted By: Tomao Re: randommessages.com socket read - 21/07/11 10:05 PM
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.
Posted By: Riamus2 Re: randommessages.com socket read - 21/07/11 10:33 PM
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
© mIRC Discussion Forums