1#!/usr/local/bin/perl
2#
3# by Atoms
4
5use strict;
6use WWW::Shorten::TinyURL;
7use WWW::Shorten 'TinyURL';
8
9use vars qw($VERSION %IRSSI);
10
11use Irssi qw(command_bind active_win);
12$VERSION = '1.1';
13%IRSSI = (
14    authors	=> 'Atoms',
15    contact	=> 'atoms@tups.lv',
16    patch   => 'spowers@dimins.com',
17    name	=> 'tinyurl',
18    description	=> 'create a tinyurl from a long one',
19    license	=> 'GPL',
20);
21
22command_bind(
23    tinyurl => sub {
24        my ($msg, $server, $witem) = @_;
25        my $answer = tinyurl($msg);
26
27        if ($answer) {
28            print CLIENTCRAP "$answer";
29
30            if ($witem && ($witem->{type} eq 'CHANNEL' || $witem->{type} eq 'QUERY')) {
31  	            $witem->command("MSG " . $witem->{name} ." ". $answer);
32            }
33        }
34    }
35);
36
37sub tinyurl {
38    my $url = shift;
39
40    my $res = makeashorterlink($url);
41
42    if (defined $res) {
43        return $res;
44    } else {
45        print CLIENTCRAP "ERROR: tinyurl: tinyurl is down or not pingable";
46        return "";
47    }
48}
49