rendered paste body#!/usr/bin/perl -w
use IO::Socket;
$nick = "dictionary";
$backupnick = "dic`";
$chan = "#potat0wned";
$masterhost = "omg\@.*";
$serv = "irc.swiftirc.net";
$port = "6667";
$dict = "dict.txt";
$IRC = IO::Socket::INET->new(
PeerAddr => "$serv",
PeerPort => $port
) or die "Failed.";
while(<$IRC>) {
print;
#Checks for pings.
if(/PING\s:(.*)/){
print $IRC "PONG :$1\n";
print "<- PONG :$1\n";
}
#Checks to see if the default nick is in use, if it is we change to the backup nick.
if(/Nickname is already in use./){
print $IRC "NICK :$backupnick\n";
print "Changing to backup nickname!\n";
}
if(/Register first/){
print $IRC "NICK $nick\n";
print "<- NICK $nick\n";
print $IRC "USER perlbot 127.0.0.1 * : DicTionaryBot\n";
print "<- USER perlbot 127.0.0.1 * : DicTionaryBot\n";
print $IRC "JOIN $chan\n";
}
#Listens for when to send info to ident server
if(/NOTICE AUTH/){
print $IRC "NICK $nick\n";
print "<- NICK $nick\n";
print $IRC "USER perlbot 127.0.0.1 * : DicTionaryBot\n";
print "<- USER perlbot 127.0.0.1 * : DicTionaryBot\n";
print $IRC "JOIN $chan\n";
}
eval{
if(/PRIVMSG (.*) :$nick, (.+)\b/){
my $chn = $1;
my $meaning;
my $def = $2;
open DICT, $dict;
chomp(my @lines = <DICT>);
close DICT;
for $line (@lines){
if($line =~ /$def:(.+)/){
$meaning = $1;
print $IRC "PRIVMSG $chn : --> $meaning\n";
}
}
}
if(/PRIVMSG (.*) :!sayall\b/){
open DICT, $dict;
print $IRC "PRIVMSG $1 : --> $_\n" while(<DICT>);
close DICT;
}
if(/PRIVMSG (.*) :$nick, add (.+):(.+)/){
open DICT, ">>" . $dict;
print DICT "$2:$3";
close DICT;
print $IRC "PRIVMSG $1 : --> $2 was added to the dictionary!\n";
}
};
if(/$masterhost PRIVMSG (.*) :!clearall/){
open DICT, ">" . $dict;
print DICT "";
close DICT;
print $IRC "PRIVMSG $1 : --> $dict was cleared!\n";
}
if(/KICK (.*) $nick/){
print $IRC "JOIN $1\n";
}
}