Blob


1 #!/usr/bin/perl
2 use strict;
3 use warnings;
5 open(my $fh, ">>logbot.log") or die "Unable to write to logbot.log";
6 select((select($fh), $|=1)[0]);
8 package LogBot;
9 use base qw(Bot::BasicBot);
11 sub date {
12 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
13 my $localtime = sprintf("%04d%02d%02d %02d:%02d", $year+1900, $mon+1, $mday, $hour, $min);
14 return $localtime;
15 }
17 sub said {
18 my $self = shift;
19 my $arguments = shift;
20 print $fh date()." <$arguments->{who}> $arguments->{body}\n";
21 return;
22 }
24 sub emoted {
25 my $self = shift;
26 my $arguments = shift;
27 print $fh date()." *$arguments->{who} $arguments->{body}\n";
28 return;
29 }
31 sub noticed {
32 my $self = shift;
33 my $arguments = shift;
34 print $fh date()." [$arguments->{who} notice]: $arguments->{body}\n";
35 return;
36 }
38 sub chanjoin {
39 my $self = shift;
40 my $arguments = shift;
41 print $fh date()." -!- $arguments->{raw_nick} has joined $arguments->{channel}\n";
42 return;
43 }
45 sub chanpart {
46 my $self = shift;
47 my $arguments = shift;
48 print $fh date()." -!- $arguments->{raw_nick} has left $arguments->{channel} $arguments->{body}\n";
49 return;
50 }
52 sub topic {
53 my $self = shift;
54 my $arguments = shift;
55 my $who = $arguments->{who};
56 if (defined($who)) {
57 print $fh date()." -!- $who changed the topic of $arguments->{channel} to: $arguments->{topic}\n";
58 }
59 return;
60 }
62 sub nickchange {
63 my $self = shift;
64 my $oldnick = shift;
65 my $newnick = shift;
66 print $fh "$oldnick is now known as $newnick\n";
67 return;
68 }
70 sub mode_change {
71 my $self = shift;
72 my $arguments = shift;
73 my $chan = $arguments->{channel};
74 my $operands = $arguments->{mode_operands};
75 if (defined($chan) && $chan ne "msg" && scalar(@$operands)) {
76 print $fh date()." -!- mode/$chan $arguments->{who} [$arguments->{mode_changes}] ".join(", ", @$operands)."\n";
77 }
78 return;
79 }
81 sub kicked {
82 my $self = shift;
83 my $arguments = shift;
84 print $fh date()." -!- $arguments->{who} kicks $arguments->{kicked} [$arguments->{reason}]\n";
85 }
87 sub userquit {
88 my $self = shift;
89 my $arguments = shift;
90 print $fh " -!- $arguments->{raw_nick} quits [$arguments->{body}]\n";
91 }
93 package main;
95 my $bot = LogBot->new(
96 server => 'irc.example.com',
97 port => '6667',
98 channels => ['#perl104'],
99 nick => 'nickname',
100 name => 'username',
101 );
103 local $SIG{INT} = sub {
104 close($fh);
105 print "Quitting program...\n";
106 $bot->shutdown("Quitting...");
107 };
109 $bot->run();