Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.20 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # This is a simple IRC bot that just rot13 encrypts public messages.
  3. # It responds to "rot13 <text to encrypt>".
  4. use warnings;
  5. use strict;
  6. use POE;
  7. use POE::Component::IRC;
  8. use POE::Component::IRC::Common qw(matches_mask_array);
  9.  
  10. # Create the component that will represent an IRC network.
  11. my ($irc) = POE::Component::IRC->spawn();
  12.  
  13. my %usermodes = (
  14. '*!*@Raltharg.users.quakenet.org' => 'o',
  15. );
  16.  
  17. # Create the bot session.  The new() call specifies the events the bot
  18. # knows about and the functions that will handle those events.
  19. POE::Session->create(
  20.   inline_states => {
  21.     _start     => \&bot_start,
  22.     irc_001    => \&on_connect,
  23.     irc_public => \&on_public,
  24.     irc_join   => \&on_join,
  25.   },
  26. );
  27.  
  28. # The bot session has started.  Register this bot with the "magnet"
  29. # IRC component.  Select a nickname.  Connect to a server.
  30. sub bot_start {
  31.   $irc->yield(register => "all");
  32.   my $nick = 'TheCynicalBot';
  33.   $irc->yield(
  34.     connect => {
  35.       Nick     => $nick,
  36.       Username => 'TheCynicalBot',
  37.       Ircname  => 'A Very Cynical Bot',
  38.       Server   => 'localhost',
  39.       Port     => '10001',
  40.       Password => '*********',
  41.     }
  42.   );
  43. }
  44.  
  45. # The bot has successfully connected to a server.  Join a channel.
  46. sub on_connect {
  47.   $irc->yield(join => '#cynicalbrit');
  48. }
  49.  
  50. # The bot has received a public message.  Parse it for commands, and
  51. # respond to interesting things.
  52. sub on_public {
  53.   my ($kernel, $who, $where, $msg) = @_[KERNEL, ARG0, ARG1, ARG2];
  54.   my $nick    = (split /!/, $who)[0];
  55.   my $channel = $where->[0];
  56.   my $ts      = scalar localtime;
  57.   print " [$ts] <$nick:$channel> $msg\n";
  58. }
  59.  
  60. sub on_join {
  61.   my ($kernel, $who, $channel) = @_[KERNEL, ARG0, ARG1];
  62.   my $nick    = (split /!/, $who)[0];
  63.   my $msg     = 'Joined';
  64.   my $ts      = scalar localtime;
  65.   print " [$ts] $who $msg $channel\n";
  66.   my @matches = matches_mask_array(keys(%usermodes), [$who]);
  67.         print "matches = @matches\n";
  68.         foreach my $match (@matches) {
  69.                 print "/mode $channel $nick $usermodes{$match}\n";
  70.                 $irc->yield(mode => $channel => $nick => $usermodes{$match$
  71.         }
  72. }
  73.  
  74. # Run the bot until it is done.
  75. $poe_kernel->run();
  76. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement