dIRC (Dialog IRC) Socket Bot
Posted by Coag
Monday, September 26, 2005
Description: A mIRC Socket Bot with fully functional dialog to go with it.


dialog dIRC {
  title "dIRC Socket Bot"
  size -1 -1 216 140
  option dbu
  edit  "", 1, 3 12 211 112, multiline size vsbar
  edit "", 3, 3 127 170 10, return default
  button "Connect", 6, 176 126 37 12, default
  edit "-- Welcome to dIRC Bot v1.0.  Type in a server and hit enter to start. --", 2, 3 3 211 10, read
}
alias dirc { dialog -md dIRC dIRC }
alias decho { did -az dIRC 1 $crlf $+ -- $1- }
alias drecv { did -az dIRC 1 $crlf $+ <- $1- }
alias dsend { did -az dIRC 1 $crlf $+ -> $1- | sockwrite -tn ircdirc $1- | did -r dIRC 3 }
alias dchange { did -ra dIRC $1- }
alias clearbox { did -r dIRC 3 }

on *:SOCKOPEN:*:{
  if (ircdirc isin $sockname) {
    if (!$sockerr) {
      dsend USER dircbot 0 0 :Dialog IRC Bot
      dsend NICK dIRCBot
      dchange 6 Send
      dchange 2 -- Connected to %connect --
    }
    else decho Error: $sock($sockname,1).wsmsg
  }
}
on *:SOCKREAD:*:{
  sockread %x
  tokenize 32 %x
  drecv $1-
  if ($1 == PING) {
    drecv $1-
    dsend PONG $2-
  }
  elseif ($2 == 376) {
    dsend JOIN #script
  }
}  

on *:DIALOG:dIRC:*:*:{
  if ($devent == sclick) {
    if ($did == 6) {
      if ($did(dIRC,6) == Connect) {
        if ($did(dIRC,3).text != $null) {
          set %connect $did(dIRC,3).text
          decho Initializing Socket Connection...
          sockopen ircdirc %connect 6667
          did -r dIRC 3
        }
        else decho Please Enter a VALID IRC Server
      }
      elseif ($did(dIRC,6) == Send) {
        var %input = $did(dIRC,3).text
        var %channel = $gettok(%input,2,32)
        var %cmd = $gettok(%input,1,32)
        var %args = $remove(%input,%cmd,%channel)

        if (/* !iswm %cmd) {
          decho Unknown Command ' $+ $did(dIRC,3).text $+ ' /help for help
          clearbox
        }
        elseif (%cmd == /help) {
          decho /raw <IRC Protocol>; /say <channel> <message>; /emote <channel> <message>
          clearbox
        }
        elseif (%cmd == /say) {
          dsend PRIVMSG %channel : $+ %args
        }
        elseif (%cmd == /emote) {
          dsend PRIVMSG %channel : $+ $chr(1) $+ ACTION $+ %args $+ $chr(1)
        }
        elseif (%cmd == /raw) {
          dsend %channel %args
        }
      }
    }
  }
  elseif ($devent == close) {
    sockwrite -tn $sockname QUIT :Dialog Closed
    sockclose $sockname
  }
}
Some errors...
Posted by Rustynails
Wednesday, September 28, 2005 08:18am PDT
Hey, Coag..
I was looking through your script and found an error or two...


  elseif ($devent == close) {
    sockwrite -tn $sockname QUIT :Dialog Closed
    sockclose $sockname
  }


You're using that in your on *:dialog events. $sockname will not return the name of any sockets in that case, for $sockname only returns in an on *:sock* event...

I'll report here if I find any more 'bugs'...
Submit a comment
Oops! You need to login or register before you can post a comment!

ebaum's world