Mercurial > ~darius > hgwebdir.cgi > scrape-gm
annotate findplayer.pl @ 13:e8550290e512
Update parser for new format.
author | darius@Inchoate |
---|---|
date | Sun, 14 Dec 2008 18:48:15 +1030 |
parents | 22a51e8c0a69 |
children |
rev | line source |
---|---|
4 | 1 ############################################################################ |
2 # Run the game-monitor script when triggered | |
3 # | |
9 | 4 # $Id$ |
4 | 5 ############################################################################ |
6 # | |
7 # Copyright (C) 2007 Daniel O'Connor. All rights reserved. | |
8 # | |
9 # Redistribution and use in source and binary forms, with or without | |
10 # modification, are permitted provided that the following conditions | |
11 # are met: | |
12 # 1. Redistributions of source code must retain the above copyright | |
13 # notice, this list of conditions and the following disclaimer. | |
14 # 2. Redistributions in binary form must reproduce the above copyright | |
15 # notice, this list of conditions and the following disclaimer in the | |
16 # documentation and/or other materials provided with the distribution. | |
17 # | |
18 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
21 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE | |
22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
24 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
25 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
27 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
28 # SUCH DAMAGE. | |
29 # | |
30 ############################################################################ | |
31 | |
32 use strict; | |
33 use vars qw($VERSION %IRSSI); | |
34 | |
35 use Irssi; | |
36 | |
37 $VERSION = '1.00'; | |
38 %IRSSI = ( | |
39 authors => 'Darius', | |
40 contact => 'darius\@dons.net.au', | |
41 name => 'findplayer', | |
42 description => 'Looks for players on game-monitor', | |
43 license => 'BSD', | |
44 ); | |
45 | |
46 my $lastran = 0; | |
47 | |
48 sub event_privmsg { | |
49 # $data = "nick/#channel :text" | |
50 my ($server, $data, $nick, $address) = @_; | |
51 my ($target, $text) = split(/ :/, $data, 2); | |
52 | |
9 | 53 #print CLIENTCRAP "target = \"$target\""; |
11
22a51e8c0a69
Update copyright date. Remove CVS ID.
darius@inchoate.localdomain
parents:
9
diff
changeset
|
54 if (lc($target) ne "#teabf" && lc($target) ne "#tea" && lc($target) ne "darius") { |
4 | 55 return; |
56 } | |
57 #print CLIENTCRAP "target = \"$target\""; | |
58 | |
59 # Remove colours, bold etc (taken from cleanpublic.pl) | |
60 $text =~ s/\x03\d?\d?(,\d?\d?)?|\x02|\x1f|\x16|\x06|\x07//g; | |
61 #print CLIENTCRAP "text is $text"; | |
62 | |
9 | 63 if ($text =~ /^!fp *(.*)/) { |
4 | 64 if ($lastran + Irssi::settings_get_int('fp_mininter') > time()) { |
65 print CLIENTCRAP "ignoring command from $nick"; | |
66 return; | |
67 } | |
68 $lastran = time(); | |
69 | |
70 my $string = $1; | |
9 | 71 $string =~ s/[^0-9a-zA-Z .,\[\]]//g; |
72 #print CLIENTCRAP "Target found - $string"; | |
73 if ($string eq "") { | |
74 $string = "[TEA]"; | |
75 #print CLIENTCRAP "No target, using [TEA]"; | |
76 } | |
4 | 77 $server->command("msg $target Looking for \"$string\" on game-monitor.com..."); |
78 open (SCR, "-|", "/home/doconnor/bin/scrape-gm.py", $string); | |
11
22a51e8c0a69
Update copyright date. Remove CVS ID.
darius@inchoate.localdomain
parents:
9
diff
changeset
|
79 my $i = 0; |
4 | 80 while (<SCR>) { |
81 chomp; | |
82 $server->command("msg $target $_"); | |
11
22a51e8c0a69
Update copyright date. Remove CVS ID.
darius@inchoate.localdomain
parents:
9
diff
changeset
|
83 $i++; |
22a51e8c0a69
Update copyright date. Remove CVS ID.
darius@inchoate.localdomain
parents:
9
diff
changeset
|
84 if ($i > Irssi::settings_get_int('fp_maxlen')) { |
22a51e8c0a69
Update copyright date. Remove CVS ID.
darius@inchoate.localdomain
parents:
9
diff
changeset
|
85 $server->command("msg $target Too many results, truncating"); |
4 | 86 } |
87 close SCR; | |
88 } | |
89 } | |
90 | |
91 Irssi::signal_add("event privmsg", "event_privmsg"); | |
92 Irssi::settings_add_int('misc', 'fp_mininter', 10); | |
11
22a51e8c0a69
Update copyright date. Remove CVS ID.
darius@inchoate.localdomain
parents:
9
diff
changeset
|
93 Irssi::settings_add_int('misc', 'fp_maxlen', 10); |
4 | 94 |
95 print CLIENTCRAP "findplayer loaded"; | |
96 1; | |
97 | |
98 #;;; Local Variables: *** | |
99 #;;; mode:perl *** | |
100 #;;; End: *** | |
101 |