Hack 45 Run an Infobot

 < Day Day Up > 

Hack 45 Run an Infobot

figs/moderate.gif figs/hack45.gif

Set up an infobot to sit in your channel, learning facts and reeling off useful information .

Infobots are handy. You can use them for any number of things: to leave notes for other users, inquire when someone was last seen around the channel, do quick math problems, or simulate dice rolls. But the most important feature of the infobot is undoubtedly its factoid support. These are simply a combination of a key phrase and a response. For example, if you have an infobot called Fiona, you can feed it a factoid like this:

 <Fennec>  Fiona, the official site is http://www.reuben.org/holbrook/index.htm  

Every time someone comes into your channel and asks:

 <RandomGuy> Where is the official site? 

He'll get a fast and effective reply from the infobot, saving you the effort of typing the answer:

 <Fiona> The official site is http://www.reuben.org/holbrook/index.htm 

The infobot source also allows for some variation, to better serve the clueless. For example, it would also respond to the following questions:

 <RandomGuy> so where is the official site? <RandomGuy> the official site? <RandomGuy> but what is the official site? 

7.3.1 Getting Infobot

Your first step is to obtain the infobot source code. You can get this from http://www.infobot.org. You will also need to have Perl installed, as infobot is implemented in this language.

7.3.1.1 Configuration

All the configuration files are in the conf directory. Your first stop should be to edit infobot.config . Open this in your favorite text editor and review all of the options, but note especially the values that you will probably want to change for your bot:


ident

The name of the infobot, for internal purposes. The bot will respond to this identity and use its value for certain pronouns. This is perhaps the most important setting for your bot. You should try to make it appropriate for the channel's general theme.


wantNick

The nickname of the infobot, for the IRC server. The bot will attempt to connect under this nickname.


dbName

The prefix for the infobot's database filenames. You may wish to change it to match the name of the bot.


logfile

The name of the bot's log file.


server

The IRC server to connect to.


port

The port to use for the IRC server. You will need to specify this if you use something other than port 6667.


join_channels

The channels your infobot should automatically join.


allowed_channels

The channels the bot should generally be allowed to join.


friendlyBots

If you know of other bots whose knowledge you can trust, place their nicknames here, and the bot will ask them questions that it is unsure about.

The parameters addressing and no-require-question should also be considered , along with the needs of your channel.

7.3.2 Set Up Users

Now you should edit infobot.users . This file holds all the user information and permissions data for your infobot. After the opening comment, which describes the meaning of all flags this file should have by default:

 UserEntry default {     flags    +trmcs;     } 

Consider what kind of permissions you want your infobot to have. +tmrc means that anyone can teach the bot or remove or change a factoid. If you trust people with your bot, this is the best option, but it leaves you prone to vandalism. Alternatively, you could leave it as:

 flags; 

and give out accounts under the infobot to whomever you trust.

The first infobot account should be your own. Change the following to suit yourself:

 UserEntry FooBarBaz {     name    "Jacob Riis";     title    "Bot owner";     flags    +frtmcsSope;     mask    *!*@*.wfu.edu;     mask    *!*@152.17.*.*;     mask    *!*@*.mis.prserv.net;     mask    *!*@eh.net     } 

The portion after UserEntry (in this case, FooBarBaz ) is the name of the account. This name is used when querying the infobot about who has been setting factoids. The name and title fields are primarily for your benefit as the infobot maintainer, so you can remember who the user is. The flags are simply a list of all the powers you wish to grant to the userin this case, all powers.

7.3.3 Using the Infobot

Once the infobot is up and running with your chosen setting, you are ready to use it. In the following examples, the infobot is called Fiona. The following dialogs show off most of the factoid features.

As a general rule, the infobot will respond when you address it with a new factoid, in this case a quote from a film:

 <Foo>  Fiona, today is a good day to die!  <Fiona> Okay, Foo. 

The infobot will then learn that "today" is "a good day to die!"

You can then ask the infobot about this factoid in several different ways:

 <Foo>  Fiona, today?  <Fiona> today is a good day to die! <Foo>  today?  <Fiona> today is a good day to die! <Foo>  today?  <Foo>  what is toDay?  <Fiona> toDay is a good day to die! <Foo>  who is today?  <Fiona> today is a good day to die! 

If you try to teach the infobot a factoid that it has already learned, it will refuse to add it, and it will tell you what the existing meaning is:

 <Foo>  Fiona: today is the day after yesterday.  <Fiona> ... but today is a good day to die! ... 

To add an extra meaning, you can add the "also" token:

 <Foo>  Fiona, today is also the day after yesterday.  <Fiona> Okay, Foo. 

So when you ask what "today" is, the infobot will now respond with both factoids:

 <Foo>  today?  <Fiona> today is a good day to die! or the day after yesterday 

You can also tell an infobot to forget a factoid:

 <Foo>  Fiona, forget today.  <Fiona> Okay, Foo. 

If you tell the infobot to forget a factoid that doesn't exist, it will let you know:

 <Foo>  Fiona, forget tomorrow.  <Fiona> I didn't have anything matching "tomorrow", Foo. 

You can also customize the way in which the infobot responds to questions. By adding <reply> to the start of your fact, you can get the infobot to reply with exactly what you want:

 <Foo>  Fiona, tomorrow is <reply> ./~ Tomorrow, tomorrow, I love you, tomorrow, you're always a day away! ./~  <Fiona> Okay, Foo. <Foo>  Tomorrow?  <Fiona> ./~ Tomorrow, tomorrow, I love you, tomorrow, you're always a day away! ./~ 

To tell an infobot to forget about an existing factoid and replace it with a new one, you can use the "no" token, like so:

 <Foo>  no, Fiona, tomorrow is another day.  <Fiona> Okay, Foo. 

To start introducing some random replies, you can use the character to specify alternatives. This next example adds "Christmas!" to the list of possible replies:

 <Foo>  Fiona, tomorrow is also  Christmas!  <Fiona> Okay, Foo. 

So when you ask the infobot what "tomorrow" is, it will randomly give one of two replies:

 <Foo>  Tomorrow?  <Fiona> Tomorrow is Christmas! <Foo>  Tomorrow?  <Fiona> Tomorrow is Christmas! <Foo>  Tomorrow?  <Fiona> Tomorrow is another day. <Foo>  Tomorrow?  <Fiona> Tomorrow is Christmas! 

You can also define alternative replies in a single line. The next example tells the infobot to respond with one of three actions. The $who variable gets replaced by the nickname of the user who talks to the infobot:

 <Foo>  Fiona, Coke is <action> serves $who a glass of ice cold coke.  <action> cannot serve $who more coke, too much caffeine for you.  <action> happily serves   $who a can of cold Coca Cola (tm)  <Fiona> Okay, Foo. <Foo>  Coke?  * Fiona serves Foo a glass of ice cold coke. 

You can then see the literal definition for "coke":

 <Foo>  literal coke?  <Fiona> Foo: coke =is=  <action> serves $who a glass of ice cold coke.  <action> cannot serve $who more coke, too much caffeine for you.  <action> happily serves $who a can of cold Coca Cola (tm) 

You can even find out who set the factoid:

 <Foo>  Fiona, who set coke?  <Fiona> coke was set by Foo 

The infobot can also pass messages on to other users:

 <Foo>  Fiona, note to Foo: Silly user.  <Fiona> Okay, I will tell that to Foo. <Foo>  Fiona: note to Fennec Fun stuff, man!  <Fiona> Sorry, I don't know who Fennec is; perhaps you mistyped it?  (private message)  <Fiona> Foo left you a note: Silly user. 

7.3.4 Reprogramming the Infobot

The infobot was programmed in Perl. Reprogramming the infobot's internals to change its behavior often results in a mess, so you're on your own here. But if you'd just like to add a new capability, it should be pretty simple. Just edit extras/myRoutines.pl . That file should already contain fairly detailed instructions on what is expected. Here's a sample that implements dice rolls for the Freeform Universal Do-It-Yourself Gaming Engine (FUDGE). Somewhere in sub myRoutines , enter:

 if($addressed && $message =~ /(rollfudgefudgerollfudge roll)? (\d+)?dF/i) {         return fudgeroll();     } 

Later on in the file, insert the subroutine that will perform the dice rolling:

 sub fudgeroll { # Freeform Universal DIY Gaming Engine     (my $dicecount) = @_;     my $rollstring = "$who, the FUDGE dice read: (";     my $rolltotal = 0;     if($dicecount == 0){ $dicecount = 4; } # standard FUDGE roll has 4 dice     if($dicecount > 20){ return "Too many dice, $who!"; }     if($dicecount < 1){ return "Too few dice, $who!"; }     for($x = 0; $x < $dicecount; $x++){         $a = int(rand(3)) - 1;         $rolltotal += $a;         $rollstring .= $a;     }     $_ = $rollstring . "): ";     s/-1/&/g; # make pretty +/- marks     s/1/\+/g;     s/&/\-/g;     return $_ . $rolltotal; } 

You will now be able to use the roll (or fudge , fudgeroll , fudge roll ) command to get the infobot to roll some dice for you. (For example: Fiona, roll 10dF . )

Thomas Whaples

 < Day Day Up > 


IRC Hacks
IRC Hacks
ISBN: 059600687X
EAN: 2147483647
Year: 2004
Pages: 175
Authors: Paul Mutton

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net