Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- print "POE IRC Bot. Skeleton by Caaz.\n";
- print "You can add an optional ! NICK.\n";
- print "SERVER ! PORT\n";
- chomp($Connect = <STDIN>);
- use POE::Component::IRC;
- use POE;
- # Fill these out.
- $BotNick = "Luka"; # Nick
- $BotUser = "."; # Username "indent"
- $BotName = "a Perl bot. Originally by Caaz"; # Real Name
- $BotPass = ""; # Nickserv Password
- $BotOwner = "Caaz"; # Owner of the Bot
- $BotPath = ""; # Path to any files.
- $BotChannels = "#Powerplant"; # Channels it joins on connect.
- $Connect = $Connect." ! ".$BotNick;
- $BotNick = (split / ! /, $Connect)[2];
- # Alright now, here's where we connect and get some events.
- my ($irc) = POE::Component::IRC->spawn();
- POE::Session->create(inline_states => {
- _start => sub {
- $irc->yield(register => "all");
- $irc->yield( connect => {
- Nick => (split / ! /, $Connect)[2],
- Username => $BotUser,
- Ircname => $BotName,
- Server => (split / ! /, $Connect)[0],
- Port => (split / ! /, $Connect)[1],
- });
- },
- irc_001 => sub {
- $irc->yield(mode => $BotNick." +B");
- $irc->yield(privmsg => "Nickserv" => "id ".$BotPass);
- $irc->yield(join => $BotChannels);
- },
- irc_error => sub {
- my ($kernel, $IRCWhat) = @_[KERNEL, ARG0];
- print $IRCError."\n";
- },
- irc_ctcp_action => sub {
- my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
- $IRCWhere = $where->[0];
- print GetTime()."$IRCWhere > * ".(split /!/, $IRCWho)[0]." $IRCWhat\n";
- Bot("ACTION",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
- },
- irc_join => sub {
- my ($kernel, $IRCWho, $IRCWhere) = @_[KERNEL, ARG0, ARG1];
- print GetTime()."Join * ".(split /!/, $IRCWho)[0]." joins $IRCWhere\n";
- Bot("JOIN",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere);
- },
- irc_invite => sub {
- my ($kernel, $IRCWho, $IRCWhere) = @_[KERNEL, ARG0, ARG1];
- print GetTime()."Invi * ".(split /!/, $IRCWho)[0]." invites you to $IRCWhere\n";
- Bot("INVITE", (split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere);
- },
- irc_kick => sub {
- my ($kernel, $IRCWho, $IRCWhere, $IRCWhoElse, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2, ARG3];
- print GetTime()."Kick * ".(split /!/, $IRCWho)[0]." kicks $IRCWhoElse out of $IRCWhere ($IRCWhat)\n";
- Bot("KICK",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhoElse,$IRCWhat);
- },
- irc_msg => sub {
- my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
- $IRCWhere = $where->[0];
- print GetTime()."Priv > <".(split /!/, $IRCWho)[0]."> $IRCWhat\n";
- Bot("PRIVMSG",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
- },
- irc_nick => sub {
- my ($kernel, $IRCWho, $IRCWhoElse) = @_[KERNEL, ARG0, ARG1];
- print GetTime()."$IRCWhere > Nick * ".(split /!/, $IRCWho)[0]." changes nick to $IRCWhoElse\n";
- Bot("NICK", (split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhoElse);
- },
- irc_notice => sub {
- my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
- $IRCWhere = $where->[0];
- print GetTime()."Noti > <".(split /!/, $IRCWho)[0]."> $IRCWhat\n";
- Bot("NOTICE",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
- },
- irc_part => sub {
- my ($kernel, $IRCWho, $IRCWhere, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
- print GetTime()."Part > *".(split /!/, $IRCWho)[0]." left channel $IRCWhere \(".$IRCWhat."\)\n";
- Bot("PART",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
- },
- irc_public => sub {
- my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
- $IRCWhere = $where->[0];
- print GetTime()."$IRCWhere > <".(split /!/, $IRCWho)[0]."> $IRCWhat\n";
- Bot("CHANMSG",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
- },
- irc_disconnected => sub { print "Disconnected.\n"; exit 1; }, # Ends on disconnect.
- },);
- sub Bot {
- $Event = $_[0];
- if($Event =~ /CHANMSG/) { $Com = "privmsg ".$_[3]; $UserMsg = $_[4]; }
- elsif($Event =~ /NOTICE/) { $Com = "notice ".$_[1]; $UserMsg = $_[4]; }
- elsif($Event =~ /PRIVMSG/) { $Com = "notice ".$_[1]; $UserMsg = $_[4]; }
- elsif($Event =~ /INVITE/) { $Com = "notice ".$_[1]; $UserMsg = $_[3]; }
- elsif($Event =~ /JOIN/) { $Com = "notice ".$_[3]; $UserMsg = $_[3]; }
- elsif($Event =~ /NICK/) { if($_[1] =~ /^$BotOwner$/i) { print "Owner changing...\n"; $BotOwner = $_[3]; } }
- $UserNick = $_[1];
- $UserHost = $_[2];
- $UserMsg = POE::Component::IRC::Common::strip_color($UserMsg);
- $CurSec = SpamProtect();
- # Now this, is where the magic happens `O'
- if($Event =~ /(CHANMSG|NOTICE|PRIVMSG)/) {
- if(($UserMsg =~ /^~End$/i) && ($UserNick =~ /^$BotOwner$/i)) {
- $irc->yield(quit => POE::Component::IRC::Common::MAGENTA."〜 Goodbye 〜");
- }
- }
- }
- sub SpamProtect {
- my($Sec, $Min, $Hour, $Day, $mon, $year, $WDay, $YDay) = localtime;
- return (((($YDay * 24) * 60) * 60) + (($Hour * 60) * 60) + ($Min * 60) + $Sec);
- }
- sub Privmsg {
- $PrivmsgA = $_[0];
- @PrivmsgB = split / /, $PrivmsgA;
- $ComA = shift(@PrivmsgB);
- $ComB = shift(@PrivmsgB);
- $irc->yield($ComA => $ComB => POE::Component::IRC::Common::MAGENTA.(join " ", @PrivmsgB)." 〜");
- }
- sub GetTime {
- my($Sec, $Min, $Hour, $Day, $Mon, $Year, $WDay, $YDay) = localtime;
- my $APM = "AM";
- if($Hour > 12) { $Hour -= 12; $APM = "PM"; }
- if($Hour < 10) { $Hour = "0".$Hour; }
- if($Min < 10) { $Min = "0".$Min; }
- if($Sec < 10) { $Sec = "0".$Sec; }
- return "[ $Hour:$Min:$Sec $APM ] ";
- }
- # Caaz was here.
- $poe_kernel->run();
- exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement