For module information, check http://www.aichaos.com/docs/alpha.html - there you'll find how to use the module, and a simple tutorial on how to program Alpha replies.
Here's the test reply file, if you want to see what it looks like:
Code:
// Test Replies<br /><br />// A standard reply to "hello", with multiple responses.<br />+ hello<br />- Hello there!<br />- What's up?<br />- This is random, eh?<br /><br />// A simple one-reply response to "what's up"<br />+ what's up<br />- Not much, you?<br /><br />// A test using <star1><br />+ say *<br />- Um.... "<star1>"<br /><br />// This reply is referred to below.<br />+ identify yourself<br />- I am Alpha.<br /><br />// Refers the asker back to the reply above.<br />+ who are you<br />@ identify yourself<br /><br />// Conditionals Test<br />+ am i your master<br />* if master = 1::Yes, you are my master.<br />- No, you are not my master.<br /><br />// A Conversation Holder: Knock Knock!<br />+ knock knock<br />- Who's there?<br />& <msg> who?<br />& Ha! <msg>! That's a good one!<br /><br />// A Conversation Holder: Rambling!<br />+ are you crazy<br />- I was crazy once.<br />& They locked me away...<br />& In a room with padded walls.<br />& There were rats there...<br />& Did I mention I was crazy once?
It's a simple line-by-line command-driven language. The first character on each line is the command (the list of commands can be found on the module's POD, as stated above).
When getting a reply, you send $id and $msg -- $id would (in most cases) be your user's username; it's used to keep track of conversation (for example, that "knock knock" reply, it needs to keep track of the user to know to go back to that reply next time).
And a quick overview of the synopsis:
Code:
use Chatbot::Alpha;<br /><br />my $alpha = new Chatbot::Alpha (debug => 1);<br /><br />$alpha->load_folder ('./replies');<br />$alpha->load_file ('./more_replies.txt');<br /><br /># Set and remove variables.<br />$alpha->set_variable ("master", "1");<br />$alpha->remove_variable ("master");<br />$alpha->set_variable ("var", "value");<br />$alpha->clear_variables;<br /><br /># Go get a reply.<br />my $user = "foo";<br />my $message = "Hello Alpha";<br />my $reply = $alpha->reply ($user,$message);
So tell me what you think. Post any questions, comments, bugs, compliments, etc. in reply here.
Also: This module has been tested quite thoroughly, although I have not tested what happens if you use the commands in other ways (for example, if you have a command sequence of "+ - & -", I don't know what would happen)... so if you want to test out different combinations and report back with their results (if they broke it, or how it turned out if it did work)... that would be nice too. _________________ Current Site (2008) http://www.cuvou.com/
Joined: 15 Mar 2004 Posts: 661 Location: Manchester, UK
Posted: Fri Nov 12, 2004 4:23 pm Post subject:
Thats cool I might use this.... +1 _________________ MSN: gavin [at] gavinbrittain [dot] co [dot] uk
E-Portfolio: www.gavinbrittain.co.uk (New version comming soon)
delete $self->{alpha}; delete $self->{room}; $self->sendmsg("-info- You have now exited Alpha mode.");
} else { my $alpha = new Chatbot::Alpha (debug => 0); my $load = $alpha->load_file ('./testreplies.txt'); die "Error: $load" unless $load == 1; my $id = $username; chomp $msg; $alpha->set_variable ("username", $username); my $reply = $alpha->reply ($username,$msg); $alpha->remove_variable ("username"); $self->sendmsg("$reply", Name => "[ Alpha ] - [ Type !exit to leave Alpha Mode ]"); }
elsif ($msg =~ /^!alpha$/){ $self->{room} = 1; $self->{alpha} = 1; $self->sendmsg("You are now chatting to Alpha.\n\nYou can pick up the module at: http://aichaos.com");
ok, maybe I'm the one that's mixed up. You're logic didn't seem right. In any case, you create a new $alpha object every single time a message comes in, right? That's not good.
After many many hours of being lazy, I've created the files to put the Alpha brain into Juggernaut.
If your Juggernaut has a "brains" folder, this should be compatible (I forget what version started doing that ).
Zip attached, extract the two files (alpha_load.pl and alpha_get.pl) into your "brains" folder. And to make your bot use them, change your bot's "Brain:" and "Reply" fields to:
Quote:
Brain: Alpha Reply: ./replies/alpha
The reply folder can be whereever you want to put your Alpha replies into. All reply files should be a .TXT, or you can edit alpha_load.pl to change that.
The Codes:
Code:
sub alpha_load {<br /> # Incoming data for the brain.<br /> my ($bot,$brain,$dir) = @_;<br /><br /> use Chatbot::Alpha;<br /><br /> # Get the Alpha brain going.<br /> $chaos->{$bot}->{_alpha} = new Chatbot::Alpha (<br /> debug => 0,<br /> );<br /><br /> # Load the directory.<br /> $chaos->{$bot}->{_alpha}->load_folder ($dir, "txt");<br /><br /> # All done!<br /> return 1;<br />}
Code:
sub alpha_get {<br /> # Incoming data for the brain.<br /> my ($brain,$self,$client,$listener,$msg,$omsg,$sn) = @_;<br /><br /> $brain = lc($brain);<br /> $brain =~ s/ //g;<br /><br /> $sn = lc($sn);<br /> $sn =~ s/ //g;<br /><br /> # Input all kinds of variables.<br /> foreach my $var (keys %{$chaos->{_users}->{$client}}) {<br /> $chaos->{$sn}->{_alpha}->set_variable ($var, $chaos->{_users}->{$client}->{$var});<br /> }<br /><br /> my $reply = $chaos->{$sn}->{_alpha}->reply ($client,$msg);<br /><br /> # Clear variables.<br /> $chaos->{$sn}->{_alpha}->clear_variables;<br /><br /> return $reply;<br />}
It sends all user variables (name, age, etc.) into the Alpha brain. If you want it to send more (i.e. username, isAdmin, isMaster, etc.) you can put in the codes to do that yourself.