Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use DBI;
- use IO::Socket;
- my $server = "localhost";
- my $port = "6667";
- my $bot_nickname = "WatchBot";
- my $nickserv_pass = "";
- my $bot_user = "WatchBot";
- my $admin_watch_channel = "#debug";
- # Bot MUST have Oper privs on login!
- my $oper_user = ""; # Edit this!!!
- my $oper_pass = ""; # Edit this!!!
- my @Opers = qw(linus rodja square ZsuZsaZsa squared casey); # <- Users to auto-SAJOIN when they join #debug
- ## MySQL Constants
- my $db_database = "gazelle";
- my $db_host = ""; # Edit this!!!
- my $db_port = ""; # Edit this!!!
- my $db_user = ""; # Edit this!!!
- my $db_pass = ""; # Edit this!!!
- my $ircsock = new IO::Socket::INET(PeerAddr => $server, PeerPort => $port, Proto => 'tcp') or die "Can't connect to the IRC server!\n";
- print $ircsock "NICK $bot_nickname\r\n";
- print $ircsock "USER $bot_user 8 * :IRC Channel Watching Bot\r\n";
- print $ircsock "PRIVMSG nickserv identify $nickserv_pass\r\n";
- print $ircsock "OPER $oper_user $oper_pass\r\n";
- print $ircsock "SAJOIN $bot_nickname #staff\r\n";
- print $ircsock "SAJOIN $bot_nickname #swarm\r\n";
- print $ircsock "SAJOIN $bot_nickname #announce\r\n";
- print $ircsock "SAJOIN $bot_nickname #help\r\n";
- print $ircsock "SAJOIN $bot_nickname #invite\r\n";
- print $ircsock "SAJOIN $bot_nickname #disabled\r\n";
- while (my $input = <$ircsock>) {
- if ($input =~ /004/) {
- last;
- }
- elsif ($input =~ /433/) {
- die "Nickname is in use!";
- }
- print $input;
- }
- print $ircsock "JOIN $admin_watch_channel\r\n";
- while (chomp(my $input = <$ircsock>)) {
- print "$input\n";
- if ($input =~ /^PING(.*)$/i) {
- print $ircsock "PONG $1\r\n";
- } elsif ($input =~ /^:(.*)!(.*)@.* JOIN :$admin_watch_channel/i) {
- if(isOper($1)==1) {
- print $ircsock "SAJOIN $1 #staff\r\n";
- print $ircsock "SAJOIN $1 #announce\r\n";
- print $ircsock "SAJOIN $1 #swarm\r\n";
- print $ircsock "SAJOIN $1 #help\r\n";
- print $ircsock "SAJOIN $1 #invite\r\n";
- print $ircsock "SAJOIN $1 #disabled\r\n";
- }
- } elsif ($input =~ /^:(.*)!(.*)@.* JOIN :#swarm/i) {
- if(getGreeting($2, "#swarm")==1) {
- print "**** getGreeting SUCCESS ****\r\n";
- }
- if(onIRC("1", $2)==1) {
- print "**** onIRC SUCCESS | User: $2, IRC: 1 ****\r\n";
- }
- } elsif ($input =~ /^:(.*)!(.*)@.* JOIN :#staff/i) {
- if(getGreeting($2, "#staff")==1) {
- print "**** getGreeting SUCCESS ****\r\n";
- }
- } elsif ($input =~ /^:(.*)!(.*)@.* PART #swarm :.*/i) {
- if(onIRC("0", $2)==1) {
- print "**** onIRC SUCCESS | User: $2, IRC: 0 ****\r\n";
- }
- } elsif ($input =~ /^:(.*)!(.*)@.* QUIT :.*/i) {
- print "**** USER $2 QUIT! ****\r\n";
- if(onIRC("0", $2)==1) {
- print "**** onIRC SUCCESS | User: $2, IRC: 0 ****\r\n";
- }
- }
- }
- sub isOper() {
- my $nick = $_[0];
- foreach(@Opers) {
- if($_ eq $nick) {
- return 1;
- }
- }
- return 0;
- }
- sub getGreeting() {
- my $user = $_[0];
- my $channel = $_[1];
- my $dsn = "dbi:mysql:$db_database:$db_host:$db_port";
- my $DB = DBI->connect($dsn, $db_user, $db_pass);
- my $umquery = qq/select ID from users_main where Username='$user'/;
- my $umsql = $DB->prepare($umquery);
- $umsql->execute();
- if ($umsql->{NUM_OF_FIELDS}<1) {
- print "**** IRC User $user not found in database! ****\r\n";
- return 0;
- } else {
- my @res = $umsql->fetchrow_array;
- my $userid = @res[0];
- print "**** UserID for $user found to be $userid! ****\r\n";
- my $uiquery = qq/select IRCGreeting from users_info where UserID='$userid'/;
- my $uisql = $DB->prepare($uiquery);
- $uisql->execute();
- my @res2 = $uisql->fetchrow_array;
- my $ircgreeting = @res2[0];
- if ($ircgreeting ne "") {
- print $ircsock "PRIVMSG $channel $user joined the channel: $ircgreeting\r\n";
- }
- return 1;
- }
- return 0;
- }
- sub onIRC() {
- my $val = $_[0];
- my $user = $_[1];
- my $dsn = "dbi:mysql:$db_database:$db_host:$db_port";
- my $DB = DBI->connect($dsn, $db_user, $db_pass);
- my $umquery = qq/select ID from users_main where Username='$user'/;
- my $umsql = $DB->prepare($umquery);
- $umsql->execute();
- if ($umsql->{NUM_OF_FIELDS}<1) {
- print "**** IRC User $user not found in database! ****\r\n";
- return 0;
- } else {
- my @res = $umsql->fetchrow_array;
- my $userid = @res[0];
- my $uiquery = qq/update users_info set OnIRC='$val' where UserID='$userid'/;
- my $uisql = $DB->prepare($uiquery);
- $uisql->execute();
- return 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement