From: terminaldweller Date: Mon, 3 Jul 2023 20:20:54 +0000 (+0330) Subject: added an expando, fixed a style issue by removing prantheses X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=3489871af7ad893317c9ba4b27fa457fe8f5fa69;p=irssi-scripts.irssi.org.git added an expando, fixed a style issue by removing prantheses --- diff --git a/scripts/whereami.pl b/scripts/whereami.pl index a6c3ebf..1460a78 100644 --- a/scripts/whereami.pl +++ b/scripts/whereami.pl @@ -16,12 +16,13 @@ our %IRSSI = ( # /set whereami_frequency sets how often we make the IP query in miliseconds # /set whereami_url the url of the service that gives us our IP # please note that the default url is being provided by cloudflare +# the script also provides a expando called whereami Irssi::settings_add_int('misc', 'whereami_frequency', 300000); Irssi::settings_add_str('misc', 'whereami_url', 'https://icanhazip.com'); my $whereami_ip = '0.0.0.0'; my $timeout; -sub whereami() { +sub whereami { my $ua = LWP::UserAgent->new; Irssi::timeout_remove($timeout); my $server_endpoint = Irssi::settings_get_str('whereami_url'); @@ -38,12 +39,16 @@ sub whereami() { $timeout = Irssi::timeout_add_once(Irssi::settings_get_int('whereami_frequency'), 'whereami' , undef); } -sub whereamiStatusbar() { +sub whereamiStatusbar { my ($item, $get_size_only) = @_; $item->default_handler($get_size_only, "{sb ".$whereami_ip."}", undef, 1); } +Irssi::expando_create('whereami', sub { + return $whereami_ip; +}, {}); + Irssi::command_bind('whereami', \&whereami); Irssi::statusbar_item_register('whereami', '{sb $0-}', 'whereamiStatusbar'); $timeout = Irssi::timeout_add(Irssi::settings_get_int('whereami_frequency'), 'whereami' , undef);