Want more features on Pastebin? Sign Up, it's FREE!
Guest

TheGNUGuy

By: a guest on Mar 29th, 2010  |  syntax: Perl  |  size: 1.92 KB  |  views: 240  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # set jabber bot callbacks
  2. $jabberBot->SetMessageCallBacks(chat=>\&chat);
  3. $jabberBot->SetPresenceCallBacks(available=>\&welcome,unavailable=>\&killBot);
  4. $jabberBot->SetCallBacks(receive=>\&prnt,iq=>\&gotIQ);
  5.  
  6. $jabberBot->PresenceSend(type=>"available");
  7. $jabberBot->Process(1);
  8.  
  9. sub welcome
  10. {
  11.         print "Welcome!\n";
  12.         $jabberBot->MessageSend(to=>$jbrBoss->GetJID(),subject=>"",body=>"Hello There!",type=>"chat",priority=>10);
  13.         &keepItGoing;
  14. }
  15.  
  16. sub prnt
  17. {
  18.         print $_[1]."\n";
  19. }
  20.  
  21. #$jabberBot->MessageSend(to=>$jbrBoss->GetJID(),subject=>"",body=>"Hello There! Global...",type=>"chat",priority=>10);
  22. #$jabberBot->Process(5);
  23. #&keepItGoing;
  24.  
  25. sub chat
  26. {
  27.         my ($sessionID,$msg) = @_;
  28.         $dump->pl2xml($msg);
  29.         if($msg->GetType() ne 'get' && $msg->GetType() ne 'set' && $msg->GetType() ne '')
  30.         {
  31.                 my $jbrCmd = &trimSpaces($msg->GetBody());
  32.                 my $dbQry = $dbh->prepare("SELECT command,acknowledgement FROM commands WHERE message = '".lc($jbrCmd)."'");
  33.                 $dbQry->execute();
  34.                 if($dbQry->rows() > 0 && $jbrCmd !~ /^insert/si)
  35.                 {
  36.                         my $ref = $dbQry->fetchrow_hashref();
  37.                         $dbQry->finish();
  38.                         $jabberBot->MessageSend(to=>$msg->GetFrom(),subject=>"",body=>$ref->{'acknowledgement'},type=>"chat",priority=>10);
  39.                         eval $ref->{'command'};
  40.                         &keepItGoing;
  41.                 }
  42.                 else
  43.                 {
  44.                         $jabberBot->MessageSend(to=>$msg->GetFrom(),subject=>"",body=>"I didn't understand you!",type=>"chat",priority=>10);
  45.                         $dbQry->finish();
  46.                         &keepItGoing;
  47.                 }
  48.         }
  49. }
  50.  
  51. sub gotIQ
  52. {
  53.         print "iq\n";
  54. }
  55.  
  56. sub trimSpaces
  57. {
  58.         my $string = $_[0];
  59.         $string =~ s/^\s+//; #remove leading spaces
  60.         $string =~ s/\s+$//; #remove trailing spaces
  61.         return $string;
  62. }
  63.  
  64. sub keepItGoing
  65. {
  66.        
  67.         print "keepItGoing!\n";
  68.         my $proc = $jabberBot->Process(1);
  69.         while(defined($proc) && $proc != 1)
  70.         {
  71.                 $proc = $jabberBot->Process(1);
  72.         }
  73. }
  74.  
  75. sub killBot
  76. {
  77.         print "killing\n";
  78.         $jabberBot->MessageSend(to=>$_[0]->GetFrom(),subject=>"",body=>"Logging Out!",type=>"chat",priority=>10);
  79.         $jabberBot->Process(1);
  80.         $jabberBot->Disconnect();
  81.         exit;
  82. }
clone this paste RAW Paste Data