-
Notifications
You must be signed in to change notification settings - Fork 2
/
taihu.rb
44 lines (39 loc) · 1023 Bytes
/
taihu.rb
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
require 'net/http'
require 'rubygems'
require 'hpricot'
require 'uri'
class Taihu < Citrus::Plugin
def description
<<-DESCRIPTION.gsub(/^\s+/, '')
DESCRIPTION
end
def initialize(*args)
super
@prefix = @config['prefix'] || '(台風|たいふう)どうなった'
@number = @config['number'] || 3
@limit = @config['limit'] || 10
end
def on_privmsg(prefix, channel, message)
return if !@config["channels"].nil? && !@config["channels"].include?(channel)
case message
when /
^
#{@prefix}
/x
result = search
result.each { |line| notice(channel, line) }
end
end
private
def search ()
result = Array.new
html = Hpricot(open("http://typhoon.yahoo.co.jp/weather/jp/typhoon/typhb.html"))
html.search("tr") { |tr|
if /^(台風\d).+[^号]$/ =~ tr.innerText.strip.toutf8
result << tr.innerText.strip.toutf8[0..250]
end
}
result << "http://disaster.yahoo.co.jp/weather/1249345464/typhoon.yahoo.co.jp/weather/jp/typhoon/typha.jpg"
result
end
end