| # Irssi TagInfo Join Plugin
|
| #
|
| # Installation:
|
| # - Save as ~/.irssi/scripts/taginfo_join.pl
|
| # - In Irssi: /script load taginfo_join.pl
|
| #
|
| # Configuration:
|
| # - /set taginfo_enabled ON|OFF (Default: ON)
|
| #
|
| # Requirements:
|
| # - An external command (e.g., 'taginfo') that accepts an IP address or
|
| # hostname as an argument and prints location information to standard
|
| # output.
|
|
|
| use strict;
|
| use warnings;
|
|
|
| use Irssi;
|
| use Irssi::Irc;
|
|
|
| # --- Plugin Information ---
|
| our $VERSION = '1.0';
|
| our %IRSSI = (
|
| authors => 'Me',
|
| contact => '',
|
| name => 'taginfo_join',
|
| description => 'Adds location info from external taginfo command to join messages based on WHOIS IP.',
|
| license => 'GPLv3',
|
| url => '',
|
| );
|
|
|
|
|
| Irssi::settings_add_bool('misc', 'taginfo_enabled', 1);
|
|
|
|
|
| # Print the final join message with location
|
| sub print_join_message {
|
| my ($info, $location) = @_;
|
| my $server = Irssi::server_find_tag($info->{server_tag});
|
| my $window = $server ? $server->channel_find($info->{channel}) : undef;
|
| if (defined($window)) {
|
| $window->printformat(MSGLEVEL_JOINS, 'join_location', $info->{nick}, $info->{userhost}, $location, $info->{channel});
|
| }
|
| }
|
|
|
|
|
| # Called when a user joins a channel
|
| sub sig_message_join {
|
| my ($server, $channel, $nick, $address) = @_;
|
| return unless Irssi::settings_get_bool('taginfo_enabled');
|
| return if $nick eq $server->{nick}; # Don't process joins for self
|
|
|
| my $lc_nick = lc $nick;
|
| my $server_tag = $server->{tag};
|
|
|
|
|
| if ($address =~ /^.+?@([A-Za-z0-9\.:\-]+)$/) {
|
| my $hostname = "$1";
|
| my $info = {
|
| nick => $nick,
|
| channel => $channel,
|
| userhost => $address, # Full user@host
|
| server_tag => $server_tag,
|
| time => time(),
|
| };
|
|
|
| my $location = `taginfo $hostname`;
|
| if ($location ne "") {
|
| print_join_message($info, $location);
|
| Irssi::signal_stop();
|
| }
|
| }
|
| }
|
|
|
|
|
| # Define the custom format for the join message with location
|
| # $0 = nick, $1 = user@host, $2 = location, $3 = channel
|
| Irssi::theme_register([
|
| 'join_location',
|
| # This example mimics the default join but adds the location in parentheses.
|
| '{channick_hilight $0} {chanhost_hilight $1} ({channick_hilight $2}) has joined {channel $3}'
|
| ]);
|
|
|
|
|
| # Register signals
|
| Irssi::signal_add_first('message join', 'sig_message_join');
|
|
|
| # Initial messages
|
| Irssi::print("TagInfoJoin Plugin v$VERSION Loaded.", MSGLEVEL_CLIENTNOTICE);
|
| Irssi::print(" - Use: /set taginfo_enabled ON|OFF", MSGLEVEL_CLIENTNOTICE);
|