Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 4.49 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use DBI;
  5. use IO::Socket;
  6.  
  7. my $server = "localhost";
  8. my $port = "6667";
  9. my $bot_nickname = "WatchBot";
  10. my $nickserv_pass = "";
  11. my $bot_user = "WatchBot";
  12. my $admin_watch_channel = "#debug";
  13. # Bot MUST have Oper privs on login!
  14. my $oper_user = ""; # Edit this!!!
  15. my $oper_pass = ""; # Edit this!!!
  16. my @Opers = qw(linus rodja square ZsuZsaZsa squared casey); # <- Users to auto-SAJOIN when they join #debug
  17.  
  18. ## MySQL Constants
  19. my $db_database = "gazelle";
  20. my $db_host = ""; # Edit this!!!
  21. my $db_port = ""; # Edit this!!!
  22. my $db_user = ""; # Edit this!!!
  23. my $db_pass = ""; # Edit this!!!
  24.  
  25.  
  26. my $ircsock = new IO::Socket::INET(PeerAddr => $server, PeerPort => $port, Proto => 'tcp') or die "Can't connect to the IRC server!\n";
  27.  
  28. print $ircsock "NICK $bot_nickname\r\n";
  29. print $ircsock "USER $bot_user 8 * :IRC Channel Watching Bot\r\n";
  30. print $ircsock "PRIVMSG nickserv identify $nickserv_pass\r\n";
  31. print $ircsock "OPER $oper_user $oper_pass\r\n";
  32. print $ircsock "SAJOIN $bot_nickname #staff\r\n";
  33. print $ircsock "SAJOIN $bot_nickname #swarm\r\n";
  34. print $ircsock "SAJOIN $bot_nickname #announce\r\n";
  35. print $ircsock "SAJOIN $bot_nickname #help\r\n";
  36. print $ircsock "SAJOIN $bot_nickname #invite\r\n";
  37. print $ircsock "SAJOIN $bot_nickname #disabled\r\n";
  38.  
  39. while (my $input = <$ircsock>) {
  40.     if ($input =~ /004/) {
  41.             last;
  42.         }
  43.         elsif ($input =~ /433/) {
  44.             die "Nickname is in use!";
  45.         }
  46.      print $input;
  47. }
  48.  
  49. print $ircsock "JOIN $admin_watch_channel\r\n";
  50.  
  51. while (chomp(my $input = <$ircsock>)) {    
  52.         print "$input\n";
  53.         if ($input =~ /^PING(.*)$/i) {
  54.             print $ircsock "PONG $1\r\n";
  55.         } elsif ($input =~ /^:(.*)!(.*)@.* JOIN :$admin_watch_channel/i) {
  56.             if(isOper($1)==1) {
  57.                     print $ircsock "SAJOIN $1 #staff\r\n";
  58.                     print $ircsock "SAJOIN $1 #announce\r\n";
  59.             print $ircsock "SAJOIN $1 #swarm\r\n";
  60.                     print $ircsock "SAJOIN $1 #help\r\n";
  61.                     print $ircsock "SAJOIN $1 #invite\r\n";
  62.                     print $ircsock "SAJOIN $1 #disabled\r\n";
  63.             }
  64.         } elsif ($input =~ /^:(.*)!(.*)@.* JOIN :#swarm/i) {
  65.         if(getGreeting($2, "#swarm")==1) {
  66.             print "**** getGreeting SUCCESS ****\r\n";
  67.         }
  68.         if(onIRC("1", $2)==1) {
  69.             print "**** onIRC SUCCESS | User: $2, IRC: 1 ****\r\n";
  70.         }
  71.     } elsif ($input =~ /^:(.*)!(.*)@.* JOIN :#staff/i) {
  72.         if(getGreeting($2, "#staff")==1) {
  73.             print "**** getGreeting SUCCESS ****\r\n";
  74.         }
  75.     } elsif ($input =~ /^:(.*)!(.*)@.* PART #swarm :.*/i) {
  76.         if(onIRC("0", $2)==1) {
  77.             print "**** onIRC SUCCESS | User: $2, IRC: 0 ****\r\n";
  78.         }
  79.     } elsif ($input =~ /^:(.*)!(.*)@.* QUIT :.*/i) {
  80.         print "**** USER $2 QUIT! ****\r\n";
  81.         if(onIRC("0", $2)==1) {
  82.             print "**** onIRC SUCCESS | User: $2, IRC: 0 ****\r\n";
  83.         }
  84.     }
  85. }
  86.  
  87. sub isOper() {
  88.         my $nick = $_[0];
  89.         foreach(@Opers) {
  90.             if($_ eq $nick) {
  91.                 return 1;
  92.             }
  93.         }
  94.         return 0;
  95. }
  96.  
  97. sub getGreeting() {
  98.     my $user = $_[0];
  99.     my $channel = $_[1];
  100.     my $dsn = "dbi:mysql:$db_database:$db_host:$db_port";
  101.     my $DB = DBI->connect($dsn, $db_user, $db_pass);
  102.  
  103.     my $umquery = qq/select ID from users_main where Username='$user'/;
  104.     my $umsql = $DB->prepare($umquery);
  105.     $umsql->execute();
  106.     if ($umsql->{NUM_OF_FIELDS}<1) {
  107.         print "**** IRC User $user not found in database! ****\r\n";
  108.         return 0;
  109.     } else {
  110.         my @res = $umsql->fetchrow_array;
  111.         my $userid = @res[0];
  112.         print "**** UserID for $user found to be $userid! ****\r\n";
  113.         my $uiquery = qq/select IRCGreeting from users_info where UserID='$userid'/;
  114.         my $uisql = $DB->prepare($uiquery);
  115.         $uisql->execute();
  116.         my @res2 = $uisql->fetchrow_array;
  117.         my $ircgreeting = @res2[0];
  118.         if ($ircgreeting ne "") {
  119.             print $ircsock "PRIVMSG $channel $user joined the channel: $ircgreeting\r\n";
  120.         }
  121.         return 1;
  122.     }  
  123.     return 0;
  124. }
  125.  
  126. sub onIRC() {
  127.     my $val = $_[0];
  128.     my $user = $_[1];
  129.    
  130.     my $dsn = "dbi:mysql:$db_database:$db_host:$db_port";
  131.     my $DB = DBI->connect($dsn, $db_user, $db_pass);
  132.  
  133.     my $umquery = qq/select ID from users_main where Username='$user'/;
  134.     my $umsql = $DB->prepare($umquery);
  135.     $umsql->execute();
  136.     if ($umsql->{NUM_OF_FIELDS}<1) {
  137.         print "**** IRC User $user not found in database! ****\r\n";
  138.         return 0;
  139.     } else {
  140.         my @res = $umsql->fetchrow_array;
  141.         my $userid = @res[0];
  142.         my $uiquery = qq/update users_info set OnIRC='$val' where UserID='$userid'/;
  143.         my $uisql = $DB->prepare($uiquery);
  144.         $uisql->execute();
  145.         return 1;
  146.     }
  147.     return 0;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement