From: bw1 Date: Thu, 30 May 2019 20:59:25 +0000 (+0200) Subject: [fortune] change the interface X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=4a046ff04deeead7b74a91176cb3646d6ec65dbd;p=irssi-scripts.irssi.org.git [fortune] change the interface --- diff --git a/scripts/fortune.pl b/scripts/fortune.pl index be2e92e..cb57da9 100644 --- a/scripts/fortune.pl +++ b/scripts/fortune.pl @@ -1,27 +1,37 @@ # # fortune # -# Edited by: Ivo Marino -# $Id: fortune.pl,v 1.3 2004/12/17 19:39:19 eim Exp $ +# Edited by: +# Ivo Marino 1.3 2004/12/17 +# bw1 1.4 2019/05/30 # # Required (Debian) packages: # # . fortune-mod The fortune core binaries # . fortunes-min Basic english fortune cookies +# +# Optional (Debian) packages: +# # . fortunes-de German fortune cookies # . fortunes-it Italian fortune cookies # # Usage: # -# Inside a channel write: /fortune [lang] -# The optional [lang] parameter can be: +# Inside Irssi write: /fortune [nick] [-h] [-o options] +# The optional [options] parameter can be: # # . en English # . de German # . it Italian +# or anything else what the fortune command provide # # If not defined the fortune script defaults to en. # +# Settings: +# +# fortune_command +# fortune_default_args +# # TODO: # # . Check if specified user exists. @@ -32,7 +42,8 @@ use strict; use vars qw($VERSION %IRSSI); use Irssi; -($VERSION) = '$Id: fortune.pl,v 1.3 2004/12/17 19:39:19 eim Exp $' =~ / (\d+\.\d+) /; +use Getopt::Long qw/GetOptionsFromString/; +$VERSION = '1.4'; %IRSSI = ( authors => 'Ivo Marino', contact => 'eim@cpan.rg', @@ -41,42 +52,43 @@ use Irssi; license => 'Public Domain', ); +my ($nargs, $help); +my %opts = ( + 'h' => \$help, + 'o=s' => \$nargs, +); + sub fortune { my ($param, $server, $witem) = @_; my $return = 0; my $cookie = ''; + my $cmd = Irssi::settings_get_str($IRSSI{name}.'_command'); + my $args = Irssi::settings_get_str($IRSSI{name}.'_default_args'); + my ($ret, $arg)= GetOptionsFromString($param, %opts) or $help=1; + my $nick = $arg->[0]; - if ($param) { + if (!defined $help) { if ($server || $server->{connected}) { - (my $nick, my $lang) = split (' ', $param); - - $lang = 'en' unless ($lang eq 'de'|| $lang eq 'it' || $lang eq 'en'); - - Irssi::print ("Nick: " . $nick . ", Lang: \"" . $lang . "\""); - - if ($lang eq 'de') { - - $cookie = `fortune -x`; + #Irssi::print ("Nick: " . $nick . ", Lang: \"" . $lang . "\""); - } elsif ($lang eq 'it') { - - $cookie = `fortune -a italia`; - - } else { - - $cookie = `fortune.en -a fortunes literature riddles`; - } + $args = $nargs if (defined $nargs); + $cookie = `$cmd $args`; $cookie =~ s/\s*\n\s*/ /g; if ($cookie) { if ($witem && ($witem->{type} eq "CHANNEL")) { - + if (defined $nick) { $witem->command('MSG ' . $witem->{name} . ' ' . $nick . ': ' . $cookie); + } else { + $witem->command('MSG ' . $witem->{name} .' '. $cookie); + } + } else { + Irssi::print ($cookie); } } else { @@ -93,11 +105,20 @@ sub fortune { } else { - Irssi::print ("Usage: /fortune [language]"); + Irssi::print ("Usage: /fortune [nick] [-h] [-o options]"); $return = 1; } + $nick = undef; + $nargs= undef; + $help = undef; + return $return; } +Irssi::settings_add_str($IRSSI{name}, $IRSSI{name}.'_command', 'fortune'); +Irssi::settings_add_str($IRSSI{name}, $IRSSI{name}.'_default_args', ''); + Irssi::command_bind ('fortune', \&fortune); + +# vim:set expandtab sw=4 ts=4: