summaryrefslogtreecommitdiffstats
path: root/scripts/tinyurl.pl
blob: 30e4b5bab6281f9c7591c651d2e257c78010e1e3 (plain)
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
#
# by Atoms

use strict;
use WWW::Shorten::TinyURL;
use WWW::Shorten 'TinyURL';

use vars qw($VERSION %IRSSI);

use Irssi qw(command_bind active_win);
$VERSION = '1.1';
%IRSSI = (
    authors	=> 'Atoms',
    contact	=> 'atoms@tups.lv',
    patch   => 'spowers@dimins.com',
    name	=> 'tinyurl',
    description	=> 'create a tinyurl from a long one',
    license	=> 'GPL',
);

command_bind(
    tinyurl => sub {
        my ($msg, $server, $witem) = @_;
        my $answer = tinyurl($msg);
        
        if ($answer) {
            print CLIENTCRAP "$answer";

            if ($witem && ($witem->{type} eq 'CHANNEL' || $witem->{type} eq 'QUERY')) {
  	            $witem->command("MSG " . $witem->{name} ." ". $answer);
            }
        }
    }
);

sub tinyurl {
    my $url = shift;

    my $res = makeashorterlink($url);

    if (defined $res) {
        return $res;
    } else {
        print CLIENTCRAP "ERROR: tinyurl: tinyurl is down or not pingable";
        return "";
    }
}