- add ringbuffer for each channel
authorAndreas Scherbaum <andreas@scherbaum.biz>
Sun, 8 Sep 2013 15:09:22 +0000 (17:09 +0200)
committerAndreas Scherbaum <andreas@scherbaum.biz>
Sun, 8 Sep 2013 15:09:22 +0000 (17:09 +0200)
docbot.pl

index 8f3f1ec55bc8a8d6013715430ca7019a787d4710..0a8222cf4b13c7f4626e64bc6384352268f7cadf 100755 (executable)
--- a/docbot.pl
+++ b/docbot.pl
@@ -86,6 +86,8 @@ $main::logfile = 'docbot.log';
 # statistics
 %main::statistics = ();
 init_statistics();
+# channel ringbuffer
+%main::channels = ();
 
 
 ######################################################################
@@ -1890,6 +1892,54 @@ sub extract_channel {
 }
 
 
+# store_channel_message_in_ringbuffer()
+#
+# store last x messages for each channel
+#
+# parameter:
+#  - POE kernel
+#  - POE heap
+#  - the full who of the message sender, including the nick name
+#  - the nick name of the message sender
+#  - the message itself
+#  - POE sender
+#  - sender nick name
+#  - the channel name
+#  - session irc handle
+#  - the sessiom handle
+# return:
+#  none
+sub store_channel_message_in_ringbuffer {
+    my $kernel = shift;
+    my $heap = shift;
+    my $who = shift;
+    my $where = shift;
+    my $msg = shift;
+    my $sender = shift;
+    my $nick = shift;
+    my $channel = shift;
+    my $irc = shift;
+    my $session = shift;
+
+    if (lc($channel) eq lc($irc->nick_name())) {
+        return;
+    }
+
+    if (!defined($main::channels{$channel})) {
+        $main::channels{$channel} = [];
+        #print_msg("initialize channel ringbuffer: $channel", DEBUG);
+    }
+
+    push(@{$main::channels{$channel}}, $nick . ' = ' . $msg);
+    #print_msg("have " . scalar(@{$main::channels{$channel}}) . " entries in ringbuffer for channel " . $channel, DEBUG);
+
+    while (scalar(@{$main::channels{$channel}}) > 50) {
+        shift(@{$main::channels{$channel}});
+    }
+    #print_msg("ringbuffer: " . join(" | ", @{$main::channels{$channel}}), DEBUG);
+}
+
+
 # handle_command()
 #
 # wrapper to handle all commands
@@ -4183,6 +4233,13 @@ sub on_message {
     print_msg("on_message($msg), session: $session", DEBUG);
 
 
+    # if this is a message sent to a channel
+    if (lc($channel) ne lc($irc->nick_name())) {
+        # store it in the ringbuffer
+        store_channel_message_in_ringbuffer($kernel, $heap, $who, $where, $msg, $sender, $nick, $channel, $irc, $session);
+    }
+
+
     # recognize valid command (admin, operator and unprivileged)
     my ($command, $string) = find_command($msg, (is_a_channel($channel)) ? $channel : undef);