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 "SERVER PORT NICK\n";
- chomp($Connect = <STDIN>);
- # Tuesday, June 29th, 2010.
- use POE::Component::IRC;
- use POE;
- BOTVARS: {
- $BotNick = "MyBot"; # Nick
- $BotUser = "."; # Username "indent"
- $BotName = "a Perl bot. Skeleton by Caaz"; # Real Name
- $BotPass = "PASSWORD"; # Nickserv Password
- $BotOwner = "Caaz"; # Owner of the Bot
- $BotPath = "/Users/Caaz/Desktop/Perl/BOT/"; # Path to any files.
- }
- RANDOMJUNKNOONENEEDSTOKNOWABOUT: {
- open DATA, "<".$BotPath.(split / /, $Connect)[0]."-AutoJoin.txt";
- @Channels=<DATA>;
- close DATA;chomp(@Channels);
- $BotChannels = $Channels[0];
- $Connect = $Connect." ".$BotNick;
- $BotNick = (split / /, $Connect)[2];
- }
- 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);
- my $alarm_id = $irc->delay( [ join => $BotChannels ], 2 );
- },
- irc_error => sub {
- my ($kernel, $IRCWhat) = @_[KERNEL, ARG0];
- print $IRCWhat."\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\a> <".(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()."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]; $Where = $_[3]; }
- elsif($Event =~ /NOTICE/) { $Com = "notice ".$_[1]." "; $UserMsg = $_[4]; $Where = $_[1]; }
- elsif($Event =~ /PRIVMSG/) { $Com = "notice ".$_[1]." "; $UserMsg = $_[4]; $Where = $_[1]; }
- elsif($Event =~ /INVITE/) { $Com = "notice ".$_[1]." "; $UserMsg = $_[3]; $Where = $_[1]; if ($UserMsg !~ /Spp/i) { $irc->yield(join => $UserMsg); }} # Joins on invite, if it's not spp. heh.
- elsif($Event =~ /JOIN/) { $Com = "notice ".$_[3]." "; $UserMsg = $_[3]; $Where = $_[1]; }
- elsif($Event =~ /NICK/) { if($_[1] =~ /^$BotOwner$/i) { print "Owner changing...\n"; $BotOwner = Regexit($_[3]) } }
- $UserNick = Regexit($_[1]);
- $UserHost = $_[2];
- $UserMsg = POE::Component::IRC::Common::strip_color($UserMsg);
- $CurSec = SpamProtect();
- if($Event =~ /(CHANMSG|NOTICE|PRIVMSG)/) {
- #####################
- # Owner commands #
- #####################
- if(($UserMsg =~ /^!End$/i) && ($UserNick =~ /^$BotOwner$/i)) {
- $irc->yield(quit => POE::Component::IRC::Common::MAGENTA."~ Goodbye ~");
- }
- elsif($UserMsg =~ /^!Do (.*?) (.*?) (.*)/i) {
- @Temp = ($1,$2,$3);
- if($UserNick =~ /^$BotOwner$/i) {
- $irc->yield($Temp[0] => $Temp[1] => $Temp[2]);
- }
- }
- elsif($UserMsg =~ /^!Nick (.*)/i) {
- $tring = $1;
- if($UserNick =~ /^$BotOwner$/i) {
- $BotNick = $tring;
- $irc->yield(nick => $tring);
- }
- }
- elsif($UserMsg =~ /^!Amsg (.*)/i) {
- $tring = $1;
- if($UserNick =~ /^$BotOwner$/i) {
- $irc->yield(privmsg => $BotChannels => $tring);
- }
- }
- #####################
- #Important Commands #
- #####################
- elsif($UserMsg =~ /^!(Help|Commands)$/i) {
- Command($Com."Skeleton by Caaz.");
- }
- elsif($UserMsg =~ /^!AJ$/i) {
- open DATA, "<".$BotPath.(split / /, $Connect)[0].(split / /, $Connect)[1]."-AutoJoin.txt";
- @Channels=<DATA>;
- close DATA;
- if($Channels[0] !~ /$Where,/i) {
- open DATA, ">>".$BotPath.(split / /, $Connect)[0].(split / /, $Connect)[1]."-AutoJoin.txt"; print DATA "$Where,"; close DATA;
- Command($Com."Channel added to AutoJoin.");
- }
- else {
- Command($Com."Channel already in AutoJoin.");
- }
- }
- elsif($UserMsg =~ /^!Alert$/i) {
- print "\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a ANNOYING BEEPS ACTIVATED.\n";
- }
- #####################
- # Random Commands #
- #####################
- elsif($UserMsg =~ /^!Nothing$/i) {
- Command($Com."\a\a\a\a\a\a\a\a\a");
- }
- #####################
- # END #
- #####################
- }
- }
- sub Regexit {
- ($Reg = $_[0]) =~ s/\\/\\\\/gs;
- $Reg =~ s/(\?|\(|\)|\||\[|\|\{|\}|\.)/\\$1/gs;
- $Reg =~ s/\*/\(\.\*\)/gs;
- return $Reg;
- }
- sub SpamProtect {
- my($Sec, $Min, $Hour, $Day, $mon, $year, $WDay, $YDay) = localtime;
- return (((($YDay * 24) * 60) * 60) + (($Hour * 60) * 60) + ($Min * 60) + $Sec);
- }
- sub Command {
- $PrivmsgA = $_[0];
- @PrivmsgB = split / /, $PrivmsgA;
- $ComA = shift(@PrivmsgB);
- $ComB = shift(@PrivmsgB);
- if($BotNick =~ /Luka/i) { $BotFont = "〜"; $irc->yield($ComA => $ComB => POE::Component::IRC::Common::MAGENTA.(join " ", @PrivmsgB)." 〜"); }
- elsif($BotNick =~ /Pichu/i) { $BotFont = "⚡"; $irc->yield($ComA => $ComB => POE::Component::IRC::Common::ORANGE.(join " ", @PrivmsgB)." ⚡"); }
- else { $irc->yield($ComA => $ComB => POE::Component::IRC::Common::MAGENTA.(join " ", @PrivmsgB)." 〜"); }
- }
- sub GetTime { # This is just for timestamps, just leave it.
- 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