Académique Documents
Professionnel Documents
Culture Documents
/usr/bin/perl
# Created by Franc. This is an IRC Bot, it will message back to you as long as
you're
# privmsg it. Right now you can only do 'weather oneWord oneWord', if the city has
more
# than one word, it won't work. So yea, this is version 1 of the Bot.
# JEFF Wanted me to make it D:
# 'perl irc -h' for help menu, 'sudo chmod a+x irc' to make it executable using
'./'
system "clear";
print "Internet Relay Chat Bot\n\n";
# The modules you'll need to make this bot work. Download via CPAN.
use strict;
use Net::IRC;
use Term::ANSIColor;
use Weather::Underground;
use HTML::Parser;
use HTML::Tagset;
use LWP::UserAgent;
$SIG{INT} = \&signalint;
if($h) {
print color 'bold blue';
print "Usage: perl irc <BotName> <IRCServer> <IRCChannel>\n";
print "Example: perl irc bot102928 irc.freenode.net \\#ubuntu\n";
print color 'reset';
exit;
}
my $conn = $irc->newconn
(
Nick => $ircb,
Ircname => $ircb,
Server => $ircs
);
sub signalint {
print color 'bold red';
print STDERR "\nKilled the bot.\n";
print color 'reset';
print LOGFILE "\n\n";
system("reset");
exit;
}
sub on_connect {
my $self = shift;
$self->join($ircc);
sub on_msg {
if($event->{args}[0] =~ /\bcommands\b/i) {
}elsif($event->{args}[0] =~ /\bversion\b/i) {
}elsif($event->{args}[0] =~ /\binfo\b/i) {
}elsif($event->{args}[0] =~ /^(-)?\d+\.\d+$/) {
}elsif($event->{args}[0] =~ /^(-)?\d+$/) {
}elsif($event->{args}[0] =~ /\b(date|time)\b/i) {
print "Date.\n";
print LOGFILE "Checked date\n";
$conn->privmsg($event->{nick}, "The date is $date");
}elsif($event->{args}[0] =~ /^weather(\s+)(\w+)(\s+)(\w+)/i) {
my $weather = Weather::Underground->new
(
place => "$2, $4",
debug => 0
);
my $ref = $weather->get_weather();
my $loc = "$ref->[0]->{place}";
my $upd = "$ref->[0]->{updated}";
my $csc = "$ref->[0]->{conditions}";
my $h = "$ref->[0]->{humidity}\%";
my $temp = "$ref->[0]->{temperature_fahrenheit}F $ref->[0]-
>{temperature_celsius}C";
my $wind = "$ref->[0]->{wind_direction} $ref->[0]-
>{wind_kilometersperhour}KPH $ref->[0]->{wind_milesperhour}MPH\)";
$conn->privmsg($event->{nick}, "-----");
$conn->privmsg($event->{nick}, "Location: $loc");
$conn->privmsg($event->{nick}, "\[Sky: $csc\] \[Humidity: $h\]
\[Temperature: $temp\] \[Wind: $wind\]");
$conn->privmsg($event->{nick}, "Last updated: $upd");
$conn->privmsg($event->{nick}, "-----");
}elsif($event->{args}[0] =~ /^weather(\s+)help/) {
}elsif($event->{args}[0] =~ /\bhi\b/) {
}else{
print "Typed something that does't exist.\n";
print LOGFILE "Typed something that doesn't exist\n";
$conn->privmsg($event->{nick}, "Command does\'t exist. type
'commands'");
}
}
sub on_join {
my ($self, $event) = @_;
my ($channel) = ($event->to)[0];
my $nick = $event->{nick};
$self->privmsg($ircc, "Hello $nick, type '/msg $ircb commands' for help.");
}
$conn->add_handler('join', \&on_join);
$conn->add_global_handler('376', \&on_connect);
$conn->add_handler('msg', \&on_msg);
$irc->start();