Pchatelizabot.pl
Eliza chat bot for Hotline.
#!/usr/local/bin/perl #Eliza Bot that talks through private chats. Very Elite. #By can and netfreak for preterhuman.net (Higher Intellect) #Sun Mar 10 17:37:09 PST 2002 #Set up our "uses". #Unless you'd like to clean this up, don't use strict. use Getopt::Std; use Net::Hotline; use Net::Hotline::Client; use Net::Hotline::PrivateChat; use Chatbot::Eliza; #Modify for your server, of course. $server= 'preterhuman.net', $nick="doc", $login="liz", $pass="doc"; #Create an instance of Eliza. $mybot = new Chatbot::Eliza { name => "Liz" }; #Set up Net::Hotline::Client and Net::Hotline::PrivateChat $hlc = new Net::Hotline::Client; $hlc->connect("$server"); $hlc->login_handler(\&Login_Handler); $hlc->pchat_invite_handler(\&Pchat_Invited_Handler); $hlc->pchat_chat_handler(\&Pchat_Chat_Handler); $hlc->pchat_leave_handler(\&Pchat_Leave_Handler); $hlc->login(Login => $login, Password => $pass, Nickname => $nick, Icon => 18016, NoNews => 1); $hlc->run(); #Say hello the the people, honey. sub Login_Handler { $hlc->chat("Dr. Liz is here to help.") } #All right; we've come to the meat of the program. #If we get a pchat invite, accept it, and store the #socket and chat reference number in a hash, with #the socket as they key. Why? $hlc->pchat_leave_handler #gives us the user's sockets, and $hlc->pchat_leave #requires a chat reference number. The hash allows us #find the reference number of the chat from the user's #sockets. [I am so good - can]. sub Pchat_Invited_Handler { my($self, $ref, $socket, $nick) = @_; $self->pchat_accept($ref); $socketref{$socket} = $ref; } #When we get a new line of chat, we send it over to #Chatbot::Eliza. We don't want the bot talking to itself #and getting stuck in a feedback loop, and we also want #to extract the message from the reference that $text gives #us. And so we have split, regular expressions, and ne #[Yep, still good - can]. sub Pchat_Chat_Handler { my($hlc, $ref, $text) = @_; my($botnick)="doc"; my($mybot) = $mybot; @line = split(/:/, $$text); @line[0] =~ s/\s*//; @line[1] =~ s/\s*//; $reply = $mybot->transform(@line[1]); if(@line[0] ne $botnick) { $hlc->pchat($ref, "$reply"); } } #Remember that hash? Here it comes. #$hlc->pchat_leave_handler gives us the socket #of the user that just left, and we use that as #a key to find the ref. [I like repeating myself # - can]. sub Pchat_Leave_Handler { my($hlc, $pchat, $socket, ) = @_; my($leave) = $socketref{$socket}; $hlc->pchat_leave($leave); }