All pastes #899209 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-02-10 23:41 UTC
rendered paste body
#-> mIRC Socket Bot by KnickLighter
#-> Named as 'sBot.mIRC'
#-> Leave these 3 lines ALWAYS in this script.

#-> Configuration:


#-> Server/DNS to connect to:
alias sbot.server return        { BLA BLA }

#-> Port to connect to:
alias sbot.port return          { 31337 }

#-> Server password (leave blank if not used):
alias sbot.serverpass return    { }

#-> Bot's nickname
alias sbot.nick return          { sBot }

#-> NickServ password
alias sbot.nspass return        { }

#-> Channel to join:
alias sbot.channel return       { #root }

#-> Channel password (leave blank if not used):
alias sbot.chankey return       { }

#-> On-Join message to send:
alias sbot.onjoinmsg return     { [sBot.mIRC]: A mIRC SocketBot by KnickLighter }


#-> Admin nickname:
alias sbot.admin.nick return    { KnickLighter }

#-> Admin hostname:
alias sbot.admin.host return    { *@KnickLighter.is.online }


#-> An alias for debugging
alias sbot.db {
  window -e @sBot
  echo @sBot $time([HH:nn:ss]) $+(-sBot:,$1,-) $2-
}

#-> Sockwrite raw alias
alias sraw {
  sockwrite -nt sBot $1-
  if (%sbot.bwcalc == on) { write sbot.bw.out $1- }
}

#-> Sockwrite PRIVMSG alias
alias smsg {
  sockwrite -nt sBot PRIVMSG $1 : $+ $2-
  if (%sbot.bwcalc == on) { write sbot.bw.out PRIVMSG $1 : $+ $2- }
}

#-> Sockwrite NOTICE alias
alias snotice {
  sockwrite -nt sBot NOTICE $1 : $+ $2-
  if (%sbot.bwcalc == on) { write sbot.bw.out NOTICE $1 : $+ $2- }
}

#-> Connect Command alias
alias sbot.conncmd {
  sbot.db msg Connected, sending authentication commands...
  sraw NICK $sbot.nick
  sraw USER sBot x x :sBot by KnickLighter
  sraw PASS xxxxxxxx
  sraw NICKSERV identify $sbot.nspass
  sraw JOIN $sbot.channel $sbot.chankey
  if ($sbot.onjoinmsg != $null) { smsg $sbot.channel $sbot.onjoinmsg }
  halt
}

#-> The '/sbot' alias to start/stop the bot:
alias sBot {
  ;-> Start command
  if ($1 == start) {

    ;-> Clear logs for bandwidth
    write -c sbot.bw.in
    write -c sbot.bw.out

    ;-> Clear the sBot window
    .clear @sBot

    ;-> Check if the socket is already in use
    if ($sock(sBot) != $null) {
      sbot.db error Cannot create socket: Already in use.
      halt
    }

    ;-> The script will end up here when the socket isn't in use
    ;-> So let's create the socket
    sockopen sBot $sbot.server $sbot.port
    sbot.db msg Bot started. The socket has been opened...
    ;-> When the socket has been opened, we go further processing this at the 'SOCKOPEN' event
    halt
  }

  ;-> Stop command
  if ($1 == stop) {

    ;-> Clear logs for bandwidth
    write -c sbot.bw.in
    write -c sbot.bw.out

    ;-> First we check if the socket is open, if so; close it, if not; tell us
    if ($sock(sBot) != $null) {
      sockclose sBot
      sbot.db msg Bot stopped. The socket has been closed...
      halt
    }

    ;-> Tell us the bot isn't running
    else {
      sbot.db error Bot isn't running.
      halt
    }
  }

  ;-> Restart
  if ($1 == restart) { sockclose sBot | sockopen sBot $sbot.server $sbot.port | sbot.db msg Bot started. The socket has been opened... }

  ;-> What to do when none of the above commands are entered or the input is blank
  else {
    sbot.db error Syntax: /sBot <start/stop>
    halt
  }
}

#-> An alias to check if the socket's cmd target is a channel
alias ischannel {
  if ($left($1,1) == $chr(35)) || ($left($1,1) == $chr(38)) { return $true | halt }
  else { return $false | halt }
}

#-> The sockopen event
on *:sockopen:sBot:{

  ;-> Check wether it connects or not
  if ($sockerr > 0) {

    ;-> Close the socket and send error
    sockclose $sockname
    sbot.db error Could not connect to the server, aborting and closing socket...
    halt
  }

  ;-> Send commands to IRC server
  .timer 1 5 sbot.conncmd
}

#-> The sockread event
on *:sockread:sBot:{

  ;-> Read the socket's message and process it into a variable
  sockread %sbot.read

  ;-> Debug (disable if not necessary)
  sbot.db raw %sbot.read
  if (%sbot.bwcalc == on) { write sbot.bw.in %sbot.read }

  ;-> Respond to the ping command
  if ($gettok(%sbot.read,1,32) == PING) { ;smsg #home God damnit, I've just received a PING! Let's PONG back! | sraw PONG $gettok(%sbot.read,2-,32) | halt }


  ;-> Debugging of numeric raws
  if ($gettok(%sbot.read,2,32) isnum) {

    ;-> Setting the variables
    set %sbot.num.raw $gettok(%sbot.read,2,32)
    set %sbot.num.1 $gettok(%sbot.read,3,32)
    set %sbot.num.2 $gettok(%sbot.read,4,32)
    set %sbot.num.3 $gettok(%sbot.read,5-,32)

    ;-> Processing commands
    ;-> Nickname already in use
    if (433 == %sbot.num.raw) {
      if (%sbot.num.2 == $sbot.nick) { sraw NICK $sbot.nick $+ _ }
      if (%sbot.num.2 == $sbot.nick $+ _) { sbot.db error First and second nickname already in use. Disconnecting. | sbot stop | halt }
      else { sraw NICK $sbot.nick }
    }

    ;-> If the bot couldn't register, resend commands and echo error
    if (451 == %sbot.num.raw) {
      sbot.db error Bot didn't register. If this error keeps coming, please check the server.
      .timer 1 5 sbot.conncmd
      if ($sbot.onjoinmsg != $null) { smsg $sbot.channel $sbot.onjoinmsg }
    }

    ;-> Notify
    if (600 == %sbot.num.raw) { smsg $sbot.channel [notify]: %sbot.num.2 ( $+ $gettok(%sbot.num.3,1,32) $+ @ $+ $gettok(%sbot.num.3,2,32) $+ ) is online | halt }
    if (601 == %sbot.num.raw) { smsg $sbot.channel [notify]: %sbot.num.2 ( $+ $gettok(%sbot.num.3,1,32) $+ @ $+ $gettok(%sbot.num.3,2,32) $+ ) is offline | halt }
    if (604 == %sbot.num.raw) { ;smsg $sbot.channel [notify]: %sbot.num.2 ( $+ $gettok(%sbot.num.3,1,32) $+ @ $+ $gettok(%sbot.num.3,2,32) $+ ) is online | halt }
    if (605 == %sbot.num.raw) { ;smsg $sbot.channel [notify]: %sbot.num.2 is offline | halt }

    ;-> Private Message Emulation
    if (401 == %sbot.num.raw) && (%sbot.num.2 == %sbot.pemu) {
      unset %sbot.pemu
      smsg $sbot.channel [pEmu]: Deactivated, user is offline.
      halt
    }

  }

  ;-> Set variables for debugging
  ;-> Nickname
  set %sbot.sock.nick $mid($gettok($gettok(%sbot.read,1,32),1,33),2-)
  ;-> Hostname
  set %sbot.sock.host $gettok($gettok(%sbot.read,1,32),2,33)
  ;-> Event
  set %sbot.sock.event $gettok(%sbot.read,2,32)
  ;-> Target
  set %sbot.sock.target $gettok(%sbot.read,3,32)
  ;-> Text
  set %sbot.sock.text $mid($gettok(%sbot.read,4-,32),2-)

  ;-> Split text in 1) command 2) the rest
  set %sbot.sock.cmd $gettok(%sbot.sock.text,1,32)
  set %sbot.sock.rest $gettok(%sbot.sock.text,2-,32)


  ;-> Block private messages to the bot.
  if (%sbot.sock.target == $sbot.nick) {
    if (%sbot.sock.cmd == VERSION) {
      smsg %sbot.sock.nick VERSION sBot v1.1 for mIRC by KnickLigter
    }

    ;-> Private Message emulation to channel
    if (%sbot.sock.nick == %sbot.pemu) {
      smsg $sbot.channel [pEmu]: < $+ %sbot.sock.nick $+ > %sbot.sock.text
    }
  }


  ;-> !!! Admin bot commands
  if (%sbot.sock.nick == $sbot.admin.nick) && ($sbot.admin.host iswm %sbot.sock.host) {

    ;-> The .help command
    if (.help == %sbot.sock.cmd) { snotice %sbot.sock.nick [sBot]: There is currently no help available. | halt }

    ;-> Some admin commands
    if (.join == %sbot.sock.cmd) { sraw JOIN %sbot.sock.rest | halt }
    if (.part == %sbot.sock.cmd) { sraw PART %sbot.sock.rest | halt }
    ;-> Raw IRC command
    if (.raw == %sbot.sock.cmd) { sraw %sbot.sock.rest | halt }
    ;-> Disconnects the bot
    if (.die == %sbot.sock.cmd) { sbot stop | halt }
    ;-> Restarts the bot
    if (.restart == %sbot.sock.cmd) { sbot restart | halt }

    ;-> Op/deop example
    if (.op == %sbot.sock.cmd) { sraw MODE %sbot.sock.target +o %sbot.sock.rest | halt }
    if (.deop == %sbot.sock.cmd) { sraw MODE %sbot.sock.target -o %sbot.sock.rest | halt }    

    ;-> You can place more commands for the admin here

    if (.quotes == %sbot.sock.cmd) { snotice %sbot.sock.nick [Quotes]:  $+ $lines(quotes.txt) Quotes in QuoteDB. File is: $bytes($file(quotes.txt)).suf $+  | halt }

    if (.addquote == %sbot.sock.cmd) {
      if (%sbot.sock.rest == $null) { snotice %sbot.sock.nick [AddQuote]: I can't add empty quotes. | halt }
      write quotes.txt %sbot.sock.rest
      snotice %sbot.sock.nick [AddQuote]: Quote has been added, DB contains  $+ $lines(quotes.txt) Quotes. File is: $bytes($file(quotes.txt)).suf $+ 
      smsg %sbot.sock.target [Quote ( $+ $lines(quotes.txt) $+ ) $+ ]: $read(quotes.txt,$lines(quotes.txt))
      halt
    }

    if (.delquote == %sbot.sock.cmd) {
      if (%sbot.sock.rest == $null) { snotice %sbot.sock.nick [DelQuote]: Please enter quote number. | halt }
      if (%sbot.sock.rest !isnum) { snotice %sbot.sock.nick [DelQuote]: No number given. | halt }
      if (%sbot.sock.rest > $lines(quotes.txt)) { snotice %sbot.sock.nick [DelQuote]: QuoteDB has only $lines(quotes.txt) quotes. | halt }
      snotice %sbot.sock.nick [DelQuote]: Deleting " $+ $read(quotes.txt,%sbot.sock.rest) $+ "...
      write -dl $+ %sbot.sock.rest quotes.txt
      snotice %sbot.sock.nick [DelQuote]: Quote %sbot.sock.rest has been deleted.
      halt
    }

    if (.bw == %sbot.sock.cmd) {
      if (%sbot.sock.rest == in) { snotice %sbot.sock.nick [BW]: Received; $lines(sbot.bw.in) lines ( $+ $bytes($file(sbot.bw.in)).suf $+ ) | halt }
      if (%sbot.sock.rest == out) { snotice %sbot.sock.nick [BW]: Sent; $lines(sbot.bw.out) lines ( $+ $bytes($file(sbot.bw.out)).suf $+ ) | halt }
      if (%sbot.sock.rest == on) { set %sbot.bwcalc on | write -c sbot.bw.in | write -c sbot.bw.out | snotice %sbot.sock.nick [BW]: Calculation enabled. | halt }
      if (%sbot.sock.rest == off) { set %sbot.bwcalc off | write -c sbot.bw.in | write -c sbot.bw.out | snotice %sbot.sock.nick [BW]: Calculation disabled. | halt }
      if (%sbot.sock.rest == reset) { write -c sbot.bw.in | write -c sbot.bw.out | snotice %sbot.sock.nick [BW]: Cleared. | halt }
      if (%sbot.sock.rest == help) { snotice %sbot.sock.nick [BW]: in, out, on, off, NULL | halt }
      else {
        snotice %sbot.sock.nick [BW]: Received; $lines(sbot.bw.in) lines ( $+ $bytes($file(sbot.bw.in)).suf $+ )
        snotice %sbot.sock.nick [BW]: Sent; $lines(sbot.bw.out) lines ( $+ $bytes($file(sbot.bw.out)).suf $+ )
        halt
      }
    }

    if (.script == %sbot.sock.cmd) {
      snotice %sbot.sock.nick [script]: Using $script $+ , which has $lines($script) lines and is $bytes($file($script)).suf
      halt
    }

    if (.notify.add == %sbot.sock.cmd) {
      if ($gettok(%sbot.sock.rest,1,32) == $null) { snotice %sbot.sock.nick [notify]: Please enter a nickname. | halt }
      if ($readini(notify.ini,notify,$gettok(%sbot.sock.rest,1,32)) != $null) { snotice %sbot.sock.nick [notify]: User already exists. | halt }
      writeini notify.ini notify $gettok(%sbot.sock.rest,1,32) yes
      unset %sbot.notify
      set %sbot.temp 1
      :notify
      inc %sbot.temp 1
      if (%sbot.temp > $lines(notify.ini)) { goto notifyend }
      set %sbot.notify %sbot.notify + $+ $gettok($read(notify.ini,%sbot.temp),1,61)
      goto notify
      :notifyend
      sraw WATCH C %sbot.notify S
      snotice %sbot.sock.nick [notify]: User $gettok(%sbot.sock.rest,1,32) added to notify.
    }

    if (.notify.del == %sbot.sock.cmd) {
      if ($gettok(%sbot.sock.rest,1,32) == $null) { snotice %sbot.sock.nick [notify]: Please enter a nickname. | halt }
      if ($readini(notify.ini,notify,$gettok(%sbot.sock.rest,1,32)) == $null) { snotice %sbot.sock.nick [notify]: User does not exist. | halt }
      remini notify.ini notify $gettok(%sbot.sock.rest,1,32)
      unset %sbot.notify
      set %sbot.temp 1
      :notify
      inc %sbot.temp 1
      if (%sbot.temp > $lines(notify.ini)) { goto notifyend }
      set %sbot.notify %sbot.notify + $+ $gettok($read(notify.ini,%sbot.temp),1,61)
      goto notify
      :notifyend
      sraw WATCH C %sbot.notify S
      snotice %sbot.sock.nick [notify]: User $gettok(%sbot.sock.rest,1,32) deleted from notify.
    }

    if (.notify.on == %sbot.sock.cmd) {
      unset %sbot.notify
      set %sbot.temp 1
      :notify
      inc %sbot.temp 1
      if (%sbot.temp > $lines(notify.ini)) { goto notifyend }
      set %sbot.notify %sbot.notify + $+ $gettok($read(notify.ini,%sbot.temp),1,61)
      goto notify
      :notifyend
      sraw WATCH C %sbot.notify S
      snotice %sbot.sock.nick [notify]: Notify enabled.
      halt
    }

    if (.notify.off == %sbot.sock.cmd) {
      sraw WATCH 
      snotice %sbot.sock.nick [notify]: Notify disabled.
      halt
    }

    ;-> Private Message Emulation
    if (.p.on == %sbot.sock.cmd) {
      if (%sbot.sock.rest == $null) { snotice %sbot.sock.nick [pEmu]: No nickname given. | halt }
      set %sbot.pemu $gettok(%sbot.sock.rest,1,32)
      smsg %sbot.sock.target [pEmu]: Activated on ( $+ $gettok(%sbot.sock.rest,1,32) $+ ). Reporting PM's to: $sbot.channel
      halt
    }

    if (.p.off == %sbot.sock.cmd) {
      if (%sbot.pemu == $null) { snotice %sbot.sock.nick [pEmu]: Was not running. | halt }
      unset %sbot.pemu
      smsg $sbot.channel [pEmu]: Disabled.
      halt
    }

    ;if (.p == %sbot.sock.cmd) {
    ;  if (%sbot.pemu == $null) { snotice %sbot.sock.nick [pEmu]: Isn't running. | halt }
    ;  if (%sbot.sock.rest == $null) { snotice %sbot.sock.nick [pEmu]: No text given. | halt }
    ;  smsg %sbot.pemu %sbot.sock.rest
    ;  halt
    ;}

  }
  ;-> !!! End of admin commands

  ;-> Commands for normal users
  if (.help == %sbot.sock.cmd) { snotice %sbot.sock.nick [sBot]: There is currently no help available for normal users. | halt }

  ;-> You can place more commands for normal users here

  if (.quote == %sbot.sock.cmd) {
    if (%sbot.sock.rest == $null) { set %temp $rand(1,$lines(quotes.txt)) | smsg %sbot.sock.target [Quote %temp $+ ]: $read(quotes.txt,%temp) | halt }
    if (%sbot.sock.rest isnum) {
      if (%sbot.sock.rest > $lines(quotes.txt)) { smsg %sbot.sock.target [Quote]: There are only $lines(quotes.txt) quotes in QuoteDB. | halt }
      smsg %sbot.sock.target [Quote %sbot.sock.rest $+ ]: $read(quotes.txt,%sbot.sock.rest)
    }
    else {
      if ($read(quotes.txt,w,* $+ %sbot.sock.rest $+ *) != $null) { smsg %sbot.sock.target [Quote]: $read(quotes.txt,w,* $+ %sbot.sock.rest $+ *) | halt }
      if ($read(quotes.txt,w,* $+ %sbot.sock.rest $+ *) == $null) { smsg %sbot.sock.target [Quote]: No quote found. | halt }
    }
  }

  if (.lastquote == %sbot.sock.cmd) {
    smsg %sbot.sock.target [LastQuote ( $+ $lines(quotes.txt) $+ ) $+ ]: $read(quotes.txt,$lines(quotes.txt))
    halt
  }

  if (.wb == %sbot.sock.cmd) {
    sockclose wb- $+ %sbot.sock.target
    sockopen wb- $+ %sbot.sock.target www.vandale.nl 80
    set %sbot.wb.word %sbot.sock.rest
  }

  if (.p == %sbot.sock.cmd) {
    if (%sbot.pemu == $null) { snotice %sbot.sock.nick [pEmu]: Isn't running. | halt }
    if (%sbot.sock.rest == $null) { snotice %sbot.sock.nick [pEmu]: No text given. | halt }
    smsg %sbot.pemu %sbot.sock.rest
    halt
  }

  ;--- TIBIA ---
  if (.tibia == %sbot.sock.cmd) {
    if (%sbot.sock.rest == $null) || (%sbot.sock.rest == help) { snotice %sbot.sock.nick [Tibia]: Help: .tibia exp, char | halt }
    if ($gettok(%sbot.sock.rest,1,32) == exp) {
      if ($gettok(%sbot.sock.rest,2,32) isnum) {
        set %exp.tmp $gettok(%sbot.sock.rest,2,32)
        set %exp $bytes($round($calc($calc(50/3) * $calc(%exp.tmp ^ 3) - $calc(100 * $calc(%exp.tmp ^ 2)) + $calc($calc(850/3) * %exp.tmp) - 200),0),b)
        smsg %sbot.sock.target [Tibia]: You need %exp experience to reach level %exp.tmp $+ .
        halt
      }
      else { snotice %sbot.sock.nick [Tibia]: Usage: .tibia exp <level> | halt }
    }
    if ($gettok(%sbot.sock.rest,1,32) == char) {
      if ($gettok(%sbot.sock.rest,2-,32) == $null) { snotice %sbot.sock.nick [Tibia]: Usage: .tibia char <character name> | halt }
      if ($sock(tibia.char)) { smsg %sbot.sock.target [Tibia]: Please wait, busy... | halt }
      set %tibia.char $replace($gettok(%sbot.sock.rest,2-,32),$chr(32),$chr(43))
      set %tibia.chan %sbot.sock.target
      sockopen tibia.char www.tibia.com 80
    }
  }

}

;-> Woordenboek
on *:sockopen:wb-*:{ 
  sockwrite -n $sockname GET /vandale/opzoeken/woordenboek/?zoekwoord= $+ %sbot.wb.word HTTP/1.1 
  sockwrite -n $sockname Host: www.vandale.nl $+ $str($crlf ,2) 
} 
on *:sockread:wb-*:{ 
  sockread %tif
  if (<font color="#FF8000"><B><BIG> isin %tif) {
    smsg $remove($sockname,wb-) 12[4 $+ $replace($mid(%tif,13),<tr>,,<td>,,<dl>,,<BIG>,,<font color="#FF8000">,,</tr>,,</td>,,</dl>,,</font>,,</BIG>,,<dd>,,</dd>,,<b>,,</b>,,<u>,,</u>,,&#183;,·,&#126;,~,&#215;,×,<i>,,</i>,,<SUP>,,<SMALL>,,</SUP>,,</SMALL>,,&#39;,') $+ 12]
  }
  if (Het door u isin %tif) {
    smsg $remove($sockname,wb-) 12[4Het door u gezochte woord is niet gevonden.12]
  }
}

on *:sockopen:tibia.char:{
  if ($sockerr > 0) { smsg %tibia.chan [Tibia]: Oops! There was a socket error. | halt }
  sockwrite -n $sockname GET /community/?subtopic=characters&name= $+ %tibia.char HTTP/1.1 
  sockwrite -n $sockname Host: www.tibia.com $+ $str($crlf ,2)
  halt
}

on *:sockread:tibia.char:{
  sockread %tibia
  if (Character Information isin %tibia) {
    set %tibia $replace(%tibia,<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR=#505050><TD COLSPAN=2 CLASS=white><B>Character Information</B></TD></TR><TR BGCOLOR=#F1E0C6><TD WIDTH=20%>Name:</TD><TD>,)
    set %char.name $gettok(%tibia,1,60)
    set %tibia $remove(%tibia,$gettok(%tibia,1,60))
    set %tibia $replace(%tibia,</TD></TR><TR BGCOLOR=#D4C0A1><TD>Sex:</TD><TD>,)
    set %char.sex $gettok(%tibia,1,60)
    set %tibia $remove(%tibia,$gettok(%tibia,1,60))
    set %tibia $replace(%tibia,</TD></TR><TR BGCOLOR=#F1E0C6><TD>Profession:</TD><TD>,)
    set %char.profession $gettok(%tibia,1,60)
    set %tibia $remove(%tibia,$gettok(%tibia,1,60))
    set %tibia $replace(%tibia,</TD></TR><TR BGCOLOR=#D4C0A1><TD>Level:</TD><TD>,)
    set %char.level $gettok(%tibia,1,60)
    set %tibia $remove(%tibia,$gettok(%tibia,1,60))
    set %tibia $replace(%tibia,</TD></TR><TR BGCOLOR=#F1E0C6><TD>World:</TD><TD>,)
    set %char.world $gettok(%tibia,1,60)
    set %tibia $remove(%tibia,$gettok(%tibia,1,60))
    set %tibia $replace(%tibia,</TD></TR><TR BGCOLOR=#D4C0A1><TD>Residence:</TD><TD>,)
    set %char.residence $gettok(%tibia,1,60)
    if (%char.sex == female) { smsg %tibia.chan [Tibia]: 4 $+ %char.name (07 $+ %char.level $+ 4): $+(%char.sex,$chr(44),$chr(32),,%char.profession,,$chr(32),[,7,%char.world,4,$chr(44),$chr(32),%char.residence,]) | sockclose $sockname | halt }
    if (%char.sex == male) { smsg %tibia.chan [Tibia]: 12 $+ %char.name (11 $+ %char.level $+ 12): $+(%char.sex,$chr(44),$chr(32),,%char.profession,,$chr(32),[,11,%char.world,12,$chr(44),$chr(32),%char.residence,]) | sockclose $sockname | halt }
    halt
  }
  if (Could not find character isin %tibia) { smsg %tibia.chan [Tibia]: Oops! That character does not exist. | sockclose $sockname | halt }
}