72 |
values (?,?,?) |
values (?,?,?) |
73 |
}); |
}); |
74 |
|
|
75 |
|
=head2 get_from_log |
76 |
|
|
77 |
|
my @messages = get_from_log( |
78 |
|
limit => 42, |
79 |
|
search => '%what to stuff in ilike%', |
80 |
|
); |
81 |
|
|
82 |
|
=cut |
83 |
|
|
84 |
|
sub get_from_log { |
85 |
|
my $args = {@_}; |
86 |
|
|
87 |
|
$args->{limit} ||= 10; |
88 |
|
|
89 |
|
my $sql = qq{ |
90 |
|
select |
91 |
|
time::date as date, |
92 |
|
time::time as time, |
93 |
|
channel, |
94 |
|
nick, |
95 |
|
message |
96 |
|
from log |
97 |
|
}; |
98 |
|
$sql .= " where message ilike ? " if ($args->{search}); |
99 |
|
$sql .= " order by log.time desc"; |
100 |
|
$sql .= " limit " . $args->{limit}; |
101 |
|
|
102 |
|
my $sth = $dbh->prepare( $sql ); |
103 |
|
if ($args->{search}) { |
104 |
|
$sth->execute( $args->{search} ); |
105 |
|
} else { |
106 |
|
$sth->execute(); |
107 |
|
} |
108 |
|
my $last_row = { |
109 |
|
date => '', |
110 |
|
time => '', |
111 |
|
channel => '', |
112 |
|
nick => '', |
113 |
|
}; |
114 |
|
|
115 |
|
my @rows; |
116 |
|
|
117 |
|
while (my $row = $sth->fetchrow_hashref) { |
118 |
|
unshift @rows, $row; |
119 |
|
} |
120 |
|
|
121 |
|
my @msgs; |
122 |
|
|
123 |
|
foreach my $row (@rows) { |
124 |
|
|
125 |
|
$row->{time} =~ s#\.\d+##; |
126 |
|
|
127 |
|
my $t; |
128 |
|
$t = $row->{date} . ' ' if ($last_row->{date} ne $row->{date}); |
129 |
|
$t .= $row->{time}; |
130 |
|
|
131 |
|
my $msg = ''; |
132 |
|
|
133 |
|
$msg .= "($t"; |
134 |
|
$msg .= ' ' . $row->{channel} if ($last_row->{channel} ne $row->{channel}); |
135 |
|
$msg .= ") "; |
136 |
|
|
137 |
|
$msg .= $row->{nick} . ': ' if ($last_row->{nick} ne $row->{nick}); |
138 |
|
|
139 |
|
$msg .= $row->{message}; |
140 |
|
|
141 |
|
push @msgs, $msg; |
142 |
|
|
143 |
|
$last_row = $row; |
144 |
|
} |
145 |
|
|
146 |
|
return @msgs; |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
my $SKIPPING = 0; # if skipping, how many we've done |
my $SKIPPING = 0; # if skipping, how many we've done |
151 |
my $SEND_QUEUE; # cache |
my $SEND_QUEUE; # cache |
163 |
$_[KERNEL]->post($IRC_ALIAS => join => '#logger'); |
$_[KERNEL]->post($IRC_ALIAS => join => '#logger'); |
164 |
$_[KERNEL]->yield("heartbeat"); # start heartbeat |
$_[KERNEL]->yield("heartbeat"); # start heartbeat |
165 |
# $_[KERNEL]->yield("my_add", $_) for keys %FOLLOWS; |
# $_[KERNEL]->yield("my_add", $_) for keys %FOLLOWS; |
166 |
|
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" ); |
167 |
}, |
}, |
168 |
irc_public => sub { |
irc_public => sub { |
169 |
my $kernel = $_[KERNEL]; |
my $kernel = $_[KERNEL]; |
183 |
from_to($msg, 'UTF-8', 'ISO-8859-2'); |
from_to($msg, 'UTF-8', 'ISO-8859-2'); |
184 |
|
|
185 |
my $res = "unknown command '$msg', try /msg $NICK help!"; |
my $res = "unknown command '$msg', try /msg $NICK help!"; |
186 |
|
my @out; |
187 |
|
|
188 |
print "<< $msg\n"; |
print "<< $msg\n"; |
189 |
|
|
190 |
if ($msg =~ m/^help/i) { |
if ($msg =~ m/^help/i) { |
191 |
|
|
192 |
$res = "usage: /msg $NICK stat - shows user statistics | /msg $NICK last - show backtrace of conversations"; |
$res = "usage: /msg $NICK comand | commands: stat - user/message stat | last - show backtrace | grep foobar - find foobar"; |
193 |
|
|
194 |
} elsif ($msg =~ m/^msg\s+(\S+)\s+(.*)$/i) { |
} elsif ($msg =~ m/^msg\s+(\S+)\s+(.*)$/i) { |
195 |
|
|
213 |
$res .= join(" | ", @users); |
$res .= join(" | ", @users); |
214 |
} elsif ($msg =~ m/^last.*?\s*(\d*)/i) { |
} elsif ($msg =~ m/^last.*?\s*(\d*)/i) { |
215 |
|
|
216 |
my $nr = $1 || 10; |
foreach my $res (get_from_log( limit => $1 )) { |
217 |
|
print "last: $res\n"; |
218 |
my $sth = $dbh->prepare(qq{ |
from_to($res, 'ISO-8859-2', 'UTF-8'); |
219 |
select |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
|
time::date as date, |
|
|
time::time as time, |
|
|
channel, |
|
|
nick, |
|
|
message |
|
|
from log order by log.time desc limit $nr |
|
|
}); |
|
|
$sth->execute(); |
|
|
$res = "Last $nr messages: "; |
|
|
my $last_row = { |
|
|
date => '', |
|
|
time => '', |
|
|
channel => '', |
|
|
nick => '', |
|
|
}; |
|
|
|
|
|
my @rows; |
|
|
|
|
|
while (my $row = $sth->fetchrow_hashref) { |
|
|
unshift @rows, $row; |
|
220 |
} |
} |
221 |
|
|
222 |
my @msgs; |
$res = ''; |
|
|
|
|
foreach my $row (@rows) { |
|
|
|
|
|
$row->{time} =~ s#\.\d+##; |
|
|
|
|
|
my $t; |
|
|
$t = $row->{date} . ' ' if ($last_row->{date} ne $row->{date}); |
|
|
$t .= $row->{time}; |
|
|
|
|
|
my $msg = ''; |
|
|
|
|
|
$msg .= "($t"; |
|
|
$msg .= ' ' . $row->{channel} if ($last_row->{channel} ne $row->{channel}); |
|
|
$msg .= ") "; |
|
|
|
|
|
$msg .= $row->{nick} . ': ' if ($last_row->{nick} ne $row->{nick}); |
|
|
|
|
|
$msg .= $row->{message}; |
|
223 |
|
|
224 |
push @msgs, $msg; |
} elsif ($msg =~ m/^(search|grep)\s+(.*)$/i) { |
225 |
|
|
226 |
$last_row = $row; |
my $what = $2; |
|
} |
|
227 |
|
|
228 |
foreach my $res (@msgs) { |
foreach my $res (get_from_log( limit => 20, search => "%${what}%" )) { |
229 |
print "last: $res\n"; |
print "search [$what]: $res\n"; |
230 |
from_to($res, 'ISO-8859-2', 'UTF-8'); |
from_to($res, 'ISO-8859-2', 'UTF-8'); |
231 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
232 |
} |
} |
233 |
|
|
234 |
$res = ''; |
$res = ''; |
235 |
|
|
236 |
} |
} |
237 |
|
|
238 |
if ($res) { |
if ($res) { |
256 |
warn "## indetify $NICK\n"; |
warn "## indetify $NICK\n"; |
257 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" ); |
258 |
}, |
}, |
259 |
irc_433 => sub { |
# irc_433 => sub { |
260 |
print "# irc_433: ",$_[ARG1], "\n"; |
# print "# irc_433: ",$_[ARG1], "\n"; |
261 |
warn "## indetify $NICK\n"; |
# warn "## indetify $NICK\n"; |
262 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" ); |
# $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" ); |
263 |
}, |
# }, |
264 |
irc_372 => sub { |
irc_372 => sub { |
265 |
print "MOTD: ", $_[ARG1], "\n"; |
print "MOTD: ", $_[ARG1], "\n"; |
266 |
}, |
}, |