summaryrefslogtreecommitdiffstats
path: root/scripts/sana.pl
blob: 27737bfdf97c7bb8b6168f1b9fa5fd4daa93881b (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# CopyLeft Riku Voipio 2001
# Mofile Bot
use Irssi;
use Irssi::Irc;

use vars qw($VERSION %IRSSI);

$VERSION = "1.0";
%IRSSI = (
        authors     => "Riku Voipio",
        contact     => "riku.voipio\@iki.fi",
        name        => "sana",
        description => "responds to \"!sana test\" command on channels/publics with a finnish/english translatioin given as parameter",
        license     => "GPLv2",
        url         => "http://nchip.ukkosenjyly.mine.nu/irssiscripts/",
    );



sub cmd_sana_priv {
        my ($server, $data, $nick, $mask ) =@_;
	return cmd_sana($server, $data, "", $mask, $nick);
}
sub cmd_sana {
        my ($server, $data, $nick, $mask, $target) =@_;
	if ($data=~/^!sana/){
		@foo=split(/\s+/,$data);
		$len=@foo;
		if ($len==1){
		    $foo[1]="aloittelija";
		}
		# Haxxor protection
		$word=$foo[1];
		$_=$word;
		$word=~s/[^a-zA-Z����]//g;	
		open(DAT, "lynx --dump http://212.213.217.194/cgi-bin/mofind.exe/dr1?word=".$word."|");
		$count=0;
		$sucks=0;
		$result="";
		foreach $line (<DAT>)
		{
			if ($line=~/\(.*\)/)
			{
				$_=$line;
				$line=~s/\s+/ /g;
				$_=$line;
				$line=~s/( $|^ )//g;
				$result.=$line.",";
			}
		}
		if (length($result)<2)
		{
 			$result="Ei l�ydy..";
		}
		 
		chop($result);
		$server->command("/notice ".$target." ".$result);
		close(DAT);
	}
}

Irssi::signal_add_last('message public', 'cmd_sana');
Irssi::signal_add_last('message private', 'cmd_sana_priv');
Irssi::print("Sanakirja info bot by nchip loaded.");