File: fortune.pl

package info (click to toggle)
irssi-scripts 20100512
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,420 kB
  • ctags: 2,479
  • sloc: perl: 58,204; sh: 171; makefile: 33
file content (103 lines) | stat: -rw-r--r-- 2,375 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#
#   fortune
#
#   Edited by: Ivo Marino <eim@cpan.org>
#   $Id: fortune.pl,v 1.3 2004/12/17 19:39:19 eim Exp $
#
#   Required (Debian) packages:
#
#       . fortune-mod       The fortune core binaries
#       . fortunes-min      Basic english fortune cookies
#       . fortunes-de       German fortune cookies
#       . fortunes-it       Italian fortune cookies
#
#   Usage:
#
#       Inside a channel write: /fortune <nick> [lang]
#       The optional [lang] parameter can be:
#
#           . en            English
#           . de            German
#           . it            Italian
#
#       If not defined the fortune script defaults to en.
#
#   TODO:
#
#       . Check if specified user exists.
#       . Handle direct user messaging.
#

use strict;
use vars qw($VERSION %IRSSI);

use Irssi;
$VERSION = '$Id: fortune.pl,v 1.3 2004/12/17 19:39:19 eim Exp $';
%IRSSI = (
    authors     => 'Ivo Marino',
    contact     => 'eim@cpan.rg',
    name        => 'fortune',
    description => 'Send a random fortune cookie to an user in channel.',
    license     => 'Public Domain',
);

sub fortune {

    my ($param, $server, $witem) = @_;
    my $return = 0;
    my $cookie = '';

    if ($param) {

        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`;

            } elsif ($lang eq 'it') {

                $cookie = `fortune -a italia`;

            } else {

                $cookie = `fortune.en -a fortunes literature riddles`;
            }

            $cookie =~ s/\s*\n\s*/ /g;

            if ($cookie) {

                if ($witem && ($witem->{type} eq "CHANNEL")) {

                        $witem->command('MSG ' . $witem->{name} . ' ' . $nick . ': ' . $cookie);
                }

            } else {

                Irssi::print ("No cookie.");
                $return = 1;
            }

        } else {

            Irssi::print ("Not connected to server");
            $return = 1;
        }

    } else {

        Irssi::print ("Usage: /fortune <nick> [language]");
        $return = 1;
    }

    return $return;
}

Irssi::command_bind ('fortune', \&fortune);