Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6.68 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use POE;
  5. use POE::Component::IRC;
  6. use POE::Component::IRC::Common;
  7. use POE::Component::IRC::Qnet;
  8. use POE::Component::IRC::Qnet::State;
  9. use Date::Calc;
  10.  
  11. #Starting up the Bot
  12. my ($irc) = POE::Component::IRC::Qnet::State->spawn();
  13.  
  14. POE::Session->create(
  15.   inline_states => {
  16.     _start     => \&bot_start,
  17.     irc_001    => \&on_connect,
  18.     irc_public => \&on_public,
  19.     irc_join   => \&on_join,
  20.     irc_nick_sync => \&synced,
  21.     irc_invite => \&invite,
  22.     irc_ctcp_action => \&action,
  23.     irc_nick  => \&nick,
  24.     irc_mode  => \&mode,
  25.     irc_msg   => \&command,
  26.     irc_kick  => \&kick,    
  27.     irc_topic => \&topic,
  28.     heartbeat => \&heartbeat,
  29.   },
  30. );
  31.  
  32. sub bot_start {
  33.   $irc->yield(register => "all");
  34.   $irc->yield(
  35.     connect => {
  36.       Nick     => 'TheCynicalBot',
  37.       Username => 'TheCynicalBot',
  38.       Ircname  => 'Perlbot',
  39.       Server   => 'localhost',
  40.       Port     => '10001',
  41.       Password => '',
  42.     }
  43.   );
  44.  print "Connected to Quakenet....\n";
  45. }
  46.  
  47. sub on_connect {
  48.   my @channels = ('#cynicalbrit', '#cynical.shoutcast');
  49.   foreach my $channels (@channels) {
  50.     $irc->yield(join => $channels);
  51.     print "Joining " . $channels . "\n";
  52.   }
  53. }
  54.  
  55. sub heartbeat {
  56.     $_[KERNEL]->delay(heartbeat => 15);
  57. }
  58.  
  59. #Global Variables
  60.  
  61. my %stafftitle = (
  62. 'Raltharg' => '#cynicalbrit Admin',
  63. 'TotalBiscuit' => 'the Cynical Brit',
  64. 'iKing' => '#cynicalbrit Moderator',
  65. 'Amaranthea' => '#cynicalbrit Moderator'
  66. );
  67.  
  68. my @kicks = ('Good job, Sir', 'He got served!', 'Piss off you lower form of life.', '"You are the weakest link, goodbye.', 'Hey look, there is a troll on your face', "I don't like you", 'Want a cookie? Too bad.');
  69.  
  70. my @idiotlist = ('\?', '\bwhen\b', '\bshow\b', '\bblue\s*plz\b', '\btonight\b', '\bstarts\b', '\bstream\b', '\bwatch\b', '\blisten\b', '\btotal\s*biscuit\b');
  71.  
  72. #Subroutines
  73.  
  74. sub on_public {
  75.   my ($kernel, $who, $where, $msg) = @_[KERNEL, ARG0, ARG1, ARG2];
  76.   my $nick    = (split /!/, $who)[0];
  77.   my $channel = $where->[0];
  78.   my $ts      = scalar localtime;
  79.   print " [$ts] <$channel> <$nick> $msg\n";
  80.  
  81.   my $idiotcount = '0';
  82.  
  83.   if ($msg =~ /^!song$/i) {
  84.         $irc->yield(privmsg => '#cynical.shoutcast' => '!song ' . $nick . '');
  85.     }
  86.  
  87.   if ($channel eq '#cynical.shoutcast') {
  88.         $irc->yield(privmsg => '#cynicalbrit' => $msg);
  89.     }
  90.  
  91.   if ($irc->is_channel_operator($channel, $nick)) {
  92.      if ($msg =~ /^!peak$/i || $msg =~ /^!listeners$/i) {
  93.          $irc->yield(privmsg => '#cynical.shoutcast' => $msg);
  94.         };
  95.     };
  96.    
  97.   foreach my $idiot (@idiotlist) {
  98.      if ($msg =~ m/$idiot/i) {
  99.          $idiotcount++;
  100.          }   
  101.      }
  102.  
  103.    if ($idiotcount >= '3') {
  104.          $irc->yield(kick => $channel => $nick => 'Your stupidity has exceeded the set threshold.');
  105.     }
  106.  
  107.  }
  108.  
  109. sub on_join {
  110.   my ($kernel, $who, $channel) = @_[KERNEL, ARG0, ARG1];
  111.   my $nick    = (split /!/, $who)[0];
  112.   my $ts      = scalar localtime;
  113.   print " [$ts] <$channel> $nick joined\n";
  114. }
  115.  
  116. sub synced {
  117.   my ($kernel, $nick, $channel) = @_[KERNEL, ARG0, ARG1];
  118.   my $ts      = scalar localtime;
  119.  
  120.   my $qname   = $irc->is_nick_authed($nick);
  121.  
  122.   if (($nick =~ /^Total/i) || ($nick =~ /Bain/i) || ($nick =~ /Biscuit/i)) {
  123.          if (!$qname) {
  124.          $irc->yield(kick => $channel => $nick => 'You are not TotalBiscuit');
  125.          } elsif ($qname ne 'TotalBiscuit') {
  126.          $irc->yield(kick => $channel => $nick => 'You are not TotalBiscuit');
  127.      }
  128.   }
  129.  
  130.   if ($qname) {
  131.    foreach my $staff (keys %stafftitle) {
  132.     if ($qname eq $staff) {
  133.         $irc->yield(mode => '' . $channel . ' +o ' . $nick . '');
  134.         $irc->yield(privmsg => $channel => 'Welcome ' . $nick . ', ' . $stafftitle{$staff} . '.');
  135.     }
  136.    }
  137.   }
  138. }
  139.  
  140. sub nick {
  141.   my ($kernel, $who, $newnick) = @_[KERNEL, ARG0, ARG1];
  142.   my $nick    = (split /!/, $who)[0];
  143.   my $ts      = scalar localtime;
  144.   my $channel = '#cynicalbrit';  
  145.  
  146.   my $qname   = $irc->is_nick_authed($newnick);
  147.  
  148.   if (($newnick =~ /^Total/i) || ($newnick =~ /Bain/i) || ($nick =~ /Biscuit/i)) {
  149.          if (!$qname) {
  150.          $irc->yield(kick => $channel => $nick => 'You are not TotalBiscuit');
  151.          $irc->yield(kick => $channel => $newnick => 'You are not TotalBiscuit');
  152.          } elsif ($qname ne 'TotalBiscuit') {
  153.          $irc->yield(kick => $channel => $nick => 'You are not TotalBiscuit');
  154.          $irc->yield(kick => $channel => $newnick => 'You are not TotalBiscuit');
  155.      }
  156.   }
  157.  
  158. }
  159.  
  160. sub invite {
  161.   my ($kernel, $who, $channel) = @_[KERNEL, ARG0, ARG1];
  162.   my $nick    = (split /!/, $who)[0];
  163.   my $ts      = scalar localtime;
  164.  
  165.   my $qname   = $irc->is_nick_authed($nick);
  166.  
  167.   if (!$qname) {
  168.      $irc->yield(notice => $nick => 'You do not have necessary permissions to use invite, if you are staff, please log in or fuck off.');
  169.   } elsif ($qname) {
  170.    foreach my $staff (keys %stafftitle) {
  171.     if ($qname eq $staff) {
  172.      $irc->yield(join => $channel);
  173.      $irc->yield(notice => $nick => 'Joining ' . $channel . '.');
  174.      print "Joining $channel\n";
  175.     }
  176.    }
  177.   }
  178. }
  179.  
  180. sub action {
  181.   my ($kernel, $who, $where, $action) = @_[KERNEL, ARG0, ARG1, ARG2];
  182.   my $nick    = (split /!/, $who)[0];
  183.   my $channel = $where->[0];
  184.   my $ts      = scalar localtime;
  185.   print " [$ts] <$channel> *$nick $action\n";
  186.  
  187.   if ($action =~ /^slaps/i) {
  188.          $irc->yield(kick => $channel => $nick => 'Use of the slap command is prohibited.');
  189.     }
  190. }
  191.  
  192. sub topic {
  193.   my ($kernel, $who, $where, $topicscast) = @_[KERNEL, ARG0, ARG1, ARG2];
  194.   my $nick    = (split /!/, $who)[0];
  195.  
  196.    if ($where eq '#cynicalbot.shoutcast') {
  197.         $irc->yield(topic => '#cynicalbrit' => $topicscast);
  198.     }
  199. }  
  200.  
  201. sub mode {
  202.   my ($kernel, $who, $channel, $mode, @victim) = @_[KERNEL, ARG0, ARG1, ARG2, ARG3 .. $#_];
  203.   my $nick    = (split /!/, $who)[0];
  204.   my $ts      = scalar localtime;
  205.  
  206.     foreach my $victim (@victim) {
  207.          print " [$ts] <$channel> $nick applies $mode $victim\n";
  208.     }
  209. }
  210.  
  211. sub command {
  212.   my ($kernel, $who, $msg) = @_[KERNEL, ARG0, ARG2];
  213.   my $nick    = (split /!/, $who)[0];
  214.   my $ts      = scalar localtime;
  215.   my $qname   = $irc->is_nick_authed($nick);
  216.  
  217.   print " [$ts] <Private Command> <$nick> $msg\n";
  218.  
  219. }
  220.  
  221. sub kick {
  222.   my ($kernel, $who, $channel, $victim, $why) = @_[KERNEL, ARG0, ARG1, ARG2, ARG3];
  223.   my $nick    = (split /!/, $who)[0];
  224.   my $ts      = scalar localtime;
  225.   my $qname   = $irc->is_nick_authed($nick);
  226.  
  227.   print " [$ts] <$channel> $nick has kicked $victim ($why)\n";
  228.  
  229.  
  230.   if ($qname) {
  231.    foreach my $staff (keys %stafftitle) {
  232.     if ($qname eq $staff) {
  233.         $irc->yield(privmsg => $channel => $kicks[int rand($#kicks+1)]);
  234.     }
  235.    }
  236.   }
  237.    
  238. }
  239.  
  240. #Closing
  241. $poe_kernel->run();
  242. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement