A project for HPC Fundamentals 2 by Jacob Pettie during the Spring 2013 Semester.
The purpose of this project is to create an dynamic bot system that can be updated easily in terms of any feature needed and quickly, for example: pom:, weather:, location:
In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:
The end result of this project is a working and adaptable IRC Perl Bot that can be easily updated to add any functionality quickly using its dynamic If/RegEx combination looping.
Steps to creating a Dynamic Perl IRC Bot:
#!/usr/bin/perl use strict; use vars qw($VERSION %IRSSI); use LWP::Simple; use Irssi qw(command_bind signal_add); use IO::File; $VERSION = '0.1'; %IRSSI = ( authors => 'Jacob Pettie', contact => 'jpettie@corning-cc.edu', name => 'IRC Bot', description => 'Many potentially good things.', license => 'IDK', ); my $lstate = '0'; my $sleep = '0'; my $pom; sub own_question { my ($server, $msg, $target) = @_; question($server, $msg, "", $target); } sub public_question { my ($server, $msg, $nick, $address, $target) = @_; question($server, $msg, $nick, $target); } sub question($server, $msg, $nick, $target) { my ($server, $msg, $nick, $target) = @_; $_ = $msg; #if (/^whois:$/i) { #my $uInfo; #$uInfo = `$server->command('whois '.$msg)`; #} if (/^sleep:$/i) { if ($nick eq 'Ocean'){ $sleep = '1'; $server->command('msg '.$target.' '.'casts Sleep on self.'); } } if (/^wake:$/i) { if ($nick eq 'Ocean'){ $sleep = '0'; $server->command('msg '.$target.' '.'Oh, I see how it is, so now you want me to be around but not all the time....'); } } if ($sleep eq '0') { if (/^roll:$/i) { my $ia = int(rand(101)); $server->command('msg '.$target.' '.$nick.' rolled: '.$ia); return 0; } if(m/\.com/i or m/\.net/i or m/\.org/i){ my $file = Irssi::get_irssi_dir."/urls.txt"; open (FILE, '>>', $file) or $server->command('msg '.$target.' '.'Could not open file.'); print FILE time."\t".$nick."\t".$msg; print FILE "\n"; close (FILE); } if(/^lc:/i) { if ($nick eq 'Ocean' or $nick eq 'wedge'){ $msg = lc($msg); $msg =~ s/lc://; $pom = `$msg`; $server->command('msg '.$target.' '.$pom); } } if(/^define:/i) { $msg = lc($msg); #$msg =~ s/\s*//g; $msg =~ s/define://; my $defined; if ($msg eq 'milf'){ $defined = "Tom's Mom"; $server->command('msg '.$target.' '.$msg.' is '.$defined); }else{ my $define = get('http://www.dictionary.reference.com/browse/'.$msg); if ($define =~ /<div class="dndata">(.[^<]*)</){ $defined = $1; $server->command('msg '.$target.' '.$msg.' is '.$defined); }else{ if ($target eq '#offbyone'){ $define = get('http://www.urbandictionary.com/define.php?term='.$msg); if ($define =~ /<div class="definition">(.[^<]*)</){ $defined = $1; $server->command('msg '.$target.' '.$msg.' is '.$defined); }else{ $server->command('msg '.$target.' '.$msg.' was not defined.'); #$server->command('msg '.$target.' '.$target); } }else{ $server->command('msg '.$target.' '.$msg.' was not defined.'); } } } } if(/^alert:/i) { my $alerted; my $alert = get('http://www.corning-cc.edu/shared/shared_rootsite/snowday.php'); if ($alert =~ /<p style="color: red;">(.[^<]*)</) { $alerted = $1; $alerted =~ s/[\000-\037]*//; $server->command('msg '.$target.' '.$alerted); } } if(/^weather:/i) { $msg = lc($msg); $msg =~ s/\s*//g; $msg =~ s/weather://; my $weather; my $wthr = get('http://www.weather.com/weather/right-now/'.$msg); if ($wthr =~ /<p class="wx-text">(.[^<]*)</){ $weather = $1; $weather =~ s/[\000-\037]*//; $server->command('msg '.$target.' '.$weather); }else{ $server->command('msg '.$target.' There was a problem finding the weather for '.$msg.'.'); } } if(/^location:/i) { $msg = lc($msg); $msg =~ s/\s*//g; $msg =~ s/location://; my $location; my $loc = get('http://www.findazip.com/search-by-code.html?q='.$msg); if ($loc =~ /$msg<\/b> - (.[^<]*)</){ $location = $1; $server->command('msg '.$target.' '.$location); }else{ $server->command('msg '.$target.' There was a problem finding the location of '.$msg.'.'); } } if(/^pom:/i) { $pom = `pom`; $server->command('msg '.$target.' '.$pom); } if(/^bear:/i) { $server->command('msg '.$target.' '.'("")(-_-)("")'); } if(/^light:$/i) { if ($nick eq 'Ocean' or $nick eq 'squirrel' or $nick eq 'wedge' or $nick eq 'asowers' or $nick eq 'polloloco'){ if ($lstate eq '1'){ $lstate = '0'; $server->command('msg '.$target.' '.$nick.' turned the light off.'); }else{ $lstate = '1'; $server->command('msg '.$target.' '.$nick.' turned the light on.'); } my $res = get('http://admin:debian@10.80.1.245/Set.cmd?CMD=SetPower+P62='.$lstate); } } if (/^rick:$/i) { my $ia = int(rand(100)); $ia = 'http://www.youtube.com/watch?v=oHg5SJYRHA0'; $server->command('msg '.$target.' '.$nick.' rolled: '.$ia); return 0; } if (/^leek:$/i) { my $ia = 'http://www.youtube.com/watch?v=qs8pnY3BKn8'; $server->command('msg '.$target.' '.$nick.' leeked: '.$ia); return 0; } if (/^nyan:$/i) { my $ia = 'http://www.nyan.cat'; $server->command('msg '.$target.' '.$nick.' throws cat: '.$ia); return 0; } if (/^flip:$/i) { my $ia = '_|____|_\(`.´)/_|____|_'; $server->command('msg '.$target.' '.$ia); return 0; } } #if (!/^roll:/i) { return 0; } } signal_add("message public", "public_question"); signal_add("message own_public", "own_question");