-
Notifications
You must be signed in to change notification settings - Fork 25
/
ilbot2.pl
executable file
·149 lines (122 loc) · 3.8 KB
/
ilbot2.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env perl
use lib 'lib';
# TO BE REPLACED BY THE INSTALLER
use warnings;
use strict;
use Bot::BasicBot 0.81;
# this is a cleaner reimplementation of ilbot, with Bot::BasicBot which
# in turn is based POE::* stuff
package Ilbot::Logger;
use Ilbot::Date qw/today/;
use Ilbot::Config;
my $backend = _backend();
my $log_joins = config(backend => 'log_joins');
{
sub dbwrite {
my ($channel, $who, $line) = @_;
return unless $channel =~ /\A#\S+\z/;
$channel =~ s/\A##/#/;
# remove leading BOMs. Some clients seem to send them.
$line =~ s/\A\x{ffef}//;
return if $line =~ /^\[off\]/i;
return unless $log_joins || length($who // '');
$backend->log_line(
channel => $channel,
nick => $who,
line => $line,
);
}
use base 'Bot::BasicBot';
sub said {
my $self = shift;
my $e = shift;
dbwrite($e->{channel}, $e->{who}, $e->{body});
return undef;
}
sub emoted {
my $self = shift;
my $e = shift;
dbwrite($e->{channel}, '* ' . $e->{who}, $e->{body});
return undef;
}
sub chanjoin {
my $self = shift;
my $e = shift;
dbwrite($e->{channel}, undef, $e->{who} . ' joined ' . $e->{channel});
return undef;
}
sub chanquit {
my $self = shift;
my $e = shift;
dbwrite($e->{channel}, undef, $e->{who} . ' left ' . $e->{channel});
return undef;
}
sub chanpart {
my $self = shift;
my $e = shift;
dbwrite($e->{channel}, undef, $e->{who} . ' left ' . $e->{channel});
return undef;
}
sub _channels_for_nick {
my $self = shift;
my $nick = shift;
return grep { $self->{channel_data}{$_}{$nick} } keys( %{ $self->{channel_data} } );
}
sub userquit {
my $self = shift;
my $e = shift;
my $nick = $e->{who};
foreach my $channel ($self->_channels_for_nick($nick)) {
$self->chanpart({ who => $nick, channel => $channel });
}
}
sub topic {
my $self = shift;
my $e = shift;
dbwrite($e->{channel}, "", 'Topic for ' . $e->{channel} . ' is now ' . $e->{topic});
return undef;
}
sub nick_change {
my $self = shift;
my($old, $new) = @_;
foreach my $channel ($self->_channels_for_nick($new)) {
dbwrite($channel, "", $old . ' is now known as ' . $new);
}
return undef;
}
sub kicked {
my $self = shift;
my $e = shift;
dbwrite($e->{channel}, "", $e->{kicked} . ' was kicked by ' . $e->{who} . ': ' . $e->{reason});
return undef;
}
sub help {
my $self = shift;
return "This is a passive irc logging bot. Homepage: http://moritz.faui2k3.org/en/ilbot";
}
}
package main;
# do not use the normal config() mechanism, because there can be multiple
# bot configuration files for multiple servers
my $conf = Config::File::read_config_file(shift @ARGV || "bot.conf");
my $nick = shift @ARGV || $conf->{nick} || "ilbot6";
my $server = $conf->{server} // "irc.freenode.net";
my $port = $conf->{port} // 6667;
my $password = $conf->{password} // undef;
my $ssl = $conf->{ssl} // 0;
my $channels = [ split m/\s+/, $conf->{channel}];
my $bot = Ilbot::Logger->new(
server => $server,
port => $port,
password => $password,
ssl => $ssl,
channels => $channels,
nick => $nick,
alt_nicks => ["irclogbot", "logbot"],
username => "bot",
name => "irc log bot, http://moritz.faui2k3.org/en/ilbot",
charset => "utf-8",
);
say "Launching logger...";
$bot->run();
# vim: ts=4 sw=4 expandtab