diff options
Diffstat (limited to 'scripts/perl')
-rw-r--r-- | scripts/perl/awaylog.pl | 68 | ||||
-rw-r--r-- | scripts/perl/beep.pl | 56 | ||||
-rw-r--r-- | scripts/perl/exec.pl | 129 | ||||
-rw-r--r-- | scripts/perl/fete.pl | 163 | ||||
-rw-r--r-- | scripts/perl/fortune.pl | 57 | ||||
-rw-r--r-- | scripts/perl/hello.pl | 34 | ||||
-rw-r--r-- | scripts/perl/kernel.pl | 74 | ||||
-rw-r--r-- | scripts/perl/logsearch.pl | 95 | ||||
-rw-r--r-- | scripts/perl/moc.pl | 166 | ||||
-rw-r--r-- | scripts/perl/sound.pl | 95 | ||||
-rw-r--r-- | scripts/perl/translate.pl | 128 | ||||
-rw-r--r-- | scripts/perl/xmms.pl | 64 |
12 files changed, 1129 insertions, 0 deletions
diff --git a/scripts/perl/awaylog.pl b/scripts/perl/awaylog.pl new file mode 100644 index 000000000..0e70248c2 --- /dev/null +++ b/scripts/perl/awaylog.pl @@ -0,0 +1,68 @@ +############################################################################## +# # +# Away highlite loger # +# # +# Perl script for WeeChat. # +# # +# Log highlite/private msg when you are away # +# # +# # +# # +# Copyright (C) 2006 Jiri Golembiovsky <golemj@gmail.com> # +# # +# This program is free software; you can redistribute it and/or # +# modify it under the terms of the GNU General Public License # +# as published by the Free Software Foundation; either version 2 # +# of the License, or (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program; if not, write to the Free Software # +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # +# MA 02110-1301, USA. # +# # +############################################################################## + +weechat::register( "AwayLog", "0.4", "", "Log privmsg/highlite when you are away" ); + +weechat::add_message_handler( "PRIVMSG", "awaylog" ); + +sub test_highlight { + $str = shift; + $irc_highlight = weechat::get_config( "irc_highlight" ); + @arr = split( ",", $irc_highlight ); + $b = 0; + $str = lc( $str ); + while( $item = pop( @arr ) ) { + $item = lc( $item ); + if( substr( $item, 0, 1 ) eq '*' ) { $item = '.' . $item; } + if( substr( $item, length( $item ) - 1, 1 ) eq '*' ) { $item = substr( $item, , 0, length( $item ) - 1 ) . ".*"; } + if( $str =~ /$item/ ) { $b++; } + } + return $b; +} + +sub awaylog { + if( weechat::get_info( "away", $_[0] ) == 1 ) { + $i = index( $_[1], " PRIVMSG " ); + $hostmask = substr( $_[1], 0, $i ); + $str = substr( $_[1], $i + 9 ); + $i = index( $str, ":" ); + $channel = substr( $str, 0, $i - 1 ); + $message = substr( $str, $i + 1 ); + if( substr( $hostmask, 0, 1 ) eq ":" ) { + $hostmask = substr( $hostmask, 1 ); + } + ($nick, $host) = split( "!", $hostmask ); + $mynick = weechat::get_info( "nick", $_[0] ); + if( ( index( $message, $mynick ) != -1 ) || ( $channel eq $mynick ) || ( test_highlight( $message ) > 0 ) ) { + weechat::print( "$channel -- $nick :: $message", "", $_[0] ); + } + } + return 0; +} + diff --git a/scripts/perl/beep.pl b/scripts/perl/beep.pl new file mode 100644 index 000000000..57e618de4 --- /dev/null +++ b/scripts/perl/beep.pl @@ -0,0 +1,56 @@ +# +# Copyright (c) 2006 by FlashCode <flashcode@flashtux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# + +# +# Speaker beep on highlight/private msg. +# +# History: +# +# 2006-09-02, FlashCode <flashcode@flashtux.org>: +# initial release +# + +use strict; + +my $version = "0.1"; +my $beep_command = "echo -n \a"; + +# default values in setup file (~/.weechat/plugins.rc) +my $default_beep_highlight = "on"; +my $default_beep_pv = "on"; + +weechat::register("Beep", $version, "", "Speaker beep on highlight/private msg"); +weechat::set_plugin_config("beep_highlight", $default_beep_highlight) if (weechat::get_plugin_config("beep_highlight") eq ""); +weechat::set_plugin_config("beep_pv", $default_beep_pv) if (weechat::get_plugin_config("beep_pv") eq ""); + +weechat::add_message_handler("weechat_highlight", "highlight"); +weechat::add_message_handler("weechat_pv", "pv"); + +sub highlight +{ + my $beep = weechat::get_plugin_config("beep_highlight"); + system($beep_command) if ($beep eq "on"); + return weechat::PLUGIN_RC_OK; +} + +sub pv +{ + my $beep = weechat::get_plugin_config("beep_pv"); + system($beep_command) if ($beep eq "on"); + return weechat::PLUGIN_RC_OK; +} diff --git a/scripts/perl/exec.pl b/scripts/perl/exec.pl new file mode 100644 index 000000000..1bb3cf3d8 --- /dev/null +++ b/scripts/perl/exec.pl @@ -0,0 +1,129 @@ +############################################################################## +# # +# Exec # +# # +# Perl script for WeeChat. # +# # +# Execute the command and print it to the actual buffer or server # +# # +# # +# # +# Copyright (C) 2006 Jiri Golembiovsky <golemj@gmail.com> # +# # +# This program is free software; you can redistribute it and/or # +# modify it under the terms of the GNU General Public License # +# as published by the Free Software Foundation; either version 2 # +# of the License, or (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program; if not, write to the Free Software # +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # +# MA 02110-1301, USA. # +# # +############################################################################## + +use Config; + +$Config{usethreads} or die( "Recompile Perl with threads to run this script." ); + +use Thread; + +my $registred = 0; +weechat::register( "Exec", "0.2", "", "Execute the command and print it to some buffer" ); + +weechat::add_command_handler( + "exec", + execute, + "Execute the command and print it to some buffer", + "[-o][ -win server:::channel] <cmd line>", + " -o print as msg\n". + " -win server:::channel print the output to the specific buffer", + "" +); + +sub execute { + if( !$registred ) { return; } + my $i = 0; + my $cmd = ""; + my $msg = 0; + my $win = ""; + my @arr = split( ' ', $_[1] ); + my $cmdStart = 0; + if( $#arr < 0 ) { return; } + for( $i = 0; $i <= $#arr; $i++ ) { + if( @arr[$i] eq "-win" ) { + $i++; + $win = @arr[$i]; + $cmdStart = $i + 1; + } + if( @arr[$i] eq "-o" ) { + $msg = 1; + $cmdStart = $i + 1; + } + } + for( $i = $cmdStart; $i <= $#arr; $i++ ) { + if( length( $cmd ) ) { $cmd = $cmd . ' '; } + $cmd = $cmd . @arr[$i]; + } + + my $thr = new Thread \&func_execute, $cmd, $msg, $win; +} + +sub func_execute { + my $command = shift; + my $msg = shift; + my $win = shift; + my $c = 1; + my $char = ''; + my $date = `date +%Y%m%d%H%M%S%N`; + my $out = ""; + + if( !length( $command ) ) { + weechat::print( "No command to execute (try -? for help)" ); + return; + } + + if( substr( $date, length( $date ) - 1, 1 ) eq "\n" ) { $date = substr( $date, 0, length( $date ) - 1 ); } + + if( length( $command ) ) { system( $command . " > /tmp/weechat_" . $date . " 2>&1" ); } + + open( FD, '<', "/tmp/weechat_" . $date ) or weechat::print( "/tmp/weechat_" . $date . ": $!" ); + do { + $c = read( FD, $char, 1 ); + $out = $out . $char; + } while( $c ); + close( FD ); + system( "rm -f /tmp/weechat_" . $date ); + my $j = index( $win, ':::' ); + if( length( $win ) && ( $j >= 0 ) ) { + if( $msg ) { + my $win1 = substr( $win, $j + 3 ); + my $win2 = substr( $win, 0, $j ); + my @its = split( "\n", $out ); + for( $j = 0; $j <= $#its; $j++ ) { + weechat::command( $its[$j], $win1, $win2 ); + } + } else { + weechat::print( $out, substr( $win, $j + 3 ), substr( $win, 0, $j ) ); + } + } else { + if( $msg ) { + my $win1 = substr( $win, $j + 3 ); + my $win2 = substr( $win, 0, $j ); + my @its = split( "\n", $out ); + for( $j = 0; $j <= $#its; $j++ ) { + weechat::command( $its[$j], $win1, $win2 ); + } + } else { + weechat::print( $out ); + } + } +} + +$registred = 1; + diff --git a/scripts/perl/fete.pl b/scripts/perl/fete.pl new file mode 100644 index 000000000..0cdd458f9 --- /dev/null +++ b/scripts/perl/fete.pl @@ -0,0 +1,163 @@ +# ============================================================================= +# Copyright (c) 2003-2005 by FlashCode <flashcode@flashtux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +# fete.pl (c) Décembre 2003 par FlashCode <flashcode@flashtux.org> +# Mis à jour le 04/06/2005, FlashCode <flashcode@flashtux.org> +# +# Gestion des fêtes du calendrier français avec la commande "/fete" +# Syntaxe: /fete - affiche la fête du jour et du lendemain +# /fete prenom - cherche un prénom dans le calendrier +# ============================================================================= + +use locale; + +my $version = "0.4"; +weechat::register ("Fete", $version, "", "Gestion des fêtes du calendrier français"); +weechat::print ("Script 'Fete' $version chargé"); +weechat::add_command_handler ("fete", fete); + +@noms_jours = qw(Dimanche Lundi Mardi Mercredi Jeudi Vendredi Samedi); +@noms_mois = qw(Janvier Février Mars Avril Mai Juin Juillet Août Septembre Octobre Novembre Décembre); +@fetes = ( + # janvier + [ '!Marie - JOUR de l\'AN', '&Basile', '!Geneviève', '&Odilon', '&Edouard', + '&Mélaine', '&Raymond', '&Lucien', '!Alix', '&Guillaume', '&Paulin', + '!Tatiana', '!Yvette', '!Nina', '&Rémi', '&Marcel', '!Roseline', + '!Prisca', '&Marius', '&Sébastien', '!Agnès', '&Vincent', '&Barnard', + '&François de Sales', '-Conversion de St Paul', '!Paule', '!Angèle', + '&Thomas d\'Aquin', '&Gildas', '!Martine', '!Marcelle' ], + # février + [ '!Ella', '-Présentation', '&Blaise', '!Véronique', '!Agathe', + '&Gaston', '!Eugénie', '!Jacqueline', '!Apolline', '&Arnaud', + '-Notre-Dame de Lourdes', '&Félix', '!Béatrice', '&Valentin', '&Claude', + '!Julienne', '&Alexis', '!Bernadette', '&Gabin', '!Aimée', + '&Pierre Damien', '!Isabelle', '&Lazare', '&Modeste', '&Roméo', '&Nestor', + '!Honorine', '&Romain', '&Auguste' ], + # mars + [ '&Aubin', '&Charles le Bon', '&Guénolé', '&Casimir', '&Olive', '&Colette', + '!Félicité', '&Jean de Dieu', '!Françoise', '&Vivien', '!Rosine', + '!Justine', '&Rodrigue', '!Mathilde', '!Louise de Marillac', '!Bénédicte', + '&Patrice', '&Cyrille', '&Joseph', '&Herbert', '!Clémence', '!Léa', + '&Victorien', '!Catherine de Suède', '-Annonciation', '!Larissa', + '&Habib', '&Gontran', '!Gwladys', '&Amédée', '&Benjamin' ], + # avril + [ '&Hugues', '!Sandrine', '&Richard', '&Isodore', '!Irène', '&Marcellin', + '&Jean-Baptiste de la Salle', '!Julie', '&Gautier', '&Fulbert', + '&Stanislas', '&Jules', '!Ida', '&Maxime', '&Paterne', + '&Benoît-Joseph Labre', '&Anicet', '&Parfait', '!Emma', '!Odette', + '&Anselme', '&Alexandre', '&Georges', '&Fidèle', '&Marc', '!Alida', + '!Zita', '!Valérie', '!Catherine de Sienne', '&Robert' ], + # mai + [ '&Jérémie - FETE du TRAVAIL', '&Boris', '&Philippe / Jacques', '&Sylvain', + '!Judith', '!Prudence', '!Gisèle', '&Désiré - ANNIVERSAIRE 1945', + '&Pacôme', '!Solange', '!Estelle', '&Achille', '!Rolande', '&Mathias', + '!Denise', '&Honoré', '&Pascal', '&Eric', '&Yves', '&Bernardin', + '&Constantin', '&Emile', '&Didier', '&Donatien', '!Sophie', '&Bérenger', + '&Augustin', '&Germain', '&Aymar', '&Ferdinand', '-Visitation' ], + # juin + [ '&Justin', '!Blandine', '&Kévin', '!Clotilde', '&Igor', '&Norbert', + '&Gilbert', '&Médard', '!Diane', '&Landry', '&Barnabé', '&Guy', + '&Antoine de Padoue', '&Elisée', '!Germaine', '&Jean-François Régis', + '&Hervé', '&Léonce', '&Romuald', '&Silvère', '&Rodolphe', '&Alban', + '!Audrey', '&Jean-Baptiste', '&Salomon', '&Anthelme', '&Fernand', + '&Irénée', '&Pierre / Paul', '&Martial' ], + # juillet + [ '&Thierry', '&Martinien', '&Thomas', '&Florent', '&Antoine', '!Mariette', + '&Raoul', '&Thibaut', '!Amandine', '&Ulrich', '&Benoît', '&Olivier', + '&Henri / Joël', '!Camille - FETE NATIONALE', '&Donald', + '-N.D. du Mont Carmel', '!Charlotte', '&Frédéric', '&Arsène', '!Marina', + '&Victor', '!Marie-Madeleine', '!Brigitte', '!Christine', '&Jacques', + '&Anne', '!Nathalie', '&Samson', '!Marthe', '!Juliette', + '&Ignace de Loyola' ], + # août + [ '&Alphonse', '&Julien', '!Lydie', '&Jean-Marie Vianney', '&Abel', + '-Transfiguration', '&Gaëtan', '&Dominique', '&Amour', '&Laurent', + '!Claire', '!Clarisse', '&Hippolyte', '&Evrard', + '!Marie - ASSOMPTION', '&Armel', '&Hyacinthe', '!Hélène', '&Jean Eudes', + '&Bernard', '&Christophe', '&Fabrice', '!Rose de Lima', '&Barthélémy', + '&Louis', '!Natacha', '!Monique', '&Augustin', '!Sabine', '&Fiacre', + '&Aristide' ], + # septembre + [ '&Gilles', '!Ingrid', '&Grégoire', '!Rosalie', '!Raïssa', '&Bertrand', + '!Reine', '-Nativité de Marie', '&Alain', '!Inès', '&Adelphe', + '&Apollinaire', '&Aimé', '-La Ste Croix', '&Roland', '!Edith', '&Renaud', + '!Nadège', '!Emilie', '&Davy', '&Matthieu', '&Maurice', '&Constant', + '!Thècle', '&Hermann', '&Côme / Damien', '&Vincent de Paul', '&Venceslas', + '&Michel / Gabriel', '&Jérôme' ], + # octobre + [ '!Thérèse de l\'Enfant Jésus', '&Léger', '&Gérard', '&François d\'Assise', + '!Fleur', '&Bruno', '&Serge', '!Pélagie', '&Denis', '&Ghislain', '&Firmin', + '&Wilfried', '&Géraud', '&Juste', '!Thérèse d\'Avila', '!Edwige', + '&Baudouin', '&Luc', '&René', '!Adeline', '!Céline', '!Elodie', + '&Jean de Capistran', '&Florentin', '&Crépin', '&Dimitri', '!Emeline', + '&Simon / Jude', '&Narcisse', '!Bienvenue', '&Quentin' ], + # novembre + [ '&Harold - TOUSSAINT', '-Défunts', '&Hubert', '&Charles', '!Sylvie', + '!Bertille', '!Carine', '&Geoffroy', '&Théodore', '&Léon', + '&Martin - ARMISTICE 1918', '&Christian', '&Brice', '&Sidoine', '&Albert', + '!Marguerite', '!Elisabeth', '!Aude', '&Tanguy', '&Edmond', + '-Présentation de Marie', '!Cécile', '&Clément', '!Flora', '!Catherine', + '!Delphine', '&Séverin', '&Jacques de la Marche', '&Saturnin', '&André' ], + # décembre + [ '!Florence', '!Viviane', '&Xavier', '!Barbara', '&Gérald', '&Nicolas', + '&Ambroise', '-Immaculée Conception', '&Pierre Fourier', '&Romaric', + '&Daniel', '!Jeanne de Chantal', '!Lucie', '!Odile', '!Ninon', '!Alice', + '&Gaël', '&Gatien', '&Urbain', '&Abraham', '&Pierre Canisius', + '!Françoise-Xavier', '&Armand', '!Adèle', '&Emmanuel - NOEL', '&Etienne', + '&Jean', '-Sts Innocents', '&David', '&Roger', '&Sylvestre' ], +); + +sub fete_jour +{ + my ($sec, $min, $heure, $mjour, $mois, $annee, $sjour, $ajour, $est_dst) = localtime ($_[0]); + my $fete = $fetes[$mois][$mjour-1]; + $fete =~ s/^!/Ste /; + $fete =~ s/^&/St /; + $fete =~ s/^-//; + $fete; +} + +sub fete +{ + if ($#_ == 1) + { + my @params = split " ", @_[1]; + for $arg (@params) + { + for (my $mois = 0; $mois <= $#fetes; $mois++) + { + for (my $jour = 0; $jour < 31; $jour++) + { + if (uc ($fetes[$mois][$jour]) =~ /\U$arg/) + { + weechat::print (($jour + 1)." ".$noms_mois[$mois].": ".substr ($fetes[$mois][$jour], 1)); + } + } + } + } + } + else + { + my $time_now = time; + my ($fete1, $fete2) = (fete_jour ($time_now), fete_jour ($time_now + (3600 * 24))); + my ($mjour, $mois, $sjour) = (localtime ($time_now))[3, 4, 6]; + weechat::print_infobar (0, "$fete1 (demain: $fete2)"); + } + return weechat::PLUGIN_RC_OK; +} + +fete (); diff --git a/scripts/perl/fortune.pl b/scripts/perl/fortune.pl new file mode 100644 index 000000000..5eba1405c --- /dev/null +++ b/scripts/perl/fortune.pl @@ -0,0 +1,57 @@ +# This script is a port from the original fortune.pl irssi script written by +# Ivo Marino <eim@cpan.org>. This script is in the public domain +# +# Author: Julien Louis <ptitlouis@sysif.net> + +weechat::register("fortune", "0.1", "", "Send a random fortune cookie to a specified nick"); + +weechat::add_command_handler ("fortune", fortune, "Send a random fortune cookie to a specified nick", + "<nick> [lang]", + "<nick> The nickname to send the fortune cookie\n" . + " [lang] The cookie language (Default: en)\n", + "%n %-"); + +sub fortune { + + my ($server, $param) = @_; + my $return = weechat::PLUGIN_RC_OK; + my $cookie = ''; + + if ($param) { + + if ($server) { + (my $nick, my $lang) = split (' ', $param); + $lang = 'en' unless ($lang eq 'de'|| $lang eq 'it' || $lang eq +'en' || $lang eq 'fr' ); + weechat::print ("Nick: " . $nick . ", Lang: \"" . $lang . "\""); + + if ($lang eq 'de') { + $cookie = `fortune -x`; + } elsif ($lang eq 'it') { + $cookie = `fortune -a italia`; + } else { + $cookie = `fortune -a fortunes literature riddles`; + } + + $cookie =~ s/\s*\n\s*/ /g; + if ($cookie) { + $channel = weechat::get_info("channel"); + if ($channel) { + weechat::command($nick . ": " . $cookie, $channel); + } + } else { + weechat::print ("No cookie."); + $return = weechat::PLUGIN_RC_KO; + } + } else { + weechat::print ("Not connected to server"); + $return = weechat::PLUGIN_RC_KO; + } + } else { + weechat::print ("Usage: /fortune <nick> [language]"); + $return = weechat::PLUGIN_RC_KO; + } + return $return; +} + + diff --git a/scripts/perl/hello.pl b/scripts/perl/hello.pl new file mode 100644 index 000000000..ff9417a3b --- /dev/null +++ b/scripts/perl/hello.pl @@ -0,0 +1,34 @@ +# This script is a port from the hello.pl irssi script written by +# Cybertinus <cybertinus@cybertinus.nl> +# +# Licensed under the GPL v2 +# +# Author: Julien Louis <ptitlouis@sysif.net> + +weechat::register("hello" ,"0.1", "", "Display greetings depending the time"); + +weechat::add_command_handler("hello", hello, "", "Send greetings to the current buffer"); + +weechat::set_plugin_config("evening_message", "good evening"); +weechat::set_plugin_config("afternoon_message", "good afternoon"); +weechat::set_plugin_config("morning_message", "good morning"); +weechat::set_plugin_config("night_message", "good night"); + + +sub hello { + my ($server,$data) = @_; + + $time = (localtime(time))[2]; + if ($time >= 18) { + $text = weechat::get_plugin_config("evening_message"); + } elsif ($time >= 12) { + $text = weechat::get_plugin_config("afternoon_message"); + } elsif ($time >= 6) { + $text = weechat::get_plugin_config("morning_message"); + } elsif ($time >= 0) { + $text = weechat::get_plugin_config("night_message"); + } + weechat::command("$text $data"); + return weechat::PLUGIN_RC_OK; +} + diff --git a/scripts/perl/kernel.pl b/scripts/perl/kernel.pl new file mode 100644 index 000000000..ba8fae1a4 --- /dev/null +++ b/scripts/perl/kernel.pl @@ -0,0 +1,74 @@ +# +# This script is mostly a copy/paste from kernel.pl irssi script +# This script is in the public domain. +# +# Julien Louis <ptitlouis@sysif.net> + +use IO::Socket; + +weechat::register("kernel", "0.1", "", "Return latest kernel versions from kernel.org" ); + +weechat::add_command_handler("kernel_version", kernel_version); + +sub finger($$) { + # Yes, Net::Finger is already done and i'm reinventing the wheel. + my ($user, $host) = @_; + my $buffer; + if (my $socket = IO::Socket::INET->new( + PeerHost => $host, + PeerPort => 'finger(79)', + Proto => 'tcp', + )) + { + if (syswrite $socket, "$user\n") { + unless (sysread $socket, $buffer, 1024) { + # Should i use $! here? + weechat::print("Unable to read from the socket: $!"); + } + } else { + # ..and here? + weechat::print("Unable to write to the socket: $!"); + } + } else { + weechat::print("Connection to $host failed: $!"); + } + return $buffer; +} + +sub kernel_version { + my @version; + if (my $finger = finger("", "finger.kernel.org")) { + # The magic of the regexps :) + @version = $finger =~ /:\s*(\S+)\s*$/gm; + # Modify this to do whatever you want. + + my %branches = ( + 26 => "", + 24 => "", + 22 => "", + 20 => "", + ); + + foreach my $kernel (@version) { + if($kernel =~ /2\.6/) { + $branches{26} .= " $kernel"; + } elsif($kernel =~ /2\.4/) { + $branches{24} .= " $kernel"; + } elsif ($kernel =~ /2\.2/) { + $branches{22} .= " $kernel"; + } elsif ($kernel =~ /2\.0/) { + $branches{20} .= " $kernel"; + } + } + + my @keys = sort(keys(%branches)); + foreach my $key (@keys) { + weechat::print("branche " . join('.', split(//, $key))); + weechat::print("$branches{$key}"); + } + +# weechat::print("@version"); + return weechat::PLUGIN_RC_OK; + } +} + diff --git a/scripts/perl/logsearch.pl b/scripts/perl/logsearch.pl new file mode 100644 index 000000000..1708533c3 --- /dev/null +++ b/scripts/perl/logsearch.pl @@ -0,0 +1,95 @@ +# +# Copyright (c) 2006 by FlashCode <flashcode@flashtux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# + +# +# Search for text in WeeChat disk log files. +# +# History: +# 2006-04-17, FlashCode <flashcode@flashtux.org>: +# initial release +# + +use strict; + +# default values in setup file (~/.weechat/plugins.rc) +my $default_max = "8"; +my $default_server = "off"; +my $default_grep_options = "-i"; + +# init script +weechat::register("logsearch", "0.1", "", "Search for text in WeeChat disk log files"); +weechat::set_plugin_config("max", $default_max) if (weechat::get_plugin_config("max") eq ""); +weechat::set_plugin_config("server", $default_server) if (weechat::get_plugin_config("server") eq ""); +weechat::set_plugin_config("grep_options", $default_grep_options) if (weechat::get_plugin_config("grep_options") eq ""); + +# add command handler /logsearch +weechat::add_command_handler("logsearch", "logsearch", + "search for text in WeeChat disk log files", + "[-n#] text", + "-n#: max number or lines to display\n" + ."text: regular expression (used by grep)\n\n" + ."Plugins options (set with /setp):\n" + ." - perl.logsearch.max: max number of lines displayed by default\n" + ." - perl.logsearch.server: display result on server " + ."buffer (if on), otherwise on current buffer\n" + ." - perl.logsearch.grep_options: options to give to grep program", + ""); + +# /logsearch command +sub logsearch +{ + my $server = shift; + my $args = shift; + if ($args ne "") + { + # read settings + my $conf_max = weechat::get_plugin_config("max"); + $conf_max = $default_max if ($conf_max eq ""); + my $conf_server = weechat::get_plugin_config("server"); + $conf_server = $default_server if ($conf_server eq ""); + my $output_server = ""; + $output_server = $server if (lc($conf_server) eq "on"); + my $grep_options = weechat::get_plugin_config("grep_options"); + + # build log filename + my $buffer = weechat::get_info("channel", ""); + $buffer = ".".$buffer if ($buffer ne ""); + my $log_path = weechat::get_config("log_path"); + $log_path =~ s/%h/~\/.weechat/g; + my $file = $log_path.$server.$buffer.".weechatlog"; + + # run grep in log file + if ($args =~ /-n([0-9]+) (.*)/) + { + $conf_max = $1; + $args = $2; + } + my $command = "grep ".$grep_options." '".$args."' ".$file." 2>/dev/null | tail -n".$conf_max; + my $result = `$command`; + + # display result + if ($result eq "") + { + weechat::print("Text not found in $file", "", $output_server); + return weechat::PLUGIN_RC_OK; + } + my @result_array = split(/\n/, $result); + weechat::print($_, "", $output_server) foreach(@result_array); + } + return weechat::PLUGIN_RC_OK; +} diff --git a/scripts/perl/moc.pl b/scripts/perl/moc.pl new file mode 100644 index 000000000..23fbcd364 --- /dev/null +++ b/scripts/perl/moc.pl @@ -0,0 +1,166 @@ +############################################################################## +# # +# MOC # +# # +# Perl script for WeeChat. # +# # +# Show info about current song in moc # +# # +# # +# # +# Copyright (C) 2006 Jiri Golembiovsky <golemj@gmail.com> # +# # +# This program is free software; you can redistribute it and/or # +# modify it under the terms of the GNU General Public License # +# as published by the Free Software Foundation; either version 2 # +# of the License, or (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program; if not, write to the Free Software # +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # +# MA 02110-1301, USA. # +# # +############################################################################## + +weechat::register( "MOCP", "0.2", "", "Show info about current song in moc" ); +weechat::add_command_handler( + "moc", + moc, + "Show info about current song in moc", + "[[-i][-o][-ot]]", + "-i show info about current song (default parameter if no other is given)\n" . + "-o print results to the current channel as /msg\n" . + "-ot print results to the current channel as /me, this parameter overide -o parameter\n" . + "To set output format use moc_set_format command.\n" . + "To set another default output type than -i use moc_set_output command.\n", + "-i|-o|-ot" +); + +weechat::add_command_handler( + "moc_set_format", + mocSetFormat, + "Set output format for moc command", + "format_string", + "Following combinations will be replaced by apropriate text:\n". + " %A - artist\n" . + " %B - album\n" . + " %F - file name with path\n" . + " %H - file name without path\n" . + " %J - total time\n" . + " %K - current time\n" . + " %L - time left\n" . + " %M - total seconds\n" . + " %N - current seconds\n" . + " %S - state\n" . + " %T - title\n" . + " %U - song title\n" . + " %Y - biterate\n" . + " %Z - rate\n" . + "When no format string is setted then current format string is printed.", + "" +); + +weechat::add_command_handler( + "moc_set_output", + mocSetOutput, + "Set default output for moc command", + "i|o|ot", + "For more info see help of moc command", + "i|o|ot" +); + +sub info { + my $i; + my $res = ""; + my $sout = `mocp -i`; + my @out = split( "\n", $sout ); + my $format = weechat::get_plugin_config( "outputFormat" ); + if( length( $format ) == 0 ) { $format = "is listening to %T ::: %H"; } + if( $#out < 2 ) { return ""; } + for( $i = 0; $i <= $#out; $i++ ) { + if( ( index( @out[$i], ' ' ) == -1 ) || + ( index( @out[$i], ' ' ) == ( length( @out[$i] ) - 1 ) ) + ) { + @out[$i] = ""; + } else { + @out[$i] = substr( @out[$i], index( @out[$i], ' ' ) + 1 ); + } + } + $i = 0; + while( $i < length( $format ) ) { + if( substr( $format, $i, 1 ) eq '%' ) { + $i++; + if( substr( $format, $i, 1 ) eq 'A' ) { $res = $res . @out[3]; } + if( substr( $format, $i, 1 ) eq 'B' ) { $res = $res . @out[5]; } + if( substr( $format, $i, 1 ) eq 'F' ) { $res = $res . @out[1]; } + if( substr( $format, $i, 1 ) eq 'H' ) { + if( index( @out[1], "://" ) > 0 ) { + $res = $res . @out[1]; + } else { + $res = $res . substr( @out[1], rindex( @out[1], '/' ) + 1 ); + } + } + if( substr( $format, $i, 1 ) eq 'J' ) { $res = $res . @out[6]; } + if( substr( $format, $i, 1 ) eq 'K' ) { $res = $res . @out[9]; } + if( substr( $format, $i, 1 ) eq 'L' ) { $res = $res . @out[7]; } + if( substr( $format, $i, 1 ) eq 'M' ) { $res = $res . @out[8]; } + if( substr( $format, $i, 1 ) eq 'N' ) { $res = $res . @out[10]; } + if( substr( $format, $i, 1 ) eq 'S' ) { $res = $res . @out[0]; } + if( substr( $format, $i, 1 ) eq 'T' ) { $res = $res . @out[2]; } + if( substr( $format, $i, 1 ) eq 'U' ) { $res = $res . @out[4]; } + if( substr( $format, $i, 1 ) eq 'Y' ) { $res = $res . @out[11]; } + if( substr( $format, $i, 1 ) eq 'Z' ) { $res = $res . @out[12]; } + } else { + $res = $res . substr( $format, $i, 1 ); + } + $i++; + } + return $res; +} + +sub moc { + my $out; + my $outType = weechat::get_plugin_config( "outputType" ); + if( length( $outType ) == 0 ) { $outType = 'i'; } + if( length( $_[1] ) ) { $outType = $_[1]; } + if( ( $outType ne 'i' ) && ( $outType ne 'o' ) && ( $outType ne 'ot' ) ) { + weechat::print( "Bad parameter or default output type" ); + } + $out = info(); + if( $outType eq 'i' ) { weechat::print( $out ); } + if( $outType eq 'o' ) { weechat::command( $out ); } + if( $outType eq 'ot' ) { weechat::command( "/me " . $out ); } + return weechat::PLUGIN_RC_OK; +} + +sub mocSetFormat { + if( length( $_[1] ) ) { + weechat::set_plugin_config( "outputFormat", $_[1] ); + } else { + my $format = weechat::get_plugin_config( "outputFormat" ); + if( length( $format ) == 0 ) { $format = "is listening to %T ::: %H"; } + weechat::print( "Current format is \"$format\"" ); + } + return weechat::PLUGIN_RC_OK; +} + +sub mocSetOutput { + if( length( $_[1] ) ) { + if( ( $_[1] eq 'i' ) || ( $_[1] eq 'o' ) || ( $_[1] eq 'ot' ) ) { + weechat::set_plugin_config( "outputType", $_[1] ); + } else { + weechat::print( "moc_set_command: bad parameter" ); + } + } else { + my $out = weechat::get_plugin_config( "outputType" ); + if( length( $out ) == 0 ) { $out = 'i'; } + weechat::print( "Default output: $out" ); + } + return weechat::PLUGIN_RC_OK; +} + diff --git a/scripts/perl/sound.pl b/scripts/perl/sound.pl new file mode 100644 index 000000000..f6d04d693 --- /dev/null +++ b/scripts/perl/sound.pl @@ -0,0 +1,95 @@ +# +# Copyright (c) 2006 by FlashCode <flashcode@flashtux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# + +# +# Play a sound when highlighted/private msg, or for ctcp sound event. +# +# History: +# +# 2006-05-30, FlashCode <flashcode@flashtux.org>: +# added plugin options for commands +# 2004-10-01, FlashCode <flashcode@flashtux.org>: +# initial release +# + +use strict; + +my $version = "0.3"; +my $command_suffix = " >/dev/null 2>&1 &"; + +# default values in setup file (~/.weechat/plugins.rc) +my $default_cmd_highlight = "alsaplay -i text ~/sound_highlight.wav"; +my $default_cmd_pv = "alsaplay -i text ~/sound_pv.wav"; +my $default_cmd_ctcp = "alsaplay -i text \$filename"; + +weechat::register("Sound", $version, "", "Sound for highlights/privates & CTCP sound events"); +weechat::set_plugin_config("cmd_highlight", $default_cmd_highlight) if (weechat::get_plugin_config("cmd_highlight") eq ""); +weechat::set_plugin_config("cmd_pv", $default_cmd_pv) if (weechat::get_plugin_config("cmd_pv") eq ""); +weechat::set_plugin_config("cmd_ctcp", $default_cmd_ctcp) if (weechat::get_plugin_config("cmd_ctcp") eq ""); + +weechat::add_message_handler("PRIVMSG", "sound"); +weechat::add_message_handler("weechat_highlight", "highlight"); +weechat::add_message_handler("weechat_pv", "pv"); +weechat::add_command_handler("sound", "sound_cmd"); + +sub sound +{ + my $server = $_[0]; + if ($_[1] =~ /(.*) PRIVMSG (.*)/) + { + my ($host, $msg) = ($1, $2); + if ($host ne "localhost") + { + if ($msg =~ /\001SOUND ([^ ]*)\001/) + { + my $filename = $1; + my $command = weechat::get_plugin_config("cmd_ctcp"); + $command =~ s/(\$\w+)/$1/gee; + system($command.$command_suffix); + } + } + } + return weechat::PLUGIN_RC_OK; +} + +sub highlight +{ + my $command = weechat::get_plugin_config("cmd_highlight"); + system($command.$command_suffix); + return weechat::PLUGIN_RC_OK; +} + +sub pv +{ + my $command = weechat::get_plugin_config("cmd_pv"); + system($command.$command_suffix); + return weechat::PLUGIN_RC_OK; +} + +sub sound_cmd +{ + if ($#_ == 1) + { + my $filename = $_[1].".wav"; + my $command = weechat::get_plugin_config("cmd_ctcp"); + $command =~ s/(\$\w+)/$1/gee; + system($command.$command_suffix); + weechat::command("/quote PRIVMSG ".weechat::get_info("channel")." :\001SOUND $filename\001") if (@_); + } + return weechat::PLUGIN_RC_OK; +} diff --git a/scripts/perl/translate.pl b/scripts/perl/translate.pl new file mode 100644 index 000000000..fa5723225 --- /dev/null +++ b/scripts/perl/translate.pl @@ -0,0 +1,128 @@ +# +# Copyright (c) 2006 by FlashCode <flashcode@flashtux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# + +# +# Translate words and display result in infobar, local buffer or channel +# +# History: +# 2006-07-03, FlashCode <flashcode@flashtux.org>: +# initial release +# + +use strict; + +# default values in setup file (~/.weechat/plugins.rc) +my $default_output_infobar = "on"; +my $default_timeout = "2"; + +# script internal settings +my $languages = "de|el|en|es|fr|it|ja|ko|nl|pt|ru|zh|zt"; + +# init script +weechat::register("translate", "0.1", "", "Translation script"); +weechat::set_plugin_config("output_infobar", $default_output_infobar) if (weechat::get_plugin_config("output_infobar") eq ""); +weechat::set_plugin_config("timeout", $default_timeout) if (weechat::get_plugin_config("timeout") eq ""); + +# add command handlers for all languages +weechat::add_command_handler("translate", "translate", "translate text to other language", + "lang1 lang2 text [-o]", + "lang1: base language\n" + ."lang2: target language\n" + ." text: text to translate\n" + ." -o: result is written on channel (visible by all)", + $languages." ".$languages); + +# translate text with babelfish (altavista) +sub babelfish +{ + my $timeout = weechat::get_plugin_config("timeout"); + $timeout = $default_timeout if ($timeout eq ""); + + if (`wget -q --timeout=$timeout --user-agent "Mozilla" --output-document=- "http://babelfish.altavista.com/babelfish/tr?lp=$_[0]_$_[1]&urltext=$_[2]"` =~ /.*<td bgcolor=white class=s><div style=padding:10px;>(.*)<\/div><\/td>/) + { + return $1; + } + return ""; +} + +# translate output +sub translate_output +{ + if ($_[1] == 1) + { + if (substr($_[0],0,1) eq "/") + { + weechat::command("/".$_[0], "", ""); + } + else + { + weechat::command($_[0], "", ""); + } + } + else + { + my $output_infobar = weechat::get_plugin_config("output_infobar"); + $output_infobar = $default_output_infobar if ($output_infobar eq ""); + if ($output_infobar eq "on") + { + weechat::print_infobar(5, $_[0]); + } + else + { + weechat::print($_[0], "", ""); + } + } +} + +# /translate command +sub translate +{ + my $server = shift; + my $args = shift; + + if ($args =~ /([a-zA-Z][a-zA-Z]) ([a-zA-Z][a-zA-Z]) (.*)/) + { + my $lang1 = $1; + my $lang2 = $2; + my $text = $3; + + # output on channel? + my $output_chan = 0; + if ($text =~ /(.*) -[oO]$/) + { + $output_chan = 1; + $text = $1; + } + + my $result = babelfish($lang1, $lang2, $text); + if ($result eq "") + { + translate_output("Error: unable to translate (bad language or timeout)", 0); + } + else + { + translate_output($result, $output_chan); + } + } + else + { + translate_output("Error: bad arguments", 0); + } + + return weechat::PLUGIN_RC_OK; +} diff --git a/scripts/perl/xmms.pl b/scripts/perl/xmms.pl new file mode 100644 index 000000000..92e89fd66 --- /dev/null +++ b/scripts/perl/xmms.pl @@ -0,0 +1,64 @@ +##################################################################### +# xmms perl script for weechat # +# # +# Displays some useless xmms-infopipe values # +# (c) 2006 by Cédric Chalier <llinkz@gmail.com> # +# # +# This program is free software; you can redistribute it and/or # +# modify it under the terms of the GNU General Public License # +# as published by the Free Software Foundation; either version 2 # +# of the License, or (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program; if not, write to the Free Software # +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # +# MA 02110-1301, USA. # +# # +##################################################################### +# db[x] variables are: # +# ----------------------------------------------------------- # +# | 0 | XMMS protocol version | 7 | uSecTime # +# | 1 | InfoPipe Plugin version | 8 | Time # +# | 2 | Status | 9 | Current bitrate # +# | 3 | Tunes in playlist | 10 | Samping Frequency # +# | 4 | Currently playing | 11 | Channels # +# | 5 | uSecPosition | 12 | Title # +# | 6 | Position | 13 | File # +# # +##################################################################### + +weechat::register ("xmms", "1.1", "", "xmms info script (usage: /xmms)"); +weechat::add_command_handler ("xmms", xmmsinfo); + +sub xmmsinfo { + if (! -e "/tmp/xmms-info") + {} + else + { + open (fi, "/tmp/xmms-info"); + @db2 = <fi>; + foreach $l (0 .. 14) + { + ($c,$tmp) = split(": " ,$db2[$l]); + chomp($tmp); + push @db,$tmp; + } + } + if (($db[7]!=-1) && ($db[7]!=0)) + { + weechat::command("/me np: $db[12]"); + } + else + { + weechat::command("/me np: $db[12] ($db[13])"); + } + @db = (); + @db2 = (); + close (fi); +} +# $id: xmms-weechat.pl,v 1.1 2006/05/23 00:50:10 linkz Exp $ |