From 4f93717917c52b2d21d5d7956c14de4fd8d3203f Mon Sep 17 00:00:00 2001 From: eleksir Date: Thu, 13 Oct 2016 08:43:54 +0300 Subject: [PATCH] add pair of my draft scripts as well as some known ones --- autoaway.pl | 142 +++++++++++++++++++++++++++++++++++ dispatch.pl | 26 +++++++ img_wget.pl | 157 +++++++++++++++++++++++++++++++++++++++ info.pl | 93 +++++++++++++++++++++++ timer.pl | 175 +++++++++++++++++++++++++++++++++++++++++++ trackbar.pl | 189 +++++++++++++++++++++++++++++++++++++++++++++++ znc_timestamp.pl | 81 ++++++++++++++++++++ 7 files changed, 863 insertions(+) create mode 100644 autoaway.pl create mode 100644 dispatch.pl create mode 100644 img_wget.pl create mode 100644 info.pl create mode 100644 timer.pl create mode 100644 trackbar.pl create mode 100644 znc_timestamp.pl diff --git a/autoaway.pl b/autoaway.pl new file mode 100644 index 0000000..26fc3b0 --- /dev/null +++ b/autoaway.pl @@ -0,0 +1,142 @@ +# /AUTOAWAY - Mark user away after seconds of inactivity +# /AWAY - play nice with autoaway +# New, brighter, whiter version of my autoaway script. Actually works :) +# (c) 2000 Larry Daffner (vizzie@airmail.net) +# You may freely use, modify and distribute this script, as long as +# 1) you leave this notice intact +# 2) you don't pretend my code is yours +# 3) you don't pretend your code is mine +# +# share and enjoy! + +# A simple script. /autoaway will mark you as away automatically if +# you have not typed any commands in seconds. (=0 disables the feature) +# It will also automatically unmark you away the next time you type a command. +# Note that using the /away command will disable the autoaway mechanism, as +# well as the autoreturn. (when you unmark yourself, the autoaway wil +# restart again) + +# Thanks to Adam Monsen for multiserver and config file fix + +use Irssi; +use Irssi::Irc; + +use vars qw($VERSION %IRSSI); +$VERSION = "0.3"; +%IRSSI = ( + authors => 'Larry "Vizzie" Daffner', + contact => 'vizzie@airmail.net', + name => 'Automagic away setting', + description => 'Automatically goes away after defined inactivity', + license => 'BSD', + url => 'http://www.flamingpackets.net/~vizzie/irssi/', + changed => 'Tue Oct 19 14:41:15 CDT 2010', + changes => 'Applied multiserver/store config patch from Adam Monsen' +); + +my ($autoaway_sec, $autoaway_to_tag, $autoaway_state); +$autoaway_state = 0; + +# +# /AUTOAWAY - set the autoaway timeout +# +sub cmd_autoaway { + my ($data, $server, $channel) = @_; + + if (!($data =~ /^[0-9]+$/)) { + Irssi::print("autoaway: usage: /autoaway "); + return 1; + } + + $autoaway_sec = $data; + + if ($autoaway_sec) { + Irssi::settings_set_int("autoaway_timeout", $autoaway_sec); + Irssi::print("autoaway timeout set to $autoaway_sec seconds"); + } else { + Irssi::print("autoway disabled"); + } + + if (defined($autoaway_to_tag)) { + Irssi::timeout_remove($autoaway_to_tag); + $autoaway_to_tag = undef; + } + + if ($autoaway_sec) { + $autoaway_to_tag = + Irssi::timeout_add($autoaway_sec*1000, "auto_timeout", ""); + } +} + +# +# away = Set us away or back, within the autoaway system +sub cmd_away { + my ($data, $server, $channel) = @_; + + if ($data eq "") { + $autoaway_state = 0; + # If $autoaway_state is 2, we went away by typing /away, and need + # to restart autoaway ourselves. Otherwise, we were autoaway, and + # we'll let the autoaway return take care of business. + + if ($autoaway_state eq 2) { + if ($autoaway_sec) { + $autoaway_to_tag = + Irssi::timeout_add($autoaway_sec*1000, "auto_timeout", ""); + } + } + } else { + if ($autoaway_state eq 0) { + Irssi::timeout_remove($autoaway_to_tag); + $autoaway_to_tag = undef; + $autoaway_state = 2; + } + } +} + +sub auto_timeout { + my ($data, $server) = @_; + + # we're in the process.. don't touch anything. + $autoaway_state = 3; + foreach my $server (Irssi::servers()) { + $server->command("/AWAY autoaway after $autoaway_sec seconds"); + } + + Irssi::timeout_remove($autoaway_to_tag); + $autoaway_state = 1; +} + +sub reset_timer { + if ($autoaway_state eq 1) { + $autoaway_state = 3; + foreach my $server (Irssi::servers()) { + $server->command("/AWAY"); + } + + $autoaway_state = 0; + } + if ($autoaway_state eq 0) { + if (defined($autoaway_to_tag)) { + Irssi::timeout_remove($autoaway_to_tag); + $autoaway_to_tag = undef(); + } + if ($autoaway_sec) { + $autoaway_to_tag = Irssi::timeout_add($autoaway_sec*1000 + , "auto_timeout", ""); + } + } +} + +Irssi::settings_add_int("misc", "autoaway_timeout", 0); + +$autoaway_default = Irssi::settings_get_int("autoaway_timeout"); +if ($autoaway_default) { + $autoaway_to_tag = + Irssi::timeout_add($autoaway_default*1000, "auto_timeout", ""); + +} + +Irssi::command_bind('autoaway', 'cmd_autoaway'); +Irssi::command_bind('away', 'cmd_away'); +Irssi::signal_add('send command', 'reset_timer'); diff --git a/dispatch.pl b/dispatch.pl new file mode 100644 index 0000000..6050520 --- /dev/null +++ b/dispatch.pl @@ -0,0 +1,26 @@ +use strict; +use warnings; +use Irssi; +use Irssi::Irc; +use vars qw($VERSION %IRSSI); + +$VERSION = "0.0.2"; +%IRSSI = ( + authors => "Sebastian 'yath' Schmidt", + contact => "yathen\@web.de", + name => "Command dispatcher", + description => "This scripts sends unknown commands to the server", + license => "GNU GPLv2", + changed => "Tue Mar 5 14:55:29 CET 2002", +); + +sub event_default_command { + my ($command, $server) = @_; + return if (Irssi::settings_get_bool("dispatch_unknown_commands") == 0 + || !$server); + $server->send_raw($command); + Irssi::signal_stop(); +} + +Irssi::settings_add_bool("misc", "dispatch_unknown_commands", 1); +Irssi::signal_add_first("default command", "event_default_command"); diff --git a/img_wget.pl b/img_wget.pl new file mode 100644 index 0000000..36fba85 --- /dev/null +++ b/img_wget.pl @@ -0,0 +1,157 @@ +#use strict; +#use warnings "all"; +use threads; +use threads::shared; +use URI::URL; +use Image::Magick; +use Irssi qw (command_bind + settings_get_bool settings_add_bool + settings_get_str settings_add_str); +use vars qw($VERSION %IRSSI); + +sub info_cmd; +sub notify_cmd; +sub event_msg; + +sub dlfunc(@); +sub cdlfunc($); # thread, that checks and downloads stuff +sub is_picture($); +sub urlencode($); + + +$VERSION = '1.00'; +%IRSSI = ( + authors => 'Eleksir', + contact => 'eleksir@exs-elm.ru', + name => 'Image downloader', + description => 'Sample script to test irssi api.', + license => 'Public Domain', + changed => 'Sun Oct 02 12:21 CET 2016', +); + +my $wgetpath; + +if (-f "/bin/wget") { + $wgetpath = '/bin/wget'; +} elsif (-f "/usr/bin/wget") { + $wgetpath = '/usr/bin/wget'; +} elsif (-f "/usr/local/bin/wget") { + $wgetpath = '/usr/local/bin/wget'; +} + +Irssi::signal_add_last("message public", "hookfn"); + +my $active = 0; +share($active); +my $hook; + +sub hookfn { + my ($a, $text, $b, $c) = @_; + my @words = split(/\s+/, $text); + + foreach (@words) { + if ($_ =~ m{:?https?://([a-zA-Z0-9.-]+\.[a-zA-Z]+)/(?:.*)}) { + $active = 1; + my $t = undef; + + do { + $t = threads->create('cdlfunc', $_); + sleep 1 unless(defined($t)); + } unless (defined($t)); + + undef $t; + + if ($active == 1) { + $hook = Irssi::timeout_add(500, "timeraction", ''); + } +# catch only first link + last; + } + } + + return; +} + + +sub cdlfunc($) { + my $url = shift; + my $extension = is_picture($url); + + if (defined($extension)) { + my $savepath = sprintf("%s/imgsave", $ENV{'HOME'}); + mkdir ($savepath) unless (-d $savepath); + $savepath = $savepath . "/" . s/[^\w!., -#]/_/gr . ".$extension"; + + if ( (lc($url) =~ /\.(gif|jpeg|png|webm|mp4)$/) and ($1 eq $extension) ){ + $savepath = $ENV{'HOME'} . "/imgsave/" . s/[^\w!., -#]/_/gr; + } + + dlfunc($url, $savepath); + } + + $active = 0; + return; +} + +sub dlfunc(@) { + my $url = shift; + my $file = shift; + + $url = urlencode($url); + system($wgetpath, '--no-check-certificate', '-q', '-T', '20', '-O', $file, '-o', '/dev/null', $url); + + if ($file =~ /(png|jpe?g|gif)$/i){ + my $im = Image::Magick->new(); + my $rename = 1; + my (undef, undef, undef, $format) = $im->Ping($file); + + if (defined($format)) { + $rename = 0 if (($format eq 'JPEG') and ($file =~ /jpe?g$/i)); + $rename = 0 if (($format eq 'GIF') and ($file =~ /gif$/i)); + $rename = 0 if (($format =~ /^PNG/) and ($file =~ /png$/i)); + rename $file, sprintf("%s.%s", $file, lc($format)) if ($rename == 1); + } + } + + return; +} + +sub is_picture($) { + my $url = shift; + $url = urlencode($url); + my $r = undef; + + $r = `$wgetpath --no-check-certificate -q --method=HEAD -S --timeout=5 "$url" 2>&1`; + + foreach (split(/\n/, $r)) { + next unless($_ =~ /Content\-Type: (.+)/); + $r = ($1); chomp($r); + last; + } + + if (defined($r)) { + if ($r =~ /^image\/gif/) {return 'gif';}; + if ($r =~ /^image\/jpe?g/){return 'jpeg';}; + if ($r =~ /^image\/png/) {return 'png';}; + if ($r =~ /^video\/webm/) {return 'webm';}; + if ($r =~ /^video\/mp4/) {return 'mp4';}; + } + + return undef; +} + +sub urlencode($) { + my $url = shift; + my $urlobj = url $url; + $url = $urlobj->as_string; + undef $urlobj; + return $url; +} + +sub timeraction { + if (($active == 0) and (defined($hook))) { + Irssi::timeout_remove($hook); + } + + return; +} diff --git a/info.pl b/info.pl new file mode 100644 index 0000000..11168be --- /dev/null +++ b/info.pl @@ -0,0 +1,93 @@ +#use strict; +#use warnings "all"; +use threads; +use threads::shared; +use URI::URL; +use Image::Magick; +use Irssi qw (command_bind + settings_get_bool settings_add_bool + settings_get_str settings_add_str); +use vars qw($VERSION %IRSSI); + +sub notify_cmd; +sub notify; +sub hookfn; +sub timeraction; + +$VERSION = '1.00'; +%IRSSI = ( + authors => 'Eleksir', + contact => 'eleksir@exs-elm.ru', + name => 'Test command script', + description => 'Sample script to test irssi api.', + license => 'Public Domain', + changed => 'Sun Oct 02 12:21 CET 2016', +); + +Irssi::command_bind( 'test' => 'notify_cmd' ); +Irssi::signal_add_last("message public", "hookfn"); +Irssi::signal_add_last("message private", "hookfn"); + +my $active = 0; +share($active); + +my $hook; + +sub notify_cmd { + my ($argstring, $serverhref, $channelhref) = @_; + sleep 300; + my %SERVER = %{$serverhref}; + my %CHANNEL = %{$channelhref}; + foreach (keys(%SERVER)){ + Irssi::active_win()->print("SERVER $_ = $SERVER{$_}"); + } + foreach (keys(%CHANNEL)){ + Irssi::active_win()->print("CHANNEL $_ = $CHANNEL{$_}"); + } + Irssi::active_win()->print("$argstring"); + Irssi::active_win()->print("With limited HP you either die fast or live long enough to become suka blya"); +} + +sub notify { + my ($topic, $message) = @_; + threads->detach(); + $topic =~ s/\\/\\\\/g; + $topic =~ s/\'/\\'/g; + $message =~ s/\\/\\\\/g; + $message =~ s/\'/\\'/g; + system("notify-send", "-u", "normal", "-t", "12000", "-a", "hexchat", $topic, "-i", "hexchat", $message); + $active = 0; +} + +sub hookfn { + my ($server, $message, $nick, $nick_address, $chan) = @_; + + $active = 1; + $message = Irssi::strip_codes($message); + $nick = Irssi::strip_codes($nick); + my $topic = sprintf("%s at %s says:\n", $nick, $chan); + +#Irssi::active_win()->print(sprintf("%s at %s says: %s", $nick, $chan, $message)); + + my $t = undef; + + do { + $t = threads->create(\¬ify, $topic, $message); + sleep 1 unless(defined($t)); + } unless (defined($t)); + + undef $t; + + if ($active == 1) { + $hook = Irssi::timeout_add(250, "timeraction", ''); + } +} + +sub timeraction { + if (($active == 0) and (defined($hook))) { + Irssi::timeout_remove($hook); + } + + return; +} + diff --git a/timer.pl b/timer.pl new file mode 100644 index 0000000..1f5452c --- /dev/null +++ b/timer.pl @@ -0,0 +1,175 @@ +# Fixes for multiple servers and window items by dg +# +# 2003-08-27 coekie: +# - use item names and server tags, fixes irssi crash if window item or server is destroyed +# +# 2003-08-19 +# - changed timer stop code a bit. +# should fix the random timer o.O never happened to me before. +# +# 2002-12-21 darix: +# - nearly complete rewrite ;) the old version wasnt "use strict;" capable =) +# - still some warnings with "use warnings;" +# - use of command_runsub now :) +# + +use strict; +use Data::Dumper; +use warnings; +use vars qw ($VERSION %IRSSI); +use Irssi 20020325 qw (command_bind command_runsub command timeout_add timeout_remove signal_add_first); + +$VERSION = '0.5'; +%IRSSI = ( + authors => 'Kimmo Lehto, Marcus Rueckert', + contact => 'kimmo@a-men.org, darix@irssi.org' , + name => 'Timer', + description => 'Provides /timer command for mIRC/BitchX type timer functionality.', + license => 'Public Domain', + changed => '2003-08-27' +); + +our %timers; +# my %timer = { repeat => \d+, command => '' , windowitem => NULL , server=> NULL, timer = NULL}; + +sub timer_command { + my ( $name ) = @_; + if ( exists ( $timers{$name} ) ) { + if ( $timers{$name}->{'repeat'} != -1 ) { + if ( $timers{$name}->{'repeat'}-- == 0) { + cmd_timerstop( $name ); + return; + } + } + + my ($server, $item); + if ($timers{$name}->{'server'}) { + $server = Irssi::server_find_tag( $timers{$name}->{'server'} ); + } + if ( $server ) { + if ( $timers{$name}->{'windowitem'}) { + $item = $server->window_find_item( $timers{$name}->{'windowitem'} ); + } + ($item ? $item : $server)->command( $timers{$name}->{'command'} ); + } else { + command( $timers{$name}->{'command'} ); + } + } +} + +sub cmd_timerstop { + my ( $name ) = @_; + + if ( exists ( $timers{$name} ) ) { + timeout_remove($timers{$name}->{'timer'}); + $timers{$name} = (); + delete ( $timers{$name} ); + print( CRAP "Timer \"$name\" stopped." ); + } + else { + print( CRAP "\cBTimer:\cB No such timer \"$name\"." ); + } +} + +sub cmd_timer_help { + print ( < [] +TIMER STOP + +repeat value of 0 means unlimited too + +EOF + ); +} + +command_bind 'timer add' => sub { + my ( $data, $server, $item ) = @_; + my ( $name, $interval, $times, $command ); + + if ( $data =~ /^\s*(\w+)\s+(\d+)\s+(-?\d+)\s+(.*)$/ ) { + ( $name, $interval, $times, $command ) = ( $1, $2, $3, $4 ); + $times = -1 if ( $times == 0 ); + } + elsif ( $data =~ /^\s*(\w+)\s+(\d+)\s+(.*)$/ ) + { + ( $name, $interval, $times, $command ) = ( $1, $2, -1, $3 ); + } + else { + print( CRAP "\cBTimer:\cB parameters not understood. commandline was: timer add $data"); + return; + }; + + if ( $times < -1 ) { + print( CRAP "\cBTimer:\cB repeat should be greater or equal to -1" ); + return; + }; + + if ( $command eq "" ) { + print( CRAP "\cBTimer:\cB command is empty commandline was: timer add $data" ); + return; + }; + + if ( exists ( $timers{$name} ) ) { + print( CRAP "\cBTimer:\cB Timer \"$name\" already active." ); + } + else { + #$timers{$name} = {}; + $timers{$name}->{'repeat'} = $times; + $timers{$name}->{'interval'} = $interval; + $timers{$name}->{'command'} = $command; + if ($item) { + $timers{$name}->{'windowitem'} = $item->{'name'}; + } + if ($server) { + $timers{$name}->{'server'} = $server->{'tag'}; + } + + if ( $times == -1 ) { + $times = 'until stopped.'; + } + else { + $times .= " times."; + } + + print( CRAP "Starting timer \"$name\" repeating \"$command\" every $interval seconds $times" ); + + $timers{$name}->{'timer'} = timeout_add( $interval * 1000, \&timer_command, $name ); + } +}; + +command_bind 'timer list' => sub { + print( CRAP "Active timers:" ); + foreach my $name ( keys %timers ) { + if ( $timers{$name}->{repeat} == -1 ) { + print( CRAP "$name = $timers{$name}->{'command'} (until stopped)"); + } + else { + print( CRAP "$name = $timers{$name}->{'command'} ($timers{$name}->{'repeat'} repeats left)" ); + } + } + print( CRAP "End of /timer list" ); +}; + +command_bind 'timer stop' => sub { + my ( $data, $server, $item ) = @_; + cmd_timerstop ($data); +}; + +command_bind 'timer help' => sub { cmd_timer_help() }; + +command_bind 'timer' => sub { + my ( $data, $server, $item ) = @_; + $data =~ s/\s+$//g; + command_runsub ( 'timer', $data, $server, $item ) ; +}; + + +signal_add_first 'default command timer' => sub { +# +# gets triggered if called with unknown subcommand +# + cmd_timer_help() +} + diff --git a/trackbar.pl b/trackbar.pl new file mode 100644 index 0000000..7123330 --- /dev/null +++ b/trackbar.pl @@ -0,0 +1,189 @@ +# trackbar.pl +# +# This little script will do just one thing: it will draw a line each time you +# switch away from a window. This way, you always know just upto where you've +# been reading that window :) It also removes the previous drawn line, so you +# don't see double lines. +# +# Usage: +# +# The script works right out of the box, but if you want you can change +# the working by /set'ing the following variables: +# +# trackbar_string The characters to repeat to draw the bar +# trackbar_style The style for the bar, %r is red for example +# See formats.txt that came with irssi +# +# /mark is a command that will redraw the line at the bottom. However! This +# requires irssi version after 20021228. otherwise you'll get the error +# redraw: unknown command, and your screen is all goofed up :) +# +# /upgrade & buf.pl notice: This version tries to remove the trackbars before +# the upgrade is done, so buf.pl does not restore them, as they are not removeable +# afterwards by trackbar. Unfortiounatly, to make this work, trackbar and buf.pl +# need to be loaded in a specific order. Please experiment to see which order works +# for you (strangely, it differs from configuration to configuration, something I will +# try to fix in a next version) +# +# Authors: +# - Main maintainer & author: Peter 'kinlo' Leurs +# - Many thanks to Timo 'cras' Sirainen for placing me on my way +# - on-upgrade-remove-line patch by Uwe Dudenhoeffer +# +# Version history: +# 1.4: - Changed our's by my's so the irssi script header is valid +# - Removed utf-8 support. In theory, the script should work w/o any +# problems for utf-8, just set trackbar_string to a valid utf-8 character +# and everything *should* work. However, this script is being plagued by +# irssi internal bugs. The function Irssi::settings_get_str does NOT handle +# unicode strings properly, hence you will notice problems when setting the bar +# to a unicode char. For changing your bar to utf-8 symbols, read the line sub. +# 1.3: - Upgrade now removes the trackbars. +# - Some code cleanups, other defaults +# - /mark sets the line to the bottom +# 1.2: - Support for utf-8 +# - How the bar looks can now be configured with trackbar_string +# and trackbar_style +# 1.1: - Fixed bug when closing window +# 1.0: - Initial release +# +# +# Call for help! +# +# There is a trackbar version 2.0 that properly handles resizes and immediate config change +# activation. However, there is/are some bug(s) in irssi's main buffer/window code that causes +# irssi to 'forget' lines, which is ofcourse completly unaccepteable. I haven't found the time +# nor do I know the irssi's internals enough to find and fix this bug, if you want to help, please +# contact me, I'll give you a copy of the 2.0 version that will immediatly show you the problems. +# +# Known bugs: +# - if you /clear a window, it will be uncleared when returning to the window +# - UTF-8 characters in the trackbar_string doesnt work. This is an irssi bug. +# - if you resize your irssi (in xterm or so) the bar is not resized +# - changing the trackbar style is only visible after returning to a window +# however, changing style/resize takes in effect after you left the window. +# +# Whishlist/todo: +# - instead of drawing a line, just invert timestamp or something, +# to save a line (but I don't think this is possible with current irssi) +# - some pageup keybinding possibility, to scroll up upto the trackbar +# - <@coekie> kinlo: if i switch to another window, in another split window, i +# want the trackbar to go down in the previouswindow in that splitwindow :) +# - < bob_2> anyway to clear the line once the window is read? +# - < elho> kinlo: wishlist item: a string that gets prepended to the repeating pattern +# - < elho> an option to still have the timestamp in front of the bar +# - < elho> oh and an option to not draw it in the status window :P +# +# BTW: when you have feature requests, mailing a patch that works is the fastest way +# to get it added :p + +use strict; +use 5.6.1; +use Irssi; +use Irssi::TextUI; + +my $VERSION = "1.4"; + +my %IRSSI = ( + authors => "Peter 'kinlo' Leurs", + contact => "peter\@pfoe.be", + name => "trackbar", + description => "Shows a bar where you've last read a window", + license => "GPLv2", + url => "http://www.pfoe.be/~peter/trackbar/", + changed => "Thu Feb 20 16:18:08 2003", +); + +my %config; + +Irssi::settings_add_str('trackbar', 'trackbar_string' => '-'); +$config{'trackbar_string'} = Irssi::settings_get_str('trackbar_string'); + +Irssi::settings_add_str('trackbar', 'trackbar_style' => '%K'); +$config{'trackbar_style'} = Irssi::settings_get_str('trackbar_style'); + +Irssi::signal_add( + 'setup changed' => sub { + $config{'trackbar_string'} = Irssi::settings_get_str('trackbar_string'); + $config{'trackbar_style'} = Irssi::settings_get_str('trackbar_style'); + if ($config{'trackbar_style'} =~ /(? sub { + my (undef, $oldwindow) = @_; + + if ($oldwindow) { + my $line = $oldwindow->view()->get_bookmark('trackbar'); + $oldwindow->view()->remove_line($line) if defined $line; + $oldwindow->print(line($oldwindow->{'width'}), MSGLEVEL_NEVER); + $oldwindow->view()->set_bookmark_bottom('trackbar'); + } + } +); + +sub line { + my $width = shift; + my $string = $config{'trackbar_string'}; + $string = '-' unless defined $string; + + # There is a bug in irssi's utf-8 handling on config file settings, as you + # can reproduce/see yourself by the following code sniplet: + # + # my $quake = pack 'U*', 8364; # EUR symbol + # Irssi::settings_add_str 'temp', 'temp_foo' => $quake; + # Irssi::print length $quake; + # # prints 1 + # Irssi::print length Irssi::settings_get_str 'temp_foo'; + # # prints 3 + # + # + # Trackbar used to have a workaround, but on recent versions of perl/irssi + # it does no longer work. Therefore, if you want your trackbar to contain + # unicode characters, uncomment the line below for a nice full line, or set + # the string to whatever char you want. + + # $string = pack('U*', 0x2500); + + + my $length = length $string; + + if ($length == 0) { + $string = '-'; + $length = 1; + } + + my $times = $width / $length; + $times = int(1 + $times) if $times != int($times); + $string =~ s/%/%%/g; + return $config{'trackbar_style'} . substr($string x $times, 0, $width); +} + +# Remove trackbars on upgrade - but this doesn't really work if the scripts are not loaded in the correct order... watch out! + +Irssi::signal_add_first( 'session save' => sub { + for my $window (Irssi::windows) { + next unless defined $window; + my $line = $window->view()->get_bookmark('trackbar'); + $window->view()->remove_line($line) if defined $line; + } + } +); + +sub cmd_mark { + my $window = Irssi::active_win(); +# return unless defined $window; + my $line = $window->view()->get_bookmark('trackbar'); + $window->view()->remove_line($line) if defined $line; + $window->print(line($window->{'width'}), MSGLEVEL_NEVER); + $window->view()->set_bookmark_bottom('trackbar'); + Irssi::command("redraw"); +} + +Irssi::command_bind('mark', 'cmd_mark'); diff --git a/znc_timestamp.pl b/znc_timestamp.pl new file mode 100644 index 0000000..6d31e4d --- /dev/null +++ b/znc_timestamp.pl @@ -0,0 +1,81 @@ +#!/usr/bin/env perl + +use Irssi; +use Irssi::Irc; + +use strict; + +use vars qw($VERSION %IRSSI); + +$VERSION = "0.01"; +%IRSSI = ( + authors => 'Domen Puncer', + contact => 'domen@cba.si', + name => 'znc_timestamp', + description => 'Replace znc timestamps with native irssi ones', + license => 'GPLv2', +); + +# this script was based on bitlbee_timestamp by Tijmen "timing" Ruizendaal + +my $tf = Irssi::settings_get_str('timestamp_format'); + +my $prev_date = ''; + +sub privmsg { + my ($server, $data, $nick, $address) = @_; + my ($target, $text) = split(/ :/, $data, 2); + action($server, $text, $nick, $address, $target, 1); +} + +sub action { + my ($server, $text, $nick, $address, $target, $privmsg) = @_; + + # What we need to match: ^[17:05] + if ($text =~ /^(\x01ACTION )?\[\d\d:\d\d\]/) { + my $window; + my $time = $text; + my $date; + $time =~ s/^(\x01ACTION )?\[(\d\d:\d\d)\] .*/$2/g; + $text =~ s/\[(..:..)\] //; + + + my $mday; my $mon; my $year; + (undef,undef,undef,$mday,$mon,$year,undef) = localtime; + $date = sprintf("%04s-%02s-%02s\n", $year + 1900, $mon + 1, $mday, ); + + + if( $date ne $prev_date ){ + if( $target =~ /#|&/ ){ # find channel window based on target + $window = Irssi::window_find_item($target); + } else { # find query window based on nick + $window = Irssi::window_find_item($nick); + } + if( $window != undef ){ + my($year, $month, $day) = split(/-/, $date); + my $formatted_date = $day.' '.$month.' '.$year; + $window->print('Day changed to '.$formatted_date, MSGLEVEL_NEVER); + } + } + $prev_date = $date; + + #print "change timestamp to |$time| because of:".$server->{tag}.$target." <$nick> $text"; + Irssi::settings_set_str('timestamp_format', $time); + + # different arguments for privmsg vs. action + if ($privmsg) { + Irssi::signal_continue($server, $target . ' :' . $text, $nick, $address); + } else { + Irssi::signal_continue($server, $text, $nick, $address, $target); + } + + my $escaped = $tf; + $escaped =~ s/%/%%/g; + #print "change back to $escaped"; + Irssi::settings_set_str('timestamp_format', $tf); + } +} + +Irssi::signal_add('event privmsg', 'privmsg'); +Irssi::signal_add('event notice', 'privmsg'); +Irssi::signal_add('ctcp action', 'action');