Skip to content

Instantly share code, notes, and snippets.

@pydsigner
Created October 14, 2015 22:57
Show Gist options
  • Save pydsigner/c94aea8f8de8c23cdc43 to your computer and use it in GitHub Desktop.
Save pydsigner/c94aea8f8de8c23cdc43 to your computer and use it in GitHub Desktop.
Human/machine readable logging for irssi messages
#!/usr/bin/perl -w
use strict;
use Irssi 20010120.0250 ();
use vars qw($VERSION %IRSSI);
$VERSION = "0.2";
%IRSSI = (
authors => 'Daniel Foerster',
contact => 'pydsigner@gmail.com',
name => 'messagelog',
description => 'Writes to a file when any channel or private message is received. Designed to be read by external scripts.',
license => 'Apache 2.0',
);
# Change the file path below if needed
my $file = "$ENV{HOME}/irssimessages";
sub msg_public{
my($server,$text,$nick,$hostmask,$channel)=@_;
my $prefix = '-';
if (index($text,$server->{nick}) >= 0) {
$prefix = '!';
}
msg_log($prefix, $server->{tag}, $nick, $channel, $text);
}
sub msg_private{
my($server,$text,$nick,$hostmask)=@_;
msg_log('@', $server->{tag}, $nick, $server->{nick}, $text);
}
sub msg_log{
my($prefix, $server, $nick, $channel, $text) = @_;
open(LOG, ">>", $file) or return;
print LOG "$prefix %% $server %% $nick %% $channel %% $text\n";
close(LOG);
}
sub gui_event{
my $line = `tail -1 $file`;
chomp($line);
if ($line eq "~") {
return;
}
open(LOG, ">>", $file) or return;
print LOG "~\n";
close(LOG);
}
Irssi::signal_add_last("message public", "msg_public");
Irssi::signal_add_last("message private", "msg_private");
Irssi::signal_add_last("gui key pressed", "gui_event");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment