User Tools

Site Tools


user:mgough:wezlbot

Kick Wezlbot out of the Nest

A Brief History of Wezlbot

Genesis

I started Wezlbot in October 2009 to challenge my skills while in my Unix class. The original intention was to install and configure an eggdrop IRC bot which I managed to do without too much head to monitor thumping. I named the bot Wezlbot - my IRC nick is CrzyWezl - a throwback to a nickname I got from the “crazy weasel” in “Who Framed Roger Rabbit” (no comments!), and the only logical choice was Wezlbot (IRC has nickname length limits).

At this point, Weaz did not do much of anything, the bot was your stock eggdrop IRC bot (learn more here: http://www.eggdrop.org) that was designed to take care of mundane channel business.. what fun is that?? So I proceeded to install different TCL scripts that gave the bot more functionality - such as quiz's, a “magic 8-ball” and weather reporting (A great resource for scripts is the aptly named TCLscript.com: http://www.tclscript.com.

It's Alive!!.. well, sorta..

An info-bot, while informative and with practical function is not hyper-interesting, I wanted to shake it up a bit, so I started to research “AI” conversation bots. There are a number out there that parrot things back to you triggered by keywords, but nothing that struck my fancy, until I stumbled across MegaHAL.

Alan Turing (http://en.wikipedia.org/wiki/Turing_test)created a test to determine if a program shows intelligence. In 1991, the Cambridge Centre for Behavioural Studies held the first formal competition for the Turing Test, called the Loebner contest after Dr. Hugh Loebner who put up a $100,000 prize for the first computer program to pass it. Needless to say, no program has ever won, with the exception of two “bronze” metals. MegaHAL was part of the competition in 1998, though it did not win, it became popular for its odd responses.

Some researching later, I found a port of MegaHAL for eggdrop (Sources can be found here: http://www.barkerjr.net/irc/eggdrop/modules/megahal/) and managed to configure and install it. The module comes with some “stock” brains - but the response is more like C3PO than anything else, so I wiped it's brain and started from scratch.

Soon Wezlbot became quite the distraction on IRC people talking to it all day, as it learned the good bad and ugly of the conversations, Wezlbot appeared to grow an amusing “personality”.

Out of the Nest


This semester my intention was to allow the bot to interact out of the confines of lab46.

I took a few approaches, but my main goals were the following:
* Create a way for the bot to send output outside of IRC via a script.
* Create a way to log into a popular social networking site.
* Allow chat external to lab46.

Scripts, scripts, and more scripts...

To get the bot to speak outside of IRC, I found a perl port of MegaHAL written by Cory Spencer, the source can be found here: http://search.cpan.org/~cspencer/AI-MegaHAL-0.04/. The script is written in perl and creates functionality to receive, process, and output syntax to the bot. I created a simple custom interface which you can see below. By copying the brain files into the perl script folder and keeping it updated from the IRC brain the bot keeps concurrent with its knowledgeable.

wezlbot.pl
  1 ######################################################################
  2 #   M.Gough - 2010
  3 #   A Perl Interface for WezlBot's Facebook Interaction...
  4 ######################################################################
  5
  6
  7 use AI::MegaHAL;
  8
  9 #########################
 10 # Creating new AI::MegaHAL
 11 my $megahal = AI::MegaHAL->new(AutoSave => 1);
 12 # Get the input..
 13 my $query = $ARGV[$0];
 14 # Send reply..
 15 my $reply = $megahal->do_reply($query);
 16 print("$reply\n");
 17 $megahal = undef;

To execute the script, the following command is issued.

perl wezlbot.pl "Hello"

Which results in the output being displayed, in this case…

 Hello to my interesting convo with wezlbot.

Interesting yes, but how useful?? Not very, but that's where the next modification comes in…

At this point, I created a profile account at “that popular social networking” site for Wezlbot. To get it to update the site, I modified the megahal source code as follows… In file: /eggdrop1.6.9/src/mod/megahal.mod/megahal.c In the function static char *generate_reply(MODEL *model, DICTIONARY *words) Add the following just before the statement “return(output);”

1858
1859     // hack in an output ...
1860     // Add random to this...
1861     //
1862     int random_number = rand() % 100 + 1;
1863
1864     char o_buff[255];
1865     int o_ret;
1866     if(random_number < 20)
1867     {
1868     o_ret = sprintf(o_buff, "php ../fb/minibot/wezlbot_update.php \"%s\"",      output);
1869     system(o_buff);
1870     }

What happens is that the program creates a random number from 1-100, then if the number is less than 20, the output is sent to both IRC AND the “social networking site's” status update (via a php call, which I will cover shortly). So in essence, 20% of the bot's chatter on IRC will be sent as a status update. I would like to cronjob this and perform updates without interaction, but thats on my todo list.

And now the magic! I will not release the class file as it can be used for evil, but here's the php script that performs the update.

wezlbot_update.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">
<head>
<title>Wezlbot Status Update Test Container</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
        body {font-family:verdana,arial,sans-serif; color:#191919; font-size:11px;}
        div.resul { font-size:30px; }
        a { color:#D70606; font-weight:bold;}
</style>
</head>
<body>
<?
                include("wezlbot.class.php");
                $mb = new wezlbot();
 
                echo print_r($mb->setSOCIALNETWORKINGSITEStatus($argv[1], BOT_LOGIN_NAME, BOT_PASSWORD));
 
?>
 
</body>
</html>

So any input sent to this script will log into the site, update a status, log out etc.. This is all done using cURL and PHP.

Ok, so what about that perl script??

The perl script is what I use to generate messages to respond to responses (fun wording eh?) to Wezlbot's status updates. Unfortunately at this time, this has to be done by hand, but I am working on an auto-responder of sorts to take all this manual work off of my hands. This is also a fun way to generate voice synthesis!

The Future

I plan on developing this more and more as time goes on, my ultimate goal would be to have a CGI head of Wezlbot on the lair wall with voice recognition, voice synthesis, and facial tracking, that way he can look at you while your talking to him. It would be fun to see the janitors response as well!!

user/mgough/wezlbot.txt · Last modified: 2010/05/20 17:23 by mgough