From a76c61351eabb72f5dbb5f75394850e06f558487 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sat, 22 Jun 2019 22:49:36 +1200 Subject: Add colour to logs, add topic, ping log messages For now, this will pollute piped logs with ANSI escape sequences, but this can be filtered when proper logging is implemented. --- Plugin/Log.pm | 49 ++++++++++++++++++++++++++++++++++++++++++------- idalius.pl | 26 +++++++++++++++++++++++--- 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/Plugin/Log.pm b/Plugin/Log.pm index 8f9982f..1d69e51 100644 --- a/Plugin/Log.pm +++ b/Plugin/Log.pm @@ -3,9 +3,23 @@ package Plugin::Log; use strict; use warnings; +use Term::ANSIColor; + my $config; my $root_config; +# FIXME turn theme into config parms? +my %t = ( + bracket => color("white"), + nick => color("cyan"), + info => color("yellow"), + kick => color("red"), + channel => color("blue"), + message => color("reset"), + misc => color("bright_black"), + reset => color("reset") +); + sub configure { my $self = shift; shift; # cmdref @@ -16,45 +30,66 @@ sub configure { return $self; } +# FIXME Not triggered yet +sub on_001 { + my ($self, $logger, $server, $message, $irc) = @_; + $logger->("$t{info}Connected to ${host}$server$t{info} --- \"$t{message}$message$t{info}\"$t{reset}"); +} + sub on_message { my ($self, $logger, $who, $where, $raw_what, $what, $irc) = @_; - $logger->("[$where->[0]] $who: $raw_what"); + $logger->("$t{bracket}\[$t{channel}$where->[0]$t{bracket}\] $t{nick}$who: $t{message}$what$t{reset}"); return; } sub on_action { my ($self, $logger, $who, $where, $raw_what, $what, $irc) = @_; - $logger->("[$where->[0]] * $who $raw_what"); + $logger->("$t{bracket}\[$t{channel}$where->[0]$t{bracket}\] $t{message}* $t{nick}$who $t{message}$raw_what$t{reset}"); return; } sub on_part { my ($self, $logger, $who, $where, $why, $irc) = @_; - $logger->("[$where] --- $who left ($why)"); + $logger->("$t{bracket}\[$t{channel}$where$t{bracket}\]$t{info} --- $t{nick}$who $t{info}left ($why)$t{reset}"); return; } sub on_join { my ($self, $logger, $who, $where, $irc) = @_; - $logger->("[$where] --- $who joined"); + $logger->("$t{bracket}\[$t{channel}$where$t{bracket}\]$t{info} --- $t{nick}$who $t{info}joined$t{reset}"); return; } sub on_kick { my ($self, $logger, $kicker, $where, $kickee, $why, $irc) = @_; - $logger->("[$where] !!! $kicker kicked $kickee ($why)"); + $logger->("$t{bracket}\[$t{channel}$where$t{bracket}\]$t{kick} !!! $t{nick}$kicker $t{kick}kicked $t{nick}$kickee $t{kick}($why)$t{reset}"); return; } sub on_nick { my ($self, $logger, $who, $new_nick, $irc) = @_; - $logger->("$who changed nick to $new_nick"); + $logger->("$t{nick}$who $t{info}changed nick to $t{nick}$new_nick$t{reset}"); return; } sub on_invite { my ($self, $logger, $who, $where, $irc) = @_; - $logger->("$who invited me to join $where"); + $logger->("$t{nick}$who $t{info}invited me to join $t{channel}$where$t{reset}"); return; } + +sub on_topic { + my ($self, $logger, $who, $where, $topic, $irc) = @_; + if ($topic) { + $logger->("$t{bracket}\[$t{channel}$where$t{bracket}\]$t{info} --- $t{nick}$who $t{info}set topic to $t{message}$topic$t{reset}"); + } else { + $logger->("$t{bracket}\[$t{channel}$where$t{bracket}\]$t{info} --- $t{nick}$who $t{info}unset the topic$t{reset}"); + } + return; +} + +sub on_ping { + my ($self, $logger, $server, $irc) = @_; + $logger->("$t{misc}IRC ping from $server$t{reset}"); +} 1; diff --git a/idalius.pl b/idalius.pl index ab6a364..fcddc13 100755 --- a/idalius.pl +++ b/idalius.pl @@ -59,6 +59,8 @@ POE::Session->create( irc_kick irc_ctcp_action irc_public + irc_topic + irc_ping irc_msg irc_join irc_part @@ -203,6 +205,10 @@ sub strike_add { sub should_ignore { my ($who) = @_; + + # Short circuit on non-user messages (undef is used for server msgs) + return unless $who; + for my $mask (@{$config->{_}->{ignore}}) { my $expr = $mask; $expr =~ s/([^[:alnum:]\*])/$1/g; @@ -257,7 +263,6 @@ sub handle_common { # a given message type, passing them only the given arguments sub trigger_modules { my ($message_type, $who, $where, $no_reenter, @arguments) = @_; - my $nick = (split /!/, $who)[0]; for my $handler (handlers_for($message_type, $who, $no_reenter)) { my @base_args = (\&log_info); @@ -277,7 +282,6 @@ sub trigger_modules { sub handlers_for { my ($message_type, $who, $no_reenter) = @_; my @handlers = (); - my $nick = (split /!/, $who)[0]; $message_type = "on_$message_type"; for my $module (@{$config->{_}->{active_plugins}}) { @@ -369,6 +373,7 @@ sub irc_nick { sub irc_invite { my ($who, $where) = @_[ARG0 .. ARG1]; my @empty = (); + trigger_modules("invite", $who, undef, \@empty, ($who, $where)); return; } @@ -385,10 +390,25 @@ sub irc_invite { # irc_notice # irc_quit # irc_socketerr -# irc_topic # irc_whois # irc_whowas +sub irc_topic { + my ($who, $where, $topic) = @_[ARG0 .. ARG2]; + my @empty = (); + + trigger_modules("topic", $who, undef, \@empty, ($who, $where, $topic)); + return; +} + +sub irc_ping { + my $server = $_[ARG0]; + my @empty = (); + + trigger_modules("ping", undef, undef, \@empty, ($server)); + return; +} + sub irc_msg { my ($who, $to, $what, $ided) = @_[ARG0 .. ARG3]; my $nick = (split /!/, $who)[0]; -- cgit v1.1