/[irc-logger]/trunk/bin/irc-logger.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/bin/irc-logger.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 7 by dpavlin, Wed Mar 1 21:29:14 2006 UTC revision 8 by dpavlin, Wed Mar 1 22:42:21 2006 UTC
# Line 22  my $NICK = 'irc-logger-dev'; Line 22  my $NICK = 'irc-logger-dev';
22  my $CONNECT =  my $CONNECT =
23    {Server => 'irc.freenode.net',    {Server => 'irc.freenode.net',
24     Nick => $NICK,     Nick => $NICK,
25     Ircname => 'logger: ask dpavlin@rot13.org'     Ircname => "try /msg $NICK help",
26    };    };
27  my $CHANNEL = '#razmjenavjestina';  my $CHANNEL = '#razmjenavjestina';
28  my $IRC_ALIAS = "log";  my $IRC_ALIAS = "log";
# Line 107  POE::Session->create Line 107  POE::Session->create
107                  my $msg = $_[ARG2];                  my $msg = $_[ARG2];
108                  from_to($msg, 'UTF-8', 'ISO-8859-2');                  from_to($msg, 'UTF-8', 'ISO-8859-2');
109    
110                  my $res = 'unknown command ' . $msg;                  my $res = "unknown command '$msg', try /msg $NICK help!";
111    
112                  print "<< $msg\n";                  print "<< $msg\n";
113    
114                  if ($msg =~ m/^stat.*\s*(\d*)/) {                  if ($msg =~ m/^help/i) {
115    
116                            $res = "usage: /msg $NICK stat - shows user statistics | /msg $NICK last - show backtrace of conversations";
117    
118                    } elsif ($msg =~ m/^stat.*?\s*(\d*)/i) {
119    
120                          my $nr = $1 || 10;                          my $nr = $1 || 10;
121    
# Line 120  POE::Session->create Line 124  POE::Session->create
124                          });                          });
125                          $sth->execute();                          $sth->execute();
126                          $res = "Top $nr users: ";                          $res = "Top $nr users: ";
127                            my @users;
128                          while (my $row = $sth->fetchrow_hashref) {                          while (my $row = $sth->fetchrow_hashref) {
129                                  $res .= $row->{nick} . ': ' . $row->{count} . ", ";                                  push @users,$row->{nick} . ': ' . $row->{count};
130                          }                          }
131                  }                          $res .= join(" | ", @users);
132                    } elsif ($msg =~ m/^last.*?\s*(\d*)/i) {
133    
134                            my $nr = $1 || 10;
135    
136                            my $sth = $dbh->prepare(qq{
137                                    select
138                                            time::date as date,
139                                            time::time as time,
140                                            channel,
141                                            nick,
142                                            message
143                                    from log order by time desc limit $nr
144                            });
145                            $sth->execute();
146                            $res = "Last $nr messages: ";
147                            my $last_row = {
148                                    date => '',
149                                    time => '',
150                                    channel => '',
151                                    nick => '',
152                            };
153    
154                            my @rows;
155    
156                            while (my $row = $sth->fetchrow_hashref) {
157                                    unshift @rows, $row;
158                            }
159    
160                            my @msgs;
161    
162                            foreach my $row (@rows) {
163    
164                  $res =~ s/,\s*$//;                                  $row->{time} =~ s#\.\d+##;
                 print ">> [$nick] $res\n";  
165    
166                  from_to($res, 'ISO-8859-2', 'UTF-8');                                  my $t;
167                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );                                  $t = $row->{date} . ' ' if ($last_row->{date} ne $row->{date});
168                                    $t .= $row->{time};
169    
170                                    my $msg = '';
171    
172                                    $msg .= "($t";
173                                    $msg .= ' ' . $row->{channel} if ($last_row->{channel} ne $row->{channel});
174                                    $msg .= ") ";
175    
176                                    $msg .= $row->{nick} . ': '  if ($last_row->{nick} ne $row->{nick});
177    
178                                    $msg .= $row->{message};
179    
180                                    push @msgs, $msg;
181    
182                                    $last_row = $row;
183                            }
184    
185                            foreach my $res (@msgs) {
186                                    print "last: $res\n";
187                                    from_to($res, 'ISO-8859-2', 'UTF-8');
188                                    $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );
189                            }
190    
191                            $res = '';
192                    }
193    
194                    if ($res) {
195                            print ">> [$nick] $res\n";
196                            from_to($res, 'ISO-8859-2', 'UTF-8');
197                            $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );
198                    }
199    
200          },          },
201          irc_505 => sub {          irc_505 => sub {
202          print "# irc_505: ",$_[ARG1], "\n";          print "# irc_505: ",$_[ARG1], "\n";
203                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "register $NICK" );                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "register $NICK" );
204                  warn "## register $NICK\n";                  warn "## register $NICK\n";
205            },
206            irc_registered => sub {
207                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" );                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" );
208                  warn "## indetify $NICK\n";                  warn "## indetify $NICK\n";
209          },          },

Legend:
Removed from v.7  
changed lines
  Added in v.8

  ViewVC Help
Powered by ViewVC 1.1.26