Posted: Thu Jul 06, 2006 3:20 am Post subject: Command line Bot
Alright, im making a AIM Bot that i will be able to control from my SN. So I am wondering how i can get the bot to recgonize the options of a certain command. Right now i only have !send and !join. The !send command format is like this !send [user] [message] so this brings me to my question, how do i get it to pick out the user and the message, then use those to send the inputted message to the inputted user? So like if i were to put: !send goober Hey Dude!, it would send 'goober' the message 'Hey Dude!'. I think you know what the !join command would do. Well here is the current source to my bot:
Code:
#NiZ AIM Bot v0.2
use Net::OSCAR qw(:standard);
my $screenname = "user";
my $password = "pass";
sub im_in
{
my($oscar, $sender, $message, $is_away) = @_;
$message =~ s/<(.|\n)+?>//g;
print "[AWAY] " if $is_away;
print "$sender: $message\n";
if ($sender =~ 'admin')
{
if ($message =~ '!help')
{
$oscar->send_im ('admin', '!send [user] [message] - to send a message');
$oscar->send_im ('admin', '!join [room] - to sign me off');
$oscar->send_im ('admin', '!info - for info on me');
$oscar->send_im ('admin', '!help - for help');
$oscar->send_im ('admin', '!signoff - to sign me off');
}
elsif ($message =~ '!send')
{
$oscar->send_im ('admin', 'Needs to be coded');
}
elsif ($message =~ '!join')
{
$oscar->chat_join('Chat Join needs to be coded');
}
elsif ($message =~ '!info')
{
$oscar->send_im ('admin', '(`ˇ.ˇ´¯`ˇ.ˇNiZ BoT v0.2ˇ.ˇ´¯`ˇ.ˇ´)');
$oscar->send_im ('admin', '(`ˇ.ˇ´¯`ˇ.ˇCoded by NiZˇ.ˇ´¯`ˇ.ˇ´)');
}
elsif ($message =~ '!signoff')
{
$oscar->signoff;
}
else
{
$oscar->send_im ('admin', 'Type: !help for a list of commands');
}
}
if ($sender ne 'admin')
{
$oscar->send_im ('admin', $sender . ' has sent this message : ' . "'". $message . "'" .' to your bot!');
$oscar->send_im ($sender, 'This bot is currently being coded, check back soon. :)');
}
$oscar->set_info("This bot is currently being coded by NiZ.");
}
So that splits $1 (the data captured in the (.*?) which in this case might be "goober Hey Dude!"), at a space (\s+) and it splits it into two variables, $to being "goober" and $what being "Hey Dude!"