-
Notifications
You must be signed in to change notification settings - Fork 2
/
csfd.pl
56 lines (44 loc) · 1.38 KB
/
csfd.pl
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
use strict;
use warnings;
use Irssi;
use Irssi::Irc;
use pQuery;
use URI::Escape;
use Text::Iconv;
use vars qw($VERSION %IRSSI);
$VERSION = '0.01';
%IRSSI = (
authors => "Petr Vavrin",
contact => "pb.pb\@centrum.cz",
name => "csfd",
description => "description",
);
sub on_public {
my ( $server, $message, $nick, $hostmask, $channel ) = @_;
my $cp = Irssi::settings_get_str ( 'bot_cmd_prefix' );
my $isprivate = !defined $channel;
my $dst = $isprivate ? $nick : $channel;
return unless $message =~ /^${cp}csfd\s+(.*)$/;
my ( $searchString ) = ( $1 );
my $answer = "";
pQuery ( "http://www.csfd.cz/hledat/?q=" . uri_escape ( $searchString ) )
->find ( "#search-films li" )
->each ( sub {
my $item = pQuery ( $_ );
my $movieTitle = $item->find ( "h3" )->text;
my $movieDescr = $item->find ( "p:eq(0)" )->text;
if ( $movieTitle !~ /^\s*$/ ){
if ( $answer ne "" ){
$answer .= ", ";
}
$answer .= $movieTitle . " [" . $movieDescr . "]";
}
});
# my $converter = Text::Iconv->new ( "utf-8", "windows-1250" );
# my $answerEncoded = $converter->convert ( $answer );
# $server->send_message ( $dst, $nick . ": " . $answerEncoded, 0 );
$server->send_message ( $dst, $nick . ": " . $answer, 0 );
}
Irssi::signal_add('message public', 'on_public');
Irssi::signal_add('message private', 'on_public');
Irssi::settings_add_str('bot', 'bot_cmd_prefix', '!');