summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Scherbaum2013-09-08 15:09:22 +0000
committerAndreas Scherbaum2013-09-08 15:09:22 +0000
commit5ee65c3f98e741e64ce2599237c597eb54d3c047 (patch)
treec252f5be6d6b3dceed02fbb1dd034ca607786bb9
parent7f69ac8492c003702804022c7999e5020e41d00e (diff)
- add ringbuffer for each channel
-rwxr-xr-xdocbot.pl57
1 files changed, 57 insertions, 0 deletions
diff --git a/docbot.pl b/docbot.pl
index 8f3f1ec..0a8222c 100755
--- 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);