#-> 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 { irc.webd.nl }
#-> Port to connect to:
alias sbot.port return { 6667 }
#-> 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 { #home }
#-> 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 { *@knickzor.is.leet.nl }
#-> 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-
}
#-> Sockwrite PRIVMSG alias
alias smsg {
sockwrite -nt sBot PRIVMSG $1 : $+ $2-
}
#-> Sockwrite NOTICE alias
alias snotice {
sockwrite -nt sBot NOTICE $1 : $+ $2-
}
#-> The '/sbot' alias to start/stop the bot:
alias sBot {
;-> Start command
if ($1 == start) {
;-> 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) {
;-> 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
sbot.db msg Connected, sending authentication commands...
sraw NICK $sbot.nick
sraw USER sBot x x :sBot by KnickLighter
sraw NICKSERV identify $sbot.nspass
sraw JOIN $sbot.channel $sbot.chankey
if ($sbot.onjoinmsg != $null) { smsg $sbot.channel $sbot.onjoinmsg }
halt
}
#-> 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
;-> 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.
sraw NICK $sbot.nick
sraw USER sBot x x :sBot by KnickLighter
sraw NICKSERV identify $sbot.nspass
sraw JOIN $sbot.channel $sbot.chankey
if ($sbot.onjoinmsg != $null) { smsg $sbot.channel $sbot.onjoinmsg }
}
}
;-> 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) { halt }
;-> !!! 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
}
;-> !!! 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
}
#-> I hope that this script will help several people out
#-> with their problems of making a mIRC bot. This bot
#-> will not require a different mIRC client.
#-> Please do not put this script online with your own
#-> nickname above it. Because I will find it. Leave
#-> the 3 lines above as they are.
#-> Enjoy!