; -----------------------------------------------------------------------------
; /bot -s server [-p port] [-n nick] [-i ident] [-f full name]
alias bot {
var %p = 1, %argc = $0
if (%argc < 1) /echo -s * /bot: insufficient parameters
else {
/set %bot.server $server
/set %bot.port $port
/set %bot.nick $me $+ |BOT
/set %bot.ident $me
while ($gettok($1-, %p, 32) != $null) {
var %arg = $ifmatch
if (%arg == -f) {
/inc %p
while (-* !iswm $gettok($1-, %p, 32)) {
/set %bot.fullname %bot.fullname $gettok($1-, %p, 32)
/inc %p
}
/dec %p
}
else if (%arg == -i) {
/inc %p
/set %bot.ident $gettok($1-, %p, 32)
}
else if (%arg == -n) {
/inc %p
/set %bot.nick $gettok($1-, %p, 32)
}
else if (%arg == -p) {
/inc %p
/set %bot.port $gettok($1-, %p, 32)
}
else if (%arg == -s) {
/inc %p
/set %bot.server $gettok($1-, %p, 32)
}
/inc %p
}
if (!%bot.fullname) /set %bot.fullname $readini($mircini, mirc, user)
/bot_connect
}
}
; ctcp stuff (Not intergrated yet)
alias bot.ctcp {
if ($1 == VERSION) return mIRC $+(v,$version) Khaled Mardem-Bey
if ($1 == TIME) return $fulldate
if ($1 == PING) return PING $1
if ($1 == FINGER) return Put that finger away
}
alias bot_connect {
if ($sock(bot)) /sockclose bot
if ($window(@bot)) /clear @bot | else /window @bot
if ($window(@bot_chat)) /clear @bot_chat | else /window @bot_chat
/sockopen bot %bot.server %bot.port
}
alias bot_write {
if ($sock(bot)) {
/sockwrite -n bot $1-
.signal BOT WRITE $1-
if ($1 == NICK) /set %bot.nick $2
}
}
alias bot_disconnect {
if ($sock(bot)) {
/sock_write QUIT :SocketBot By KT
/sockclose bot
}
/unset %bot.*
if ($window(@bot)) /window -c @bot
if ($window(@bot_chat)) /window -c @bot_chan
}
; -----------------------------------------------------------------------------
on *:SOCKOPEN:bot: {
if ($sockerr) .signal BOT ERROR $sock(bot).wserr $sock(bot).wsmsg
else {
/sockwrite -n bot NICK %bot.nick
/sockwrite -n bot USER %bot.ident * * $+(:,%bot.fullname)
}
}
on *:SOCKREAD:bot: {
var %buffer
/sockread -f %buffer
.signal BOT %buffer
}
; -----------------------------------------------------------------------------
on *:SIGNAL:BOT: {
var %rawmsg = $1-
; --
; misc events
; --
; Error
if ($1 == ERROR) /echo -a Error while connecting to server: $2-
; Close event
else if ($1 == CLOSE) /echo @bot Bot Connection Closed
; ping
else if ($1 == PING) /bot_write PONG $right($2, -1)
; information written
else if ($1 == WRITE) /echo @bot <- $2-
; --
; Chatting
; --
; the normal mIRC "on" events
if ($1 == ON) {
; " on *:JOIN: "
if ($2 == JOIN) {
var %address = $3, %nick = $gettok($3, 1, $asc(!)), %chan = $4
}
; " on *:PART: "
else if ($2 == PART) {
var %address = $3, %nick = $gettok($3, 1, $asc(!)), %chan = $4
}
; " on *:KICK:#: "
else if ($2 == KICK) {
var %address = $3, %nick = $gettok($3, 1, $asc(!)), %chan = $4, %knick = $5
/tokenize 32 $6-
}
; " on *:TEXT:*:#: "
else if ($2 == CHANTEXT) {
var %address = $3, %nick = $gettok($3, 1, $asc(!)), %chan = $4
/tokenize 32 $5-
}
; " on *:TEXT:*:?: "
else if ($2 == QUERYTEXT) {
var %address = $3, %nick = $gettok($3, 1, $asc(!))
/tokenize 32 $4-
}
; " on *:ACTION:*:#: "
else if ($2 == CHANACTION) {
var %address = $3, %nick = $gettok($3, 1, $asc(!)), %chan = $4
/tokenize 32 $5-
}
; " on *:ACTION:*:?: "
else if ($2 == QUERYACTION) {
var %address = $3, %nick = $gettok($3, 1, $asc(!))
/tokenize 32 $4-
}
; " on *:NOTICE:*:*: "
; Take note, i didn't filter channel notices from private
else if ($2 == NOTICE) {
var %address = $3, %nick = $gettok($3, 1, $asc(!)), %target = $4
/tokenize 32 $5-
}
; "on *:RAWMODE:#: "
else if ($2 == RAWMODE) {
var %address = $3, %nick = $gettok($3, 1, $asc(!)), %chan = $4
/tokenize 32 $5-
}
}
; raw events
else if ($2 isnum 0-999) {
; make it like a "raw *:*: { }" event
var %numeric = $2
/tokenize 32 $3-
; don't touch these lines -- BEGIN
if (%numeric == 433) {
; this is the msg you get when you trying to connect with a bad
; name. the else .. is when you try to do /nick already on server.
if ($1 == %bot.nick) /sock_write NICK %bot.nick $+ $rand(1,999)
else /set %bot.nick $1
}
; don't touch these lines -- END
}
; --
; the below recalls the events above. It's more the "engine" of the bot. They call the above stuff.
; To make it easy on you, I made them all as similar to the actual events as possible. Use %nick
; instead of $nick, %chan for $chan, etc.
; --
; other messages
else {
if (:*!*@* iswm $1) {
var %nick = $right($gettok($1, 1, $asc(!)), -1), %address = $right($1, -1)
if ($2 == JOIN) .signal BOT ON JOIN %address $right($3, -1)
else if ($2 == KICK) .signal BOT ON KICK %address $3-4 $right($5-, -1)
else if ($2 == MODE) .signal BOT ON MODE %address $3-
else if ($2 == NOTICE) .signal BOT ON NOTICE %address $3 $right($4-, -1)
else if ($2 == PART) .signal BOT ON PART %address $3
else if ($2 == PRIVMSG) {
var %target = $3
/tokenize 32 $right($4-, -1)
if (#* iswm %target) {
if ($1 == $+($chr(1),ACTION)) .signal BOT ON CHANACTION %address %target $left($2-, -1)
else .signal BOT ON CHANTEXT %address %target $1-
}
else {
if ($1 == $+($chr(1),ACTION)) .signal BOT ON QUERYACTION %address %target $left($2-, -1)
else .signal BOT ON QUERYTEXT %address $1-
}
}
}
}
if ((WRITE * !iswm %rawmsg) && (ON * !iswm %rawmsg)) /echo @bot -> %rawmsg
}
; -----------------------------------------------------------------------------
menu channel {
Socket Bot
.$iif(!$sock(bot), Launch Connection): /bot $$?="Enter Settings: $crlf -s server [-p port] [-n nick] [-i ident] [-f full name]"
.$iif($sock(bot), Kill Connection): /bot_disconnect
.-
.$iif($sock(bot), Bot Stuff)
..Nickname: /bot_write NICK $$?="Enter New Name"
.$iif($sock(bot), Location)
..$iif(%bot.nick !ison $active, Join This Channel): /bot_write JOIN $active
..$iif(%bot.nick ison $active, Part This Channel): /bot_write PART $active
..-
..Join Channel ???: /bot_write JOIN $$?="Enter Channel Name"
..Part Channel ???: /bot_write PART $$?="Enter Channel Name"
.$iif($sock(bot), Messaging)
..Message Channel: /bot_write PRIVMSG $active $+(:,$$?="Enter Message")
}
menu nicklist {
Socket Bot
.$iif(!$sock(bot), Launch Connection): /bot $$?="Enter Settings: $crlf -s server [-p port] [-n nick] [-i ident] [-f full name]"
.$iif($sock(bot), Kill Connection): /bot_disconnect
.-
.$iif($sock(bot), User Control)
..$iif(%bot.nick isop $active && %bot.nick !isop $active, Op $$1): /bot_write MODE $active +o $1
..$iif(%bot.nick isop $active && %bot.nick isop $active, Deop $$1): /bot_write MODE $active -o $1
..$iif(%bot.nick isop $active && %bot.nick !ishop $active, Half-Op $$1): /bot_write MODE $active +h $1
..$iif(%bot.nick isop $active && %bot.nick ishop $active, Dehalf-op $$1): /bot_write MODE $active -h $1
..$iif(%bot.nick isop $active && %bot.nick !isvoice $active, Voice $$1): /bot_write MODE $active +v $1
..$iif(%bot.nick isop $active && %bot.nick isvoice $active, Devoice $$1): /bot_write MODE $active -v $1
..-
..$iif(%bot.nick isop $active, Kick $$1): /bot_write KICK $active $$1
..$iif(%bot.nick isop $active, Kick $$1 -Reason-): /bot_write KICK $active $$1 $+(:,$$?="Enter Reason")
..$iif(%bot.nick isop $active, Kick Ban $$1): /bot_write MODE $active +bb $$1 $address($$1, 11) | /bot_write KICK $active $$1
..$iif(%bot.nick isop $active, Kick Ban $$1 -Reason-): /bot_write MODE $active +bb $$1 $address($$1, 11) | /bot_write KICK $active $$1 $+(:,$$?="Enter Reason")
.$iif($sock(bot), Bot Stuff)
..Nickname: /bot_write NICK $$?="Enter New Name"
.$iif($sock(bot), Location)
..$iif(%bot.nick !ison $active, Join This Channel): /bot_write JOIN $active
..$iif(%bot.nick ison $active, Part This Channel): /bot_write PART $active
..-
..Join Channel ???: /bot_write JOIN $$?="Enter Channel Name"
..Part Channel ???: /bot_write PART $$?="Enter Channel Name"
.$iif($sock(bot), Messaging)
..Message Channel: /bot_write PRIVMSG $active $+(:,$$?="Enter Message")
..Message $$1: /bot_write PRIVMSG $$1 $+(:,$$?="Enter Message")
}
menu @bot {
Clear Window: /clear @bot
-
Location
.Join Channel ???: /bot_write JOIN $$?="Enter Channel Name"
.Part Channel ???: /bot_write PART $$?="Enter Channel Name"
-
Disconnect: /bot_disconnect
}