Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use warnings;
- use strict;
- use POE;
- use POE::Component::IRC;
- use POE::Component::IRC::Common;
- use POE::Component::IRC::Qnet;
- use POE::Component::IRC::Qnet::State;
- use Date::Calc;
- use Net::MySQL;
- #Config:
- #Bot Nickname
- my $botnick = 'TheCynicalTest';
- #Server Information
- my $botserver = 'irc.quakenet.org';
- my $botport = '6667';
- my $botpass = '';
- #MySQL
- my $sqlhost = 'localhost';
- my $sqldatabase = 'ralth';
- my $sqluser = 'ralth';
- my $sqlpassword = 'nosoupforyou';
- #Channels to join
- #Main Channel First
- my @channels = ('#cynicalbrit', '#cynicaltest');
- #Initiate IP-nick buffer
- my %buffer = ();
- #TBNameCheck
- my $tbnickcheck = 1;
- #End of Config
- #Starting Session
- my ($irc) = POE::Component::IRC::Qnet::State->spawn();
- #Connect to MySQL Database
- print "Connecting to MySQL Database\n";
- my $mysql = Net::MySQL->new(
- hostname => $sqlhost,
- database => $sqldatabase,
- user => $sqluser,
- password => $sqlpassword
- );
- #Register subroutines
- POE::Session->create(
- inline_states => {
- _start => \&bot_start,
- irc_001 => \&on_connect,
- irc_public => \&on_public,
- irc_join => \&on_join,
- irc_nick_sync => \&synced,
- irc_invite => \&invite,
- irc_ctcp_action => \&action,
- irc_nick => \&nick,
- irc_mode => \&mode,
- irc_msg => \&command,
- irc_kick => \&kick,
- irc_topic => \&topic,
- heartbeat => \&heartbeat,
- irc_disconnected => \&shutdown,
- },
- );
- #Connect to Server
- sub bot_start {
- $irc->yield(register => "all");
- $irc->yield(
- connect => {
- Nick => $botnick,
- Username => $botnick,
- Ircname => 'PerlBot written by Kiskae',
- Server => $botserver,
- Port => $botport,
- Password => $botpass,
- }
- );
- print "Connected to $botserver....\n";
- }
- #Join Channels
- sub on_connect {
- foreach my $channel (@channels) {
- $irc->yield(join => $channel);
- print "Joining " . $channel . "\n";
- }
- }
- #Timer
- sub heartbeat {
- $_[KERNEL]->delay(heartbeat => 15);
- }
- #Subroutine Variables
- #Bot should be fully functional from this point forward
- #onKick Messages
- 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.');
- #Subroutines
- sub on_public {
- my ($kernel, $who, $where, $msg) = @_[KERNEL, ARG0, ARG1, ARG2];
- my $nick = (split /!/, $who)[0];
- my $channel = $where->[0];
- my $ts = scalar localtime;
- print " [$ts] <$channel> <$nick> $msg\n";
- if ($msg =~ /^!song$/i) {
- $irc->yield(privmsg => '#cynical.shoutcast' => '!song ' . $nick . '');
- }
- if (($channel eq '#cynical.shoutcast') && ($who =~ /\*\@\*dyneslott\.com/)) {
- $irc->yield(privmsg => '#cynicalbrit' => $msg);
- }
- if ($irc->is_channel_operator($channel, $nick)) {
- if ($msg =~ /^!peak$/i || $msg =~ /^!listeners$/i) {
- $irc->yield(privmsg => '#cynical.shoutcast' => $msg);
- };
- };
- }
- sub on_join {
- my ($kernel, $who, $channel) = @_[KERNEL, ARG0, ARG1];
- my $nick = (split /!/, $who)[0];
- my $ip = (split /@/, $who)[1];
- my $ts = scalar localtime;
- print " [$ts] <$channel> $nick joined\n";
- }
- sub synced {
- my ($kernel, $nick, $channel) = @_[KERNEL, ARG0, ARG1];
- my $ts = scalar localtime;
- my $who = $irc->nick_long_form($nick);
- my $ip = (split /@/, $who)[1];
- my $qname = $irc->is_nick_authed($nick);
- if ($tbnickcheck) {
- if ((!$qname) || ($qname ne 'TotalBiscuit')) {
- if (($nick =~ /^Total/i) || ($nick =~ /Bain/i) || ($nick =~ /Biscuit/i)) {
- $irc->yield(kick => $channel => $nick => 'You are not TotalBiscuit');
- }
- }
- }
- #Adding new user to the database
- if ($qname) {
- $mysql->query('SELECT qname, ip, flags, onjoin FROM cynicalbrit WHERE qname = \'' . $qname . '\'');
- } elsif ($ip) {
- $mysql->query('SELECT qname, ip, flags, onjoin FROM cynicalbrit WHERE ip = \'' . $ip . '\'');
- }
- if (($mysql->has_selected_record) && ($mysql->get_affected_rows_length >= '1')) {
- print "MYSQL has records selected\n";
- } else {
- print "MYSQL couldn't find the records\n";
- if ($qname) {
- if ($ip) {
- if ($mysql->query('INSERT INTO cynicalbrit (qname, ip, lastknownnick) VALUES (\'' . $qname . '\', \'' . $ip . '\', \'' . $nick . '\')')) {
- print "Someone with qname inserted into table\n";
- }
- } else {
- if ($mysql->query('INSERT INTO cynicalbrit (qname, ip, lastknownnick) VALUES (\'' . $qname . '\', \'' . $qname . '.users.quakenet.org\', \'' . $nick . '\')')) {
- print "Someone with qname inserted into table\n";
- }
- }
- } else {
- if ($mysql->query('INSERT INTO cynicalbrit (ip, lastknownnick) VALUES (\'' . $ip . '\', \'' . $nick . '\')')) {
- print "Someone without qname inserted into table\n";
- }
- }
- }
- }
- sub nick {
- my ($kernel, $who, $newnick) = @_[KERNEL, ARG0, ARG1];
- my $nick = (split /!/, $who)[0];
- my $ts = scalar localtime;
- my $channel = $channels[0];
- my $qname = $irc->is_nick_authed($newnick);
- if ($tbnickcheck) {
- if ((!$qname) || ($qname ne 'TotalBiscuit')) {
- if (($newnick =~ /^Total/i) || ($newnick =~ /Bain/i) || ($newnick =~ /Biscuit/i)) {
- $irc->yield(kick => $channel => $nick => 'You are not TotalBiscuit');
- }
- }
- }
- }
- sub invite {
- my ($kernel, $who, $channel) = @_[KERNEL, ARG0, ARG1];
- my $nick = (split /!/, $who)[0];
- my $ts = scalar localtime;
- my $qname = $irc->is_nick_authed($nick);
- # Stafftitle, decrepated
- #if (!$qname) {
- # $irc->yield(notice => $nick => 'You do not have necessary permissions to use invite, if you are staff, please log in or fuck off.');
- #} elsif ($qname) {
- # foreach my $staff (keys %stafftitle) {
- # if ($qname eq $staff) {
- # $irc->yield(join => $channel);
- # $irc->yield(notice => $nick => 'Joining ' . $channel . '.');
- # print "Joining $channel\n";
- # }
- # }
- #}
- }
- sub action {
- my ($kernel, $who, $where, $action) = @_[KERNEL, ARG0, ARG1, ARG2];
- my $nick = (split /!/, $who)[0];
- my $channel = $where->[0];
- my $ts = scalar localtime;
- print " [$ts] <$channel> *$nick $action\n";
- if ($action =~ /^slaps/i) {
- $irc->yield(kick => $channel => $nick => 'Use of the slap command is prohibited.');
- }
- }
- sub topic {
- my ($kernel, $who, $where, $topicscast) = @_[KERNEL, ARG0, ARG1, ARG2];
- my $nick = (split /!/, $who)[0];
- if ($where eq '#cynical.shoutcast') {
- $irc->yield(topic => '#cynicalbrit' => $topicscast);
- }
- }
- sub mode {
- my ($kernel, $who, $channel, $mode, @victim) = @_[KERNEL, ARG0, ARG1, ARG2, ARG3 .. $#_];
- my $nick = (split /!/, $who)[0];
- my $ts = scalar localtime;
- foreach my $victim (@victim) {
- print " [$ts] <$channel> $nick applies $mode $victim\n";
- }
- }
- sub command {
- my ($kernel, $who, $msg) = @_[KERNEL, ARG0, ARG2];
- my $nick = (split /!/, $who)[0];
- my $ts = scalar localtime;
- my $qname = $irc->is_nick_authed($nick);
- print " [$ts] <Private Command> <$nick> $msg\n";
- if (($qname eq 'Raltharg') && ($msg eq '!die')) {
- $irc->yield(notice => $nick => 'Shutting down');
- $irc->yield(quit => 'Shutdown ordered by ' . $nick . '');
- print " [$ts] Shutdown ordered by $nick\n";
- }
- }
- sub kick {
- my ($kernel, $who, $channel, $victim, $why) = @_[KERNEL, ARG0, ARG1, ARG2, ARG3];
- my $nick = (split /!/, $who)[0];
- my $ts = scalar localtime;
- my $qname = $irc->is_nick_authed($nick);
- print " [$ts] <$channel> $nick has kicked $victim ($why)\n";
- # Stafftitle, decrepated
- #if ($qname) {
- #foreach my $staff (keys %stafftitle) {
- #if ($qname eq $staff) {
- # $irc->yield(privmsg => $channel => $kicks[int rand($#kicks+1)]);
- #}
- #}
- #}
- }
- sub shutdown {
- my ($kernel, $qserver) = @_[KERNEL, ARG0];
- my $ts = scalar localtime;
- print " [$ts] Disconnecting from $qserver\n";
- $irc->yield(shutdown => 'Shutdown');
- exit 0;
- }
- #Experimental - Console Input
- #chomp (my $input = <>);
- #if (my ($msg) = $input =~ /^say (.+)/) {
- # $irc->yield(privmsg => $channels[0] => $msg);
- #}
- #Closing
- $poe_kernel->run();
- exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement