diff options
| author | Alexander Færøy | 2014-05-31 13:10:46 +0200 | 
|---|---|---|
| committer | Alexander Færøy | 2014-05-31 13:10:46 +0200 | 
| commit | 2d0759e6ca5767b48bcc85bf38c2c43d5f0b63b1 (patch) | |
| tree | 1c5e6d817c88e67b46e216a50e0aef5428bf63df /scripts/timezones.pl | |
| parent | 2d080422d79d1fd49d6c5528593ccaaff9bfc583 (diff) | |
| download | scripts.irssi.org-2d0759e6ca5767b48bcc85bf38c2c43d5f0b63b1.tar.bz2 | |
Import scripts from scripts.irssi.org
Diffstat (limited to 'scripts/timezones.pl')
| -rw-r--r-- | scripts/timezones.pl | 61 | 
1 files changed, 61 insertions, 0 deletions
| diff --git a/scripts/timezones.pl b/scripts/timezones.pl new file mode 100644 index 0000000..f05bfa0 --- /dev/null +++ b/scripts/timezones.pl @@ -0,0 +1,61 @@ +# +# Add the statusbar item to its own statusbar with +# /statusbar sb_timezones enable +# /statusbar sb_timezones add -alignment left barstart +# /statusbar sb_timezones add -after barstart timezones +# /statusbar sb_timezones add -alignment right barend +# +# or add it to an existing one with +# /statusbar window add timezones (window is an exaple, see /statusbar and /help statusbar for comprehensive help) + +$VERSION = "0.1"; +%IRSSI = ( +    authors     => "Jari Matilainen", +    contact     => "irc: vague`\@freenode", +    name        => "timezones", +    description => "timezones displayer", +    license     => "Public Domain", +    url         => "http://vague.se" +); + +use strict; +use Irssi::TextUI; +use DateTime; + +my $refresh_tag; + +sub timezones { +  my ($item,$get_size_only) = @_; +  my ($datetime) = Irssi::settings_get_str("timezones_clock_format"); +  my ($div) = Irssi::settings_get_str("timezones_divider"); +  my (@timezones) = split ' ', Irssi::settings_get_str("timezones"); + +  my $result = ""; + +  foreach(@timezones) { +    if(length($result)) { $result .= $div; } +    my ($nick, $timezone) = split /:/, $_; +    my $now = DateTime->now(time_zone => $timezone); +    $result .= $nick . ": " . $now->strftime("$datetime"); +  } + +  $item->default_handler($get_size_only, undef, $result, 1); +} + +sub refresh_timezones { +  Irssi::statusbar_items_redraw('timezones'); +} + +sub init_timezones { +  Irssi::timeout_remove($refresh_tag) if ($refresh_tag); +  $refresh_tag = Irssi::timeout_add(1000, \&refresh_timezones, undef); +} + +Irssi::statusbar_item_register('timezones', '{sb $0-}', 'timezones'); +Irssi::settings_add_str('timezones', 'timezones_clock_format', '%H:%M:%S'); +Irssi::settings_add_str('timezones', 'timezones_divider', ' '); +Irssi::settings_add_str('timezones', 'timezones', 'Mike:GMT Sergey:EST'); + +init_timezones(); +Irssi::signal_add('setup changed', \&init_timezones); +refresh_timezones(); | 
