MegaHAL Hotline Perl Bot

From Higher Intellect wiki
Jump to: navigation, search

This is a simple Perl based bot for bringing the MegaHAL AI into a Hotline chat server. This requires that you have the Hotline and MegaHAL Perl modules added to your system.

$count = 0;
$server= '127.0.0.1:9900';
$nick="stupid";
$login="bot";
$pass="bot";
use Net::Hotline;
use Net::Hotline::Client;
use MegaHAL;

$megahal = new MegaHAL('Path'     => './',
                            'Banner'   => 0,
                            'Prompt'   => 0,
                            'Wrap'     => 0,
                            'AutoSave' => 1);

$hlc = new Net::Hotline::Client;
$hlc->connect("$server");
$hlc->login(Login    => $login,
            Password => $pass,
            Nickname => $nick,
            Icon     => 500);

$hlc->chat_handler(\&Chat_Handler);
$hlc->join_handler(\&Join_Handler);
$hlc->run();

sub Join_Handler {
my($hlc, $user) = @_;
$nick = $user->nick();
$hlc->chat('Welcome, ', $nick);
}

sub Chat_Handler 
{
$count++;
$text = $megahal->do_reply($chat);
if ($count % 2 ==1)
{
my($hlc, $chat) = @_;
$hlc->chat($text);
}
}


Share your opinion