/* A.L.I.C.E chatterbot, AliceChat v2.1 (socketbot version) for J-Alice Engine [http://j-alice.org] Copyright (C) 2004 bizkut This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Please read the Readme.html file checkout http://www.malaynet.org by bizkut@gamebox.net */ menu status,channel,query,menubar,@Alice.*,@Debug.*,@Monitor { - AliceChat .$iif($sock(alicesock),$style(2)) Connect:alicechat .$iif(!$sock(alicesock),$style(2)) Disconnect:alicedie .View ..Monitor:$iif(!$window(@Monitor),alice.mon,window -a @Monitor) ..Debug:$iif(!$window(@Debug.Alice),alice.dbg,window -a @Debug.Alice) .$iif(!$sock(alicesock),$style(2)) Command ..Status:.msg %alice.nick !status ..Join Chan:.msg %alice.nick !join $$?="Enter #chan the bot will join" ..Part Chan:.msg %alice.nick !part $$?="Enter #chan the bot will part" ..Start Chat:.msg %alice.nick !start $$?="#chan/nick to start chat" ..Stop Chat:.msg %alice.nick !stop $$?="#chan/nick to stop chat" ..Say:.msg %alice.nick !say $$?="#chan/nick to say" $$?="Message to say" ..Act:.msg %alice.nick !act $$?="#chan/nick to act" $$?="Message to act" ..Notice:.msg %alice.nick !notice $$?="#chan/nick to notice" $$?="Message to notice" ..Raw Cmd:.msg %alice.nick !raw $$?="Command to issue to IRC Server" ..Stop ALL!:alicestop .$iif($sock(alicesock),$style(2)) Setting:alicesett - } on *:load: { echo - echo AliceChat v2.1 (socketbot version) echo for J-Alice Engine [http://j-alice.org] echo Copyright (C) 2004 bizkut echo - echo This program is free software; you can redistribute it and/or modify echo it under the terms of the GNU General Public License as published by echo the Free Software Foundation; either version 2 of the License, or echo (at your option) any later version. echo - echo This program is distributed in the hope that it will be useful, echo but WITHOUT ANY WARRANTY; without even the implied warranty of echo MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the echo GNU General Public License for more details. echo - echo You should have received a copy of the GNU General Public License echo along with this program; if not, write to the Free Software echo Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA echo - echo Please read the Readme.html file echo checkout http://www.malaynet.org echo by bizkut@gamebox.net echo - } on *:unload: { $iif($sock(alicesock),sockwrite -n alicesock QUIT I'm afraid not to see you again..) | unset %alice.* } alias alicechat { if ($status = disconnected) { echo -a 4ERROR You are Disconnected. Plz connect to IRC first! | return } elseif ($sock(alicesock)) { echo -a 4ERROR Alice already online. Please type /msg %alice.nick !start #chan/nick to activate her. | return } elseif (!%alice.nick) { alicesett | set %alice.ftime 1 | return } sockopen alicesock %alice.ircs %alice.sport echo -a AliceChat is connecting.... } alias alicestop { var %alice.stop $input(Are you sure to stop ALL AliceChat sessions?,w,Stop ALL Sessions) if (%alice.stop) .msg %alice.nick !stopall } alias alicedie sockwrite -n alicesock QUIT Life is so short.. alias alicesett $iif(!$sock(alicesock),dialog -md aliceset aliceset,set %alice.err $input(AliceChat is already running! Plz disconnect her first,ho,AliceChat Setting)) dialog aliceset { title "AliceChat :: Settings" size -1 -1 130 100 option type dbu box "", 1, 1 1 128 98 text "Bot Nick:", 2, 8 10 30 10 edit "", 3, 30 8 48 10, autohs text "Pass:", 4, 81 10 15 10 edit "",5, 95 8 30 10, autohs password text "Server:", 8, 11 25 30 10 edit "irc.malaynet.org", 9, 30 23 48 10, autohs text "Port:", 10, 82 25 15 10 edit "6667", 11, 95 23 30 10, autohs text "BotMaster:", 12, 3 40 30 10 edit "", 13, 30 38 48 10, autohs box "J-Alice Setting", 14, 3 50 124 30 text "Address:", 15, 8 63 30 10 edit "localhost", 16, 32 61 30 10, autohs text "Port:", 17, 65 63 20 10 edit "8000", 18, 78 61 20 10, autohs button "Default", 19, 102 61 20 10, flat button "Ok", 20, 25 83 30 12, ok button "Cancel", 21, 75 83 30 12, cancel } on *:dialog:aliceset:init:0: { if (%alice.nick) did -o aliceset 3 1 %alice.nick if (%alice.auth) did -o aliceset 5 1 $decode(%alice.auth,m) if (%alice.ircs) did -o aliceset 9 1 %alice.ircs if (%alice.sport) did -o aliceset 11 1 %alice.sport $iif(%alice.mstr,did -o aliceset 13 1 %alice.mstr,did -o aliceset 13 1 $me) if (%alice.jal) did -o aliceset 16 1 %alice.jal if (%alice.pjal) did -o aliceset 18 1 %alice.pjal } on *:dialog:aliceset:sclick:19: { did -o aliceset 16 1 localhost did -o aliceset 18 1 8000 } on *:dialog:aliceset:sclick:20: { set %alice.tmpnick $did(aliceset,3) set %alice.nick $did(aliceset,3) set %alice.auth $encode($did(aliceset,5),m) set %alice.ircs $did(aliceset,9) set %alice.sport $did(aliceset,11) set %alice.mstr $did(aliceset,13) set %alice.jal $did(aliceset,16) set %alice.pjal $did(aliceset,18) if (%alice.ftime) { alicechat | unset %alice.ftime } } on *:sockopen:alicesock: { if ($sockerr > 0) { echo 4 AliceChat unable to connect IRC Server! | return } .write -c $shortfn($scriptdirdata\debug.log) sockwrite -n alicesock NICK %alice.tmpnick sockwrite -n alicesock USER Alice "" " $+ %alice.ircs $+ " :Mirc Artificial Intelligent Relay Chat } on *:sockread:alicesock: { if ($sockerr > 0) { echo 4 AliceChat Error on connect IRC Server! Plz open Debug window. | return } sockread %alice.read tokenize 32 $strip(%alice.read,burc) if ($window(@Debug.Alice)) { echo 4 @Debug.Alice $1- .write $shortfn($scriptdirdata\debug.log) $1- } if ($1 == PING) { sockwrite -n alicesock PONG $2 } elseif ($2 == 304) { sockwrite -n alicesock PRIVMSG %alice.mstr :4 $+ $4-  } elseif ($2 == 376) { set %alice.nick %alice.tmpnick ;; need this? she is a bot... ;; sockwrite -n alicesock MODE %alice.nick +B if (%alice.mstr != $me) .timer 1 1 alice.mstrchk else alice.mstrinf } elseif ($2 == 401) { if ($window(@Alice. $+ $4)) { echo 4 @Alice. $+ $4 $4- } elseif ($4 == %alice.mstr) { set %alice.mstr $me } else sockwrite -n alicesock PRIVMSG %alice.mstr :4ERROR $4- } elseif ($2 == 404) { sockwrite -n alicesock PRIVMSG %alice.mstr :4ERROR $4- } elseif ($2 == 433) { if (Nickname is already in use isin $3-) { unset %alice.*nick .timer 1 1 alice.autherr } } elseif ($2 == JOIN) { if ($readini($aldata,Channel,$gettok($1-,2,58)) == Enable) { if ($gettok($gettok($1,1,58),1,33) == %alice.nick) { .timerjoin 1 5 sockwrite -n alicesock PRIVMSG $gettok($1-,2,58) :hello all! :) } } } elseif ($2 == NICK) { var %alice.ppl $gettok($gettok($1,1,58),1,33) if (%alice.ppl == %alice.nick) { set %alice.nick $gettok($1-,2,58) sockwrite -n alicesock PRIVMSG %alice.mstr :My nick now is $gettok($1-,2,58)  } elseif (%alice.ppl == %alice.mstr) { set %alice.mstr $gettok($1-,2,58) } } elseif ($2 == NOTICE) { if ($gettok($gettok($1,1,58),1,33) == NickServ) { if ($3 == %alice.nick) { if (IDENTIFY isin $4-) { if (!%alice.auth) .timer 1 1 alice.autherr else sockwrite -n alicesock PRIVMSG Nickserv :IDENTIFY $decode(%alice.auth,m) } elseif (Password incorrect isin $4-) { unset %alice.auth .timer 1 1 alice.autherr } } } } elseif ($2 == PRIVMSG) { var %alice.ppl $gettok($gettok($1,1,58),1,33) if (($3 == %alice.nick) && (%alice.ppl != %alice.nick)) { if (:!* iswm $4) { if (%alice.ppl == %alice.mstr) { if ($4 == :!help) { .timer 1 1 sockwrite -n alicesock PRIVMSG %alice.mstr :4!join <#chan> - Join me a channel. .timer 1 2 sockwrite -n alicesock PRIVMSG %alice.mstr :4!part <#chan> - Part me joined channel. .timer 1 3 sockwrite -n alicesock PRIVMSG %alice.mstr :4!start <#chan/nick> - Start AliceChat on #chan/nick .timer 1 4 sockwrite -n alicesock PRIVMSG %alice.mstr :4!stop <#chan/nick> - Start AliceChat on #chan/nick .timer 1 5 sockwrite -n alicesock PRIVMSG %alice.mstr :4!say <#chan/nick>  - Make me saying on #chan/nick .timer 1 6 sockwrite -n alicesock PRIVMSG %alice.mstr :4!act <#chan/nick>  - Make me acting (action) on #chan/nick .timer 1 7 sockwrite -n alicesock PRIVMSG %alice.mstr :4!notice <#chan/nick>  - Make me notice on #chan/nick .timer 1 8 sockwrite -n alicesock PRIVMSG %alice.mstr :4!raw [string] - Issue custom command .timer 1 9 sockwrite -n alicesock PRIVMSG %alice.mstr :4!stopall - Will Stop AliceChat on ALL #chan/nick .timer 1 10 sockwrite -n alicesock PRIVMSG %alice.mstr :4!status - Show you some Status on AliceChat } elseif ($4 == :!join) { if (!$5 || (#* !iswm $5)) sockwrite -n alicesock PRIVMSG %alice.mstr :Join which channel, BotMaster? else { sockwrite -n alicesock JOIN $5 .writeini $aldata Channel $5 Enable sockwrite -n alicesock PRIVMSG %alice.mstr :Chat is automatically enable on $5 . Plz type !stop $5 to shut me up. } } elseif ($4 == :!part) { if (!$5 || (#* !iswm $5)) sockwrite -n alicesock PRIVMSG %alice.mstr :Part which channel, BotMaster? else { sockwrite -n alicesock PART $5 .remini $aldata Channel $5 sockwrite -n alicesock PRIVMSG %alice.mstr :I'm parting from $5 } } elseif ($4 == :!start) { if (#* iswm $5) { if ($ini($aldata,Channel,$5)) { sockwrite -n alicesock PRIVMSG %alice.mstr :Chat on $5 is now enable. .writeini $aldata Channel $5 Enable } else sockwrite -n alicesock PRIVMSG %alice.mstr :I can't start. It seems like I'm not on $5 . Plz !join $5 first! } elseif (#* !iswm $5) { sockwrite -n alicesock PRIVMSG %alice.mstr :Query chat with $5 is now enable. .writeini $aldata Query $5 Enable window -ek[0] @Alice. $+ $5 echo @Alice. $+ $5 Plz enter a greeting to $5 to make he/she knows you are querying. echo @Alice. $+ $5 Then, leave it alone.. Alice will answer any msg for you... :D } else sockwrite -n alicesock PRIVMSG %alice.mstr :Start chat with what, BotMaster? } elseif ($4 == :!stop) { if (!$5) sockwrite -n alicesock PRIVMSG %alice.mstr :Stop chat with what, BotMaster? elseif (#* iswm $5) { if ($readini($aldata,Channel,$5)) { sockwrite -n alicesock PRIVMSG %alice.mstr :Chat on $5 is now disable, but I'm still on that channel. .writeini $aldata Channel $5 Disable } else sockwrite -n alicesock PRIVMSG %alice.mstr :I can't stop. It seems like I'm not on $5 . That's great! } elseif ($readini($aldata,Query,$5)) { sockwrite -n alicesock PRIVMSG %alice.mstr :Query chat with $5 is now disable. .remini $aldata Query $5 } else sockwrite -n alicesock PRIVMSG %alice.mstr :I can't stop. It seems like I don't chat with $5 . That's great! } elseif ($4 == :!say) { if (!$6) sockwrite -n alicesock PRIVMSG %alice.mstr :I need #chan/nick and a message to say! else sockwrite -n alicesock PRIVMSG $5 : $+ $6- } elseif ($4 == :!act) { if (!$6) sockwrite -n alicesock PRIVMSG %alice.mstr :I need #chan/nick and a message to act! else sockwrite -n alicesock PRIVMSG $5 : $+ $chr(1) $+ ACTION $6- $+ $chr(1) } elseif ($4 == :!notice) { if (!$6) sockwrite -n alicesock PRIVMSG %alice.mstr :I need #chan/nick and a message to notice! else sockwrite -n alicesock NOTICE $5 : $+ $6 } elseif ($4 == :!raw) { if (!$5) sockwrite -n alicesock PRIVMSG %alice.mstr :Where is the command? else sockwrite -n alicesock $5- } elseif ($4 == :!stopall) { var %alice.stc 1 var %alice.stq 1 while (%alice.stc <= $ini($aldata,Channel,0)) { .writeini $aldata Channel $ini($aldata,Channel,%alice.stc) Disable inc %alice.stc } while (%alice.stq <= $ini($aldata,Query,0)) { .writeini $aldata Query $ini($aldata,Query,%alice.stq) Disable inc %alice.stq } sockwrite -n alicesock PRIVMSG %alice.mstr :All chat are Disable! } elseif ($4 == :!status) { var %alice.stc 1 sockwrite -n alicesock PRIVMSG %alice.mstr :Channel: while (%alice.stc <= $ini($aldata,Channel,0)) { set %alice.stn $ini($aldata,Channel,%alice.stc) .timer 1 %alice.stc sockwrite -n alicesock PRIVMSG %alice.mstr : $+ %alice.stn = $iif($readini($aldata,Channel,%alice.stn) == Enable,4Enable,14Disable) inc %alice.stc } var %alice.stq 1 .timer 1 %alice.stc sockwrite -n alicesock PRIVMSG %alice.mstr :Query: while (%alice.stq <= $ini($aldata,Query,0)) { set %alice.stm $ini($aldata,Query,%alice.stq) .timer 1 %alice.stc sockwrite -n alicesock PRIVMSG %alice.mstr : $+ %alice.stm = $iif($readini($aldata,Query,%alice.stm) == Enable,4Enable,14Disable) inc %alice.stq inc %alice.stc } .timer 1 %alice.stc sockwrite -n alicesock PRIVMSG %alice.mstr :Lines Received: %alice.rline .timer 1 %alice.stc sockwrite -n alicesock PRIVMSG %alice.mstr :Lines Sent: %alice.sline .timer 1 %alice.stc sockwrite -n alicesock PRIVMSG %alice.mstr :J-Alice is4 $iif($portfree(%alice.pjal),OFFLINE,ONLINE) } else sockwrite -n alicesock PRIVMSG %alice.mstr :4ERROR : No such command. Plz type !help for list of commands. } } elseif ($4 == :VERSION) { sockwrite -n alicesock NOTICE %alice.ppl :VERSION AliceChat v2.1 (mIRC Artificial Intelligent Relay Chat) - bizkut - www.Malaynet.org } ;; Chat engine begin elseif ($readini($aldata,Query,%alice.ppl) == Enable) { inc %alice.rline 1 if (:ACTION * iswm $4-) { set %alice.amsg $left($5-,-1) set %alice.qnickac %alice.ppl } else { set %alice.amsg $gettok($4-,1-,58) set %alice.qnick %alice.ppl } if ($window(@Alice. $+ %alice.qnick)) echo @Alice. $+ %alice.qnick 4< $+ %alice.qnick $+ 4> %alice.amsg if ($window(@Monitor)) echo @Monitor 4<-- [Private]< $+ %alice.qnick $+ > %alice.amsg .timerqmsg 1 2 alice.opencon } elseif (!$readini($aldata,Query,%alice.ppl)) { if ($window(@Monitor)) echo @Monitor 4<-- [4Stranger]< $+ %alice.ppl $+ > $gettok($4-,1-,58) sockwrite -n alicesock PRIVMSG %alice.mstr :4Notice : %alice.ppl not in my chatter list, is trying to chat with me. .writeini $aldata Query %alice.ppl Disable } else { if ($window(@Monitor)) echo @Monitor 4<-- [4Stranger]< $+ %alice.ppl $+ > $gettok($4-,1-,58) } } ;; Chat engine begin ;; on channel, only 1 msg queue at anytime. elseif (#* iswm $3) { if ($readini($aldata,Channel,$3) == Enable) { ;;; too depricated... if ((: $+ %alice.nick $+ : isin $4-) || (: $+ %alice.nick isin $4-)) { set %alice.ch $3 set %alice.chnick %alice.ppl set %alice.amsg $5- inc %alice.rline 1 if ($window(@Monitor)) echo @Monitor 4<-- [ $+ %alice.ch $+ ]< $+ %alice.chnick $+ > %alice.amsg .timercmsg 1 5 alice.opencon } elseif ((:ACTION * %alice.nick * iswm $4-) || (:ACTION * %alice.nick $+ $chr(1) iswm $4-) || (:ACTION %alice.nick * iswm $4-)) { set %alice.chac $3 set %alice.chnick %alice.ppl set %alice.amsg $left($5-,-1) inc %alice.rline 1 if ($window(@Monitor)) echo @Monitor 4<-- [ $+ %alice.ch $+ ]< $+ %alice.chnick $+ >[ACTION] %alice.amsg .timercmsg 1 5 alice.opencon } elseif ((* %alice.nick iswm $4-) || (* %alice.nick * iswm $4-) || (* %alice.nick $+ $chr(33) iswm $4-) || (* %alice.nick $+ $chr(63) iswm $4-)) { set %alice.ch $3 set %alice.chnick %alice.ppl set %alice.amsg $gettok($4-,1-,58) inc %alice.rline 1 if ($window(@Monitor)) echo @Monitor 4<-- [ $+ %alice.ch $+ ]< $+ %alice.chnick $+ > %alice.amsg .timercmsg 1 5 alice.opencon } } } } } on *:sockclose:alicesock: { echo 4 -a AliceChat lost connection.. } alias -l alice.mstrchk { set %alice.mstr $input(%alice.mstr is my Master. Or plz change to your nick here,eoq,Confirm BotMaster,%alice.mstr) alice.mstrinf } alias -l alice.mstrinf { sockwrite -n alicesock PRIVMSG %alice.mstr :I'm Online, my BotMaster! sockwrite -n alicesock PRIVMSG %alice.mstr :Please type !help for list of command. sockwrite -n alicesock PRIVMSG %alice.mstr :type !raw MODE %alice.nick +B to mark me as a bot on IRC. .writeini $aldata Query %alice.mstr Enable } alias -l alice.autherr { if (!%alice.tmpnick) { set %alice.tmpnick $$?="Alice nick already in use. Plz enter other nick" sockwrite -n alicesock NICK %alice.tmpnick } elseif (!%alice.auth) { set %alice.auth $encode($input(Plz enter Alice NickServ password or click Cancel to choose other nick,ep,NickServ Identify),m) if (!%alice.auth) { set %alice.nick $$?="Enter bot nick" | set %alice.auth $encode($?*="Plz enter the NickServ password if the nick is registered",m) } } if (%alice.auth) { sockwrite -n alicesock PRIVMSG Nickserv :IDENTIFY %alice.nick $decode(%alice.auth,m) sockwrite -n alicesock NICK %alice.nick } } alias -l alice.opencon sockopen alice %alice.jal %alice.pjal on *:input:@Alice.*: { if (/* !iswm $1) { sockwrite -n alicesock PRIVMSG $gettok($target,2,46) : $+ $1- echo $target 14 $+ %alice.nick $+ 4-->(manual) $1- } } on 1:sockopen:alice: { if ($sockerr > 0) { echo -a 4ERROR: Alice unable to chat. Plz check the J-Alice server. unset %alice.amsg } else { ;; some common http GET char replacement here set %alice.smsg $replacex(%alice.amsg,%alice.nick,Anna,$chr(32),$chr(43),$chr(59),$chr(37) $+ 3B,$chr(34),$chr(37) $+ 22,$chr(39),$chr(37) $+ 27,$chr(63),$chr(37) $+ 3F,$chr(33),$chr(37) $+ 21,$chr(58),$chr(37) $+ 3A,$chr(44),$chr(37) $+ 2C,$chr(40),$chr(37) $+ 28,$chr(41),$chr(37) $+ 29,$chr(47),$chr(37) $+ 2F,$chr(36),$chr(37) $+ 24,$chr(37),$chr(37) $+ 25) sockwrite -tn alice GET /?input= $+ %alice.smsg HTTP/1.1 $crlf $+ Accept: */* $crlf $+ Referer: %alice.ircs $crlf $+ Accept-Language: en-us $crlf $+ Accept-Encoding: gzip, deflate $crlf $+ User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) $crlf $+ Host:localhost $crlf $+ Connection: Keep-Alive } } on 1:sockread:alice: { sockread %alice.readmsg if ( isin %alice.readmsg) { inc %alice.sline 1 set %alice.repmsg $replacex($deltok($gettok(%alice.readmsg,2,58),2-,60),Anna,%alice.nick) ;; The bot got time to speak out. Look more "human" if (%alice.ch) { inc %alice.que 1 if ($window(@Monitor)) echo @Monitor 4--> [ $+ %alice.ch $+ ]< $+ %alice.chnick $+ >14 %alice.repmsg .timerer $+ %alice.que 1 $rand(5,20) sockwrite -n alicesock PRIVMSG %alice.ch : $+ %alice.chnick $+ : %alice.repmsg if (%alice.que == 2) unset %alice.que unset %alice.ch } elseif (%alice.chac) { inc %alice.que 1 if ($window(@Monitor)) echo @Monitor 4--> [ $+ %alice.ch $+ ]< $+ %alice.chnick $+ >[ACTION]14 %alice.repmsg .timerer $+ %alice.que 1 $rand(5,20) sockwrite -n alicesock PRIVMSG %alice.chac : $+ $chr(1) $+ ACTION %alice.chnick $+ : %alice.repmsg $+ $chr(1) if (%alice.que == 2) unset %alice.que unset %alice.chac } elseif (%alice.qnick) { inc %alice.quen 1 if ($window(@Monitor)) echo @Monitor 4--> [Private]< $+ %alice.qnick $+ >14 %alice.repmsg .timerar $+ %alice.quen 1 5 sockwrite -n alicesock PRIVMSG %alice.qnick : $+ %alice.repmsg if ($window(@Alice. $+ %alice.qnick)) echo @Alice. $+ %alice.qnick 14 $+ %alice.nick $+ 4-->14 %alice.repmsg  if (%alice.quen == 2) unset %alice.quen unset %alice.qnick } elseif (%alice.qnickac) { inc %alice.quen 1 if ($window(@Monitor)) echo @Monitor 4--> [Private]< $+ %alice.qnick $+ >[ACTION]14 %alice.repmsg .timerar $+ %alice.quen 1 5 sockwrite -n alicesock PRIVMSG %alice.qnickac : $+ $chr(1) $+ ACTION %alice.repmsg $+ $chr(1) if ($window(@Alice. $+ %alice.qnick)) echo @Alice. $+ %alice.qnick 14 $+ %alice.nick $+ 4-->[ACTION]14 %alice.repmsg  if (%alice.quen == 2) unset %alice.quen unset %alice.qnickac } sockclose alice } } alias alice.mon { window -e @Monitor /msg } alias alice.dbg { window -e @Debug.Alice } alias -l aldata { return $shortfn($scriptdirdata\setting.ini) } ;EOF