Please consider a donation to the Higher Intellect project. See or the Donate to Higher Intellect page for more info.

From Higher Intellect Vintage Wiki
Jump to navigation Jump to search

Eliza chat bot for Hotline.

#Eliza Bot that talks through private chats. Very Elite.
#By can and netfreak for (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= '',

#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->login(Login    => $login,
            Password => $pass,
            Nickname => $nick,
            Icon     => 18016,
            NoNews   => 1);

#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) = @_;
        $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($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};