User Control Panel
Advertisements

HELP US, HELP YOU!

Command line Bot

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl
View unanswered posts
Author Message
NiZ
Newbie
Newbie


Joined: 06 Jul 2006
Posts: 1


PostPosted: Thu Jul 06, 2006 3:20 am    Post subject: Command line Bot Reply with quote

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.");
}

$oscar = Net::OSCAR->new();
$oscar->set_callback_im_in(\&im_in);
$oscar->signon($screenname, $password);
   
while(1)
{
   $oscar->do_one_loop();
}

Any help would be greatly appreciated.

Thanks,
NiZ
Back to top
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Thu Jul 06, 2006 4:14 pm    Post subject: Reply with quote

@VARS = split (EXPRESSION, FROM_VARIABLE[, HOW_MANY_TIMES])

Code:
elsif ($message =~ /^!send (.*?)$/i) {
   my ($to,$what) = split(/\s+/, $1, 2);
   $oscar->send_im ($to, $what);
}


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!"

http://search.cpan.org/perldoc?perlfunc

_________________
Current Site (2008) http://www.cuvou.com/
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group