rbot 0.9.9 → 0.9.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/AUTHORS +8 -0
- data/ChangeLog +51 -0
- data/INSTALL +4 -0
- data/README +1 -0
- data/REQUIREMENTS +11 -0
- data/TODO +2 -0
- data/bin/rbot +21 -2
- data/data/rbot/languages/german.lang +4 -1
- data/data/rbot/languages/russian.lang +75 -0
- data/data/rbot/plugins/autoop.rb +42 -51
- data/data/rbot/plugins/bans.rb +205 -0
- data/data/rbot/plugins/bash.rb +56 -0
- data/data/rbot/plugins/chucknorris.rb +74 -0
- data/data/rbot/plugins/chucknorris.yml.gz +0 -0
- data/data/rbot/plugins/deepthoughts.rb +95 -0
- data/data/rbot/plugins/demauro.rb +95 -0
- data/data/rbot/plugins/digg.rb +51 -0
- data/data/rbot/plugins/figlet.rb +24 -0
- data/data/rbot/plugins/forecast.rb +133 -0
- data/data/rbot/plugins/freshmeat.rb +13 -7
- data/data/rbot/plugins/google.rb +2 -0
- data/data/rbot/plugins/grouphug.rb +36 -0
- data/data/rbot/plugins/imdb.rb +92 -0
- data/data/rbot/plugins/insult.rb +8 -1
- data/data/rbot/plugins/iplookup.rb +227 -0
- data/data/rbot/plugins/karma.rb +2 -2
- data/data/rbot/plugins/keywords.rb +470 -0
- data/data/rbot/plugins/lart.rb +132 -146
- data/data/rbot/plugins/lastfm.rb +25 -0
- data/data/rbot/plugins/markov.rb +204 -0
- data/data/rbot/plugins/math.rb +5 -1
- data/data/rbot/plugins/nickserv.rb +71 -11
- data/data/rbot/plugins/opme.rb +19 -19
- data/data/rbot/plugins/quakeauth.rb +2 -2
- data/data/rbot/plugins/quotes.rb +40 -25
- data/data/rbot/plugins/remind.rb +1 -1
- data/data/rbot/plugins/rot13.rb +2 -2
- data/data/rbot/plugins/roulette.rb +49 -15
- data/data/rbot/plugins/rss.rb +585 -0
- data/data/rbot/plugins/rubyurl.rb +39 -0
- data/data/rbot/plugins/seen.rb +2 -1
- data/data/rbot/plugins/slashdot.rb +5 -5
- data/data/rbot/plugins/spell.rb +5 -0
- data/data/rbot/plugins/theyfightcrime.rb +121 -0
- data/data/rbot/plugins/threat.rb +55 -0
- data/data/rbot/plugins/tinyurl.rb +39 -0
- data/data/rbot/plugins/topic.rb +204 -0
- data/data/rbot/plugins/urban.rb +71 -0
- data/data/rbot/plugins/url.rb +399 -4
- data/data/rbot/plugins/wow.rb +123 -0
- data/data/rbot/plugins/wserver.rb +1 -1
- data/data/rbot/templates/levels.rbot +2 -0
- data/lib/rbot/auth.rb +207 -96
- data/lib/rbot/channel.rb +5 -5
- data/lib/rbot/config.rb +125 -24
- data/lib/rbot/dbhash.rb +87 -21
- data/lib/rbot/httputil.rb +181 -13
- data/lib/rbot/ircbot.rb +525 -179
- data/lib/rbot/ircsocket.rb +330 -54
- data/lib/rbot/message.rb +66 -23
- data/lib/rbot/messagemapper.rb +25 -17
- data/lib/rbot/plugins.rb +244 -115
- data/lib/rbot/post-clean.rb +1 -0
- data/lib/rbot/{post-install.rb → post-config.rb} +1 -1
- data/lib/rbot/rbotconfig.rb +29 -14
- data/lib/rbot/registry.rb +111 -72
- data/lib/rbot/rfc2812.rb +208 -197
- data/lib/rbot/timer.rb +4 -0
- data/lib/rbot/utils.rb +2 -2
- metadata +127 -104
- data/data/rbot/plugins/rss.rb.disabled +0 -414
- data/lib/rbot/keywords.rb +0 -433
data/lib/rbot/timer.rb
CHANGED
@@ -78,6 +78,7 @@ module Timer
|
|
78
78
|
#
|
79
79
|
# add an action to the timer
|
80
80
|
def add(period, data=nil, &func)
|
81
|
+
debug "adding timer, period #{period}"
|
81
82
|
@handle += 1
|
82
83
|
@timers[@handle] = Action.new(period, data, &func)
|
83
84
|
start_on_add
|
@@ -90,6 +91,7 @@ module Timer
|
|
90
91
|
#
|
91
92
|
# add an action to the timer which will be run just once, after +period+
|
92
93
|
def add_once(period, data=nil, &func)
|
94
|
+
debug "adding one-off timer, period #{period}"
|
93
95
|
@handle += 1
|
94
96
|
@timers[@handle] = Action.new(period, data, true, &func)
|
95
97
|
start_on_add
|
@@ -135,6 +137,8 @@ module Timer
|
|
135
137
|
@next_action_time = timer.in
|
136
138
|
end
|
137
139
|
}
|
140
|
+
#debug "ticked. now #{@timers.length} timers remain"
|
141
|
+
#debug "next timer due at #{@next_action_time}"
|
138
142
|
end
|
139
143
|
|
140
144
|
# for backwards compat - this is a bit primitive
|
data/lib/rbot/utils.rb
CHANGED
@@ -33,7 +33,7 @@ module Irc
|
|
33
33
|
$stderr = $stdout
|
34
34
|
exec(command, *args)
|
35
35
|
rescue Exception => e
|
36
|
-
puts "exec of #{command} led to exception: #{e}"
|
36
|
+
puts "exec of #{command} led to exception: #{e.inspect}"
|
37
37
|
Kernel::exit! 0
|
38
38
|
end
|
39
39
|
puts "exec of #{command} failed"
|
@@ -75,7 +75,7 @@ module Irc
|
|
75
75
|
}
|
76
76
|
rescue => e
|
77
77
|
# cheesy for now
|
78
|
-
|
78
|
+
error "Utils.http_get exception: #{e.inspect}, while trying to get #{uristr}"
|
79
79
|
return nil
|
80
80
|
end
|
81
81
|
end
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.8.
|
2
|
+
rubygems_version: 0.8.1
|
3
3
|
specification_version: 1
|
4
4
|
name: rbot
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.9.
|
7
|
-
date:
|
6
|
+
version: 0.9.10
|
7
|
+
date: 2006-08-06
|
8
8
|
summary: A modular ruby IRC bot.
|
9
9
|
require_paths:
|
10
|
-
|
10
|
+
- lib
|
11
|
+
author: Tom Gilbert
|
11
12
|
email: tom@linuxbrit.co.uk
|
12
13
|
homepage: http://linuxbrit.co.uk/rbot/
|
13
14
|
rubyforge_project: rbot
|
@@ -18,112 +19,134 @@ bindir: bin
|
|
18
19
|
has_rdoc: true
|
19
20
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
21
|
requirements:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
version: 0.0.0
|
22
|
+
- - ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
25
|
version:
|
26
26
|
platform: ruby
|
27
|
-
signing_key:
|
28
|
-
cert_chain:
|
29
|
-
authors:
|
30
|
-
- Tom Gilbert
|
31
27
|
files:
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
28
|
+
- lib/rbot/plugins.rb
|
29
|
+
- lib/rbot/post-clean.rb
|
30
|
+
- lib/rbot/channel.rb
|
31
|
+
- lib/rbot/ircsocket.rb
|
32
|
+
- lib/rbot/messagemapper.rb
|
33
|
+
- lib/rbot/language.rb
|
34
|
+
- lib/rbot/ircbot.rb
|
35
|
+
- lib/rbot/post-config.rb
|
36
|
+
- lib/rbot/timer.rb
|
37
|
+
- lib/rbot/rfc2812.rb
|
38
|
+
- lib/rbot/dbhash.rb
|
39
|
+
- lib/rbot/utils.rb
|
40
|
+
- lib/rbot/httputil.rb
|
41
|
+
- lib/rbot/registry.rb
|
42
|
+
- lib/rbot/message.rb
|
43
|
+
- lib/rbot/rbotconfig.rb
|
44
|
+
- lib/rbot/config.rb
|
45
|
+
- lib/rbot/auth.rb
|
46
|
+
- bin/rbot
|
47
|
+
- data/rbot
|
48
|
+
- data/rbot/plugins
|
49
|
+
- data/rbot/templates
|
50
|
+
- data/rbot/languages
|
51
|
+
- data/rbot/contrib
|
52
|
+
- data/rbot/plugins/wow.rb
|
53
|
+
- data/rbot/plugins/bans.rb
|
54
|
+
- data/rbot/plugins/spell.rb
|
55
|
+
- data/rbot/plugins/rubyurl.rb
|
56
|
+
- data/rbot/plugins/tinyurl.rb
|
57
|
+
- data/rbot/plugins/chucknorris.yml.gz
|
58
|
+
- data/rbot/plugins/tube.rb
|
59
|
+
- data/rbot/plugins/excuse.rb
|
60
|
+
- data/rbot/plugins/bash.rb
|
61
|
+
- data/rbot/plugins/lart.rb
|
62
|
+
- data/rbot/plugins/remind.rb
|
63
|
+
- data/rbot/plugins/fortune.rb
|
64
|
+
- data/rbot/plugins/roulette.rb
|
65
|
+
- data/rbot/plugins/lastfm.rb
|
66
|
+
- data/rbot/plugins/demauro.rb
|
67
|
+
- data/rbot/plugins/httpd.rb.disabled
|
68
|
+
- data/rbot/plugins/opme.rb
|
69
|
+
- data/rbot/plugins/freshmeat.rb
|
70
|
+
- data/rbot/plugins/google.rb
|
71
|
+
- data/rbot/plugins/figlet.rb
|
72
|
+
- data/rbot/plugins/digg.rb
|
73
|
+
- data/rbot/plugins/forecast.rb
|
74
|
+
- data/rbot/plugins/grouphug.rb
|
75
|
+
- data/rbot/plugins/chucknorris.rb
|
76
|
+
- data/rbot/plugins/wserver.rb
|
77
|
+
- data/rbot/plugins/slashdot.rb
|
78
|
+
- data/rbot/plugins/keywords.rb
|
79
|
+
- data/rbot/plugins/threat.rb
|
80
|
+
- data/rbot/plugins/weather.rb
|
81
|
+
- data/rbot/plugins/autorejoin.rb
|
82
|
+
- data/rbot/plugins/topic.rb
|
83
|
+
- data/rbot/plugins/quakeauth.rb
|
84
|
+
- data/rbot/plugins/math.rb
|
85
|
+
- data/rbot/plugins/fish.rb
|
86
|
+
- data/rbot/plugins/xmlrpc.rb.disabled
|
87
|
+
- data/rbot/plugins/theyfightcrime.rb
|
88
|
+
- data/rbot/plugins/host.rb
|
89
|
+
- data/rbot/plugins/cal.rb
|
90
|
+
- data/rbot/plugins/imdb.rb
|
91
|
+
- data/rbot/plugins/autoop.rb
|
92
|
+
- data/rbot/plugins/nslookup.rb
|
93
|
+
- data/rbot/plugins/nickserv.rb
|
94
|
+
- data/rbot/plugins/urban.rb
|
95
|
+
- data/rbot/plugins/karma.rb
|
96
|
+
- data/rbot/plugins/markov.rb
|
97
|
+
- data/rbot/plugins/insult.rb
|
98
|
+
- data/rbot/plugins/seen.rb
|
99
|
+
- data/rbot/plugins/eightball.rb
|
100
|
+
- data/rbot/plugins/rot13.rb
|
101
|
+
- data/rbot/plugins/rss.rb
|
102
|
+
- data/rbot/plugins/iplookup.rb
|
103
|
+
- data/rbot/plugins/url.rb
|
104
|
+
- data/rbot/plugins/quotes.rb
|
105
|
+
- data/rbot/plugins/roshambo.rb
|
106
|
+
- data/rbot/plugins/deepthoughts.rb
|
107
|
+
- data/rbot/plugins/dice.rb
|
108
|
+
- data/rbot/templates/lart
|
109
|
+
- data/rbot/templates/levels.rbot
|
110
|
+
- data/rbot/templates/keywords.rbot
|
111
|
+
- data/rbot/templates/users.rbot
|
112
|
+
- data/rbot/templates/lart/larts
|
113
|
+
- data/rbot/templates/lart/praises
|
114
|
+
- data/rbot/languages/german.lang
|
115
|
+
- data/rbot/languages/dutch.lang
|
116
|
+
- data/rbot/languages/russian.lang
|
117
|
+
- data/rbot/languages/french.lang
|
118
|
+
- data/rbot/languages/english.lang
|
119
|
+
- data/rbot/contrib/plugins
|
120
|
+
- data/rbot/contrib/plugins/stats.rb
|
121
|
+
- data/rbot/contrib/plugins/ri.rb
|
122
|
+
- data/rbot/contrib/plugins/figlet.rb
|
123
|
+
- data/rbot/contrib/plugins/vandale.rb
|
124
|
+
- AUTHORS
|
125
|
+
- COPYING
|
126
|
+
- README
|
127
|
+
- REQUIREMENTS
|
128
|
+
- TODO
|
129
|
+
- ChangeLog
|
130
|
+
- INSTALL
|
131
|
+
- Usage_en.txt
|
132
|
+
- setup.rb
|
114
133
|
test_files: []
|
134
|
+
|
115
135
|
rdoc_options:
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
136
|
+
- --exclude
|
137
|
+
- post-install.rb
|
138
|
+
- --title
|
139
|
+
- rbot API Documentation
|
140
|
+
- --main
|
141
|
+
- README
|
142
|
+
- README
|
123
143
|
extra_rdoc_files: []
|
144
|
+
|
124
145
|
executables:
|
125
|
-
|
146
|
+
- rbot
|
126
147
|
extensions: []
|
148
|
+
|
127
149
|
requirements:
|
128
|
-
|
129
|
-
dependencies: []
|
150
|
+
- Ruby, version 1.8.0 (or newer)
|
151
|
+
dependencies: []
|
152
|
+
|
@@ -1,414 +0,0 @@
|
|
1
|
-
# RSS feed plugin for RubyBot
|
2
|
-
# (c) 2004 Stanislav Karchebny <berkus@madfire.net>
|
3
|
-
# (c) 2005 Ian Monroe <ian@monroe.nu>
|
4
|
-
# (c) 2005 Mark Kretschmann <markey@web.de>
|
5
|
-
# Licensed under MIT License.
|
6
|
-
|
7
|
-
# TODO
|
8
|
-
# checks feeds very often - does it use HEAD to check it needs to d/l?
|
9
|
-
# some usage issues
|
10
|
-
# why can't I do this here? :
|
11
|
-
# Class String
|
12
|
-
# def foo
|
13
|
-
# foo
|
14
|
-
# end
|
15
|
-
# end
|
16
|
-
|
17
|
-
require 'rss/parser'
|
18
|
-
require 'rss/1.0'
|
19
|
-
require 'rss/2.0'
|
20
|
-
require 'rss/dublincore'
|
21
|
-
begin
|
22
|
-
require 'rss/dublincore/2.0'
|
23
|
-
rescue LoadError => e
|
24
|
-
puts "rss plugin: no dublincore 2.0 found, should be okay tho"
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
class RSSFeedsPlugin < Plugin
|
29
|
-
@@watchThreads = Hash.new
|
30
|
-
|
31
|
-
# Keep a 1:1 relation between commands and handlers
|
32
|
-
@@handlers = {
|
33
|
-
"rss" => "handle_rss",
|
34
|
-
"addrss" => "handle_addrss",
|
35
|
-
"rmrss" => "handle_rmrss",
|
36
|
-
"listrss" => "handle_listrss",
|
37
|
-
"listwatches" => "handle_listrsswatch",
|
38
|
-
"rewatch" => "handle_rewatch",
|
39
|
-
"watchrss" => "handle_watchrss",
|
40
|
-
"rmwatch" => "handle_rmwatch"
|
41
|
-
}
|
42
|
-
|
43
|
-
def name
|
44
|
-
'rss'
|
45
|
-
end
|
46
|
-
|
47
|
-
def initialize
|
48
|
-
super
|
49
|
-
@feeds = Hash.new
|
50
|
-
@watchList = Hash.new
|
51
|
-
|
52
|
-
if FileTest.exists?("#{@bot.botclass}/rss/feeds")
|
53
|
-
IO.foreach("#{@bot.botclass}/rss/feeds") { |line|
|
54
|
-
s = line.chomp.split("|", 2)
|
55
|
-
@feeds[s[0]] = s[1]
|
56
|
-
}
|
57
|
-
end
|
58
|
-
|
59
|
-
if FileTest.exists?("#{@bot.botclass}/rss/watchlist")
|
60
|
-
IO.foreach("#{@bot.botclass}/rss/watchlist") { |line|
|
61
|
-
s = line.chomp.split("|", 3)
|
62
|
-
@watchList[s[0]] = [s[1], s[2]]
|
63
|
-
watchRss( s[2], s[0], s[1] )
|
64
|
-
}
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def cleanup
|
69
|
-
kill_threads
|
70
|
-
end
|
71
|
-
|
72
|
-
def save
|
73
|
-
Dir.mkdir("#{@bot.botclass}/rss") if not FileTest.directory?("#{@bot.botclass}/rss")
|
74
|
-
File.open("#{@bot.botclass}/rss/feeds", "w") { |file|
|
75
|
-
@feeds.each { |k,v|
|
76
|
-
file.puts(k + "|" + v)
|
77
|
-
}
|
78
|
-
}
|
79
|
-
File.open("#{@bot.botclass}/rss/watchlist", "w") { |file|
|
80
|
-
@watchList.each { |url, d|
|
81
|
-
feedFormat = d[0] || ''
|
82
|
-
whichChan = d[1] || 'markey'
|
83
|
-
file.puts(url + '|' + feedFormat + '|' + whichChan)
|
84
|
-
}
|
85
|
-
}
|
86
|
-
end
|
87
|
-
|
88
|
-
def kill_threads
|
89
|
-
Thread.critical=true
|
90
|
-
# Abort all running threads.
|
91
|
-
@@watchThreads.each { |url, thread|
|
92
|
-
puts "Killing thread for #{url}"
|
93
|
-
thread.kill
|
94
|
-
}
|
95
|
-
# @@watchThreads.each { |url, thread|
|
96
|
-
# puts "Joining on killed thread for #{url}"
|
97
|
-
# thread.join
|
98
|
-
# }
|
99
|
-
@@watchThreads = Hash.new
|
100
|
-
Thread.critical=false
|
101
|
-
end
|
102
|
-
|
103
|
-
def help(plugin,topic="")
|
104
|
-
"RSS Reader: rss name [limit] => read a named feed [limit maximum posts, default 5], addrss [force] name url => add a feed, listrss => list all available feeds, rmrss name => remove the named feed, watchrss url [type] => watch a rss feed for changes (type may be 'amarokblog', 'amarokforum', 'mediawiki', 'gmame' or empty - it defines special formatting of feed items), rewatch => restart all rss watches, rmwatch url => stop watching for changes in url"
|
105
|
-
end
|
106
|
-
|
107
|
-
def privmsg(m)
|
108
|
-
meth = self.method(@@handlers[m.plugin])
|
109
|
-
meth.call(m)
|
110
|
-
end
|
111
|
-
|
112
|
-
def handle_rss(m)
|
113
|
-
unless m.params
|
114
|
-
m.reply("incorrect usage: " + help(m.plugin))
|
115
|
-
return
|
116
|
-
end
|
117
|
-
limit = 5
|
118
|
-
if m.params =~ /\s+(\d+)$/
|
119
|
-
limit = $1.to_i
|
120
|
-
if limit < 1 || limit > 15
|
121
|
-
m.reply("weird, limit not in [1..15], reverting to default")
|
122
|
-
limit = 5
|
123
|
-
end
|
124
|
-
m.params.gsub!(/\s+\d+$/, '')
|
125
|
-
end
|
126
|
-
unless @feeds.has_key?(m.params)
|
127
|
-
m.reply(m.params + "? what is that feed about?")
|
128
|
-
return
|
129
|
-
end
|
130
|
-
|
131
|
-
m.reply("Please wait, querying...")
|
132
|
-
title = ''
|
133
|
-
items = fetchRSS(m.replyto, @feeds[m.params], title)
|
134
|
-
if(items == nil)
|
135
|
-
return
|
136
|
-
end
|
137
|
-
m.reply("Channel : #{title}")
|
138
|
-
# FIXME: optional by-date sorting if dates present
|
139
|
-
items[0...limit].each do |item|
|
140
|
-
printRSSItem(m.replyto,item)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
def handle_addrss(m)
|
145
|
-
unless m.params
|
146
|
-
m.reply "incorrect usage: " + help(m.plugin)
|
147
|
-
return
|
148
|
-
end
|
149
|
-
if m.params =~ /^force /
|
150
|
-
forced = true
|
151
|
-
m.params.gsub!(/^force /, '')
|
152
|
-
end
|
153
|
-
feed = m.params.scan(/^(\S+)\s+(\S+)$/)
|
154
|
-
unless feed.length == 1 && feed[0].length == 2
|
155
|
-
m.reply("incorrect usage: " + help(m.plugin))
|
156
|
-
return
|
157
|
-
end
|
158
|
-
if @feeds.has_key?(feed[0][0]) && !forced
|
159
|
-
m.reply("But there is already a feed named #{feed[0][0]} with url #{@feeds[feed[0][0]]}")
|
160
|
-
return
|
161
|
-
end
|
162
|
-
feed[0][0].gsub!("|", '_')
|
163
|
-
@feeds[feed[0][0]] = feed[0][1]
|
164
|
-
m.reply("RSS: Added #{feed[0][1]} with name #{feed[0][0]}")
|
165
|
-
end
|
166
|
-
|
167
|
-
def handle_rmrss(m)
|
168
|
-
unless m.params
|
169
|
-
m.reply "incorrect usage: " + help(m.plugin)
|
170
|
-
return
|
171
|
-
end
|
172
|
-
unless @feeds.has_key?(m.params)
|
173
|
-
m.reply("dunno that feed")
|
174
|
-
return
|
175
|
-
end
|
176
|
-
@feeds.delete(m.params)
|
177
|
-
m.okay
|
178
|
-
end
|
179
|
-
|
180
|
-
def handle_rmwatch(m)
|
181
|
-
unless m.params
|
182
|
-
m.reply "incorrect usage: " + help(m.plugin)
|
183
|
-
return
|
184
|
-
end
|
185
|
-
unless @watchList.has_key?(m.params)
|
186
|
-
m.reply("no such watch")
|
187
|
-
return
|
188
|
-
end
|
189
|
-
unless @watchList[m.params][1] == m.replyto
|
190
|
-
m.reply("no such watch for this channel/nick")
|
191
|
-
return
|
192
|
-
end
|
193
|
-
@watchList.delete(m.params)
|
194
|
-
Thread.critical=true
|
195
|
-
if @@watchThreads[m.params].kind_of? Thread
|
196
|
-
@@watchThreads[m.params].kill
|
197
|
-
puts "rmwatch: Killed thread for #{m.params}"
|
198
|
-
# @@watchThreads[m.params].join
|
199
|
-
# puts "rmwatch: Joined killed thread for #{m.params}"
|
200
|
-
@@watchThreads.delete(m.params)
|
201
|
-
end
|
202
|
-
Thread.critical=false
|
203
|
-
m.okay
|
204
|
-
end
|
205
|
-
|
206
|
-
def handle_listrss(m)
|
207
|
-
reply = ''
|
208
|
-
if @feeds.length == 0
|
209
|
-
reply = "No feeds yet."
|
210
|
-
else
|
211
|
-
@feeds.each { |k,v|
|
212
|
-
reply << k + ": " + v + "\n"
|
213
|
-
}
|
214
|
-
end
|
215
|
-
m.reply(reply)
|
216
|
-
end
|
217
|
-
|
218
|
-
def handle_listrsswatch(m)
|
219
|
-
reply = ''
|
220
|
-
if @watchList.length == 0
|
221
|
-
reply = "No watched feeds yet."
|
222
|
-
else
|
223
|
-
@watchList.each { |url,v|
|
224
|
-
reply << url + " for " + v[1] + " (in format: " + (v[0]?v[0]:"default") + ")\n"
|
225
|
-
}
|
226
|
-
end
|
227
|
-
m.reply(reply)
|
228
|
-
end
|
229
|
-
|
230
|
-
def handle_rewatch(m)
|
231
|
-
kill_threads
|
232
|
-
|
233
|
-
# Read watches from list.
|
234
|
-
@watchList.each{ |url, d|
|
235
|
-
feedFormat = d[0]
|
236
|
-
whichChan = d[1]
|
237
|
-
watchRss(whichChan, url,feedFormat)
|
238
|
-
}
|
239
|
-
m.okay
|
240
|
-
end
|
241
|
-
|
242
|
-
def handle_watchrss(m)
|
243
|
-
unless m.params
|
244
|
-
m.reply "incorrect usage: " + help(m.plugin)
|
245
|
-
return
|
246
|
-
end
|
247
|
-
feed = m.params.scan(/^(\S+)\s+(\S+)$/)
|
248
|
-
url = feed[0][0]
|
249
|
-
feedFormat = feed[0][1]
|
250
|
-
if @watchList.has_key?(url)
|
251
|
-
m.reply("But there is already a watch for feed #{url} on chan #{@watchList[url][1]}")
|
252
|
-
return
|
253
|
-
end
|
254
|
-
@watchList[url] = [feedFormat, m.replyto]
|
255
|
-
watchRss(m.replyto, url,feedFormat)
|
256
|
-
m.okay
|
257
|
-
end
|
258
|
-
|
259
|
-
private
|
260
|
-
def watchRss(whichChan, url, feedFormat)
|
261
|
-
if @@watchThreads.has_key?(url)
|
262
|
-
@bot.say whichChan, "ERROR: watcher thread for #{url} is already running! #{@@watchThreads[url]}"
|
263
|
-
return
|
264
|
-
end
|
265
|
-
@@watchThreads[url] = Thread.new do
|
266
|
-
puts 'watchRss thread started.'
|
267
|
-
oldItems = []
|
268
|
-
firstRun = true
|
269
|
-
loop do
|
270
|
-
begin # exception
|
271
|
-
title = ''
|
272
|
-
puts 'Fetching rss feed..'
|
273
|
-
newItems = fetchRSS(whichChan, url, title)
|
274
|
-
if( newItems.empty? )
|
275
|
-
@bot.say whichChan, "Oops - Item is empty"
|
276
|
-
break
|
277
|
-
end
|
278
|
-
puts "Checking if new items are available"
|
279
|
-
if (firstRun)
|
280
|
-
firstRun = false
|
281
|
-
else
|
282
|
-
newItems.each do |nItem|
|
283
|
-
showItem = true;
|
284
|
-
oldItems.each do |oItem|
|
285
|
-
if (nItem.to_s == oItem.to_s)
|
286
|
-
showItem = false
|
287
|
-
end
|
288
|
-
end
|
289
|
-
if showItem
|
290
|
-
puts "showing #{nItem.title}"
|
291
|
-
printFormatedRSS(whichChan, nItem,feedFormat)
|
292
|
-
else
|
293
|
-
puts "not showing #{nItem.title}"
|
294
|
-
break
|
295
|
-
end
|
296
|
-
end
|
297
|
-
end
|
298
|
-
oldItems = newItems
|
299
|
-
rescue Exception
|
300
|
-
$stderr.print "IO failed: " + $! + "\n"
|
301
|
-
end
|
302
|
-
|
303
|
-
seconds = 150 + rand(100)
|
304
|
-
puts "Thread going to sleep #{seconds} seconds.."
|
305
|
-
sleep seconds
|
306
|
-
end
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
def printRSSItem(whichChan,item)
|
311
|
-
if item.kind_of?(RSS::RDF::Item)
|
312
|
-
@bot.say whichChan, shorten(riphtml(item.title.chomp), 20) + " @ " + item.link
|
313
|
-
else
|
314
|
-
@bot.say whichChan, "#{item.pubDate.to_s.chomp+": " if item.pubDate}#{shorten(riphtml(item.title.chomp), 20)+" :: " if item.title}#{" @ "+item.link.chomp if item.link}"
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
|
-
def printFormatedRSS(whichChan,item, type)
|
319
|
-
case type
|
320
|
-
when 'amarokblog'
|
321
|
-
@bot.say whichChan, "::#{item.category.content} just blogged at #{item.link}::"
|
322
|
-
@bot.say whichChan, "::#{shorten(riphtml(item.title.chomp), 20)} - #{shorten(riphtml(item.description.chomp),60)}::"
|
323
|
-
when 'amarokforum'
|
324
|
-
@bot.say whichChan, "::Forum:: #{item.pubDate.to_s.chomp+": " if item.pubDate}#{shorten(riphtml(item.title.chomp), 20)+" :: " if item.title}#{" @ "+item.link.chomp if item.link}"
|
325
|
-
when 'mediawiki'
|
326
|
-
@bot.say whichChan, "::Wiki:: #{item.title} has been edited by #{item.dc_creator}. #{shorten(riphtml(item.description.split("\n")[0].chomp),60)} #{item.link} ::"
|
327
|
-
puts "mediawiki #{item.title}"
|
328
|
-
when "gmame"
|
329
|
-
@bot.say whichChan, "::amarok-devel:: Message #{item.title} sent by #{item.dc_creator}. #{shorten(riphtml(item.description.split("\n")[0].chomp),60)}::"
|
330
|
-
else
|
331
|
-
printRSSItem(whichChan,item)
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
335
|
-
def fetchRSS(whichChan, url, title)
|
336
|
-
begin
|
337
|
-
# Use 60 sec timeout, cause the default is too low
|
338
|
-
xml = Utils.http_get(url,60,60)
|
339
|
-
rescue URI::InvalidURIError, URI::BadURIError => e
|
340
|
-
@bot.say whichChan, "invalid rss feed #{url}"
|
341
|
-
return
|
342
|
-
end
|
343
|
-
puts 'fetched'
|
344
|
-
unless xml
|
345
|
-
@bot.say whichChan, "reading feed #{url} failed"
|
346
|
-
return
|
347
|
-
end
|
348
|
-
|
349
|
-
begin
|
350
|
-
## do validate parse
|
351
|
-
rss = RSS::Parser.parse(xml)
|
352
|
-
puts 'parsed'
|
353
|
-
rescue RSS::InvalidRSSError
|
354
|
-
## do non validate parse for invalid RSS 1.0
|
355
|
-
begin
|
356
|
-
rss = RSS::Parser.parse(xml, false)
|
357
|
-
rescue RSS::Error
|
358
|
-
@bot.say whichChan, "parsing rss stream failed, whoops =("
|
359
|
-
return
|
360
|
-
end
|
361
|
-
rescue RSS::Error
|
362
|
-
@bot.say whichChan, "parsing rss stream failed, oioi"
|
363
|
-
return
|
364
|
-
rescue
|
365
|
-
@bot.say whichChan, "processing error occured, sorry =("
|
366
|
-
return
|
367
|
-
end
|
368
|
-
items = []
|
369
|
-
if rss.nil?
|
370
|
-
@bot.say whichChan, "#{m.params} does not include RSS 1.0 or 0.9x/2.0"
|
371
|
-
else
|
372
|
-
begin
|
373
|
-
rss.output_encoding = "euc-jp"
|
374
|
-
rescue RSS::UnknownConvertMethod
|
375
|
-
@bot.say whichChan, "bah! something went wrong =("
|
376
|
-
return
|
377
|
-
end
|
378
|
-
rss.channel.title ||= "Unknown"
|
379
|
-
title.replace(rss.channel.title)
|
380
|
-
rss.items.each do |item|
|
381
|
-
item.title ||= "Unknown"
|
382
|
-
items << item
|
383
|
-
end
|
384
|
-
end
|
385
|
-
|
386
|
-
if items.empty?
|
387
|
-
@bot.say whichChan, "no items found in the feed, maybe try weed?"
|
388
|
-
return
|
389
|
-
end
|
390
|
-
return items
|
391
|
-
end
|
392
|
-
|
393
|
-
def riphtml(str)
|
394
|
-
str.gsub(/<[^>]+>/, '').gsub(/&/,'&').gsub(/"/,'"').gsub(/</,'<').gsub(/>/,'>').gsub(/&ellip;/,'...').gsub(/'/, "'").gsub("\n",'')
|
395
|
-
end
|
396
|
-
|
397
|
-
def shorten(str, limit)
|
398
|
-
if str.length > limit
|
399
|
-
str+". " =~ /^(.{#{limit}}[^.!;?]*[.!;?])/mi
|
400
|
-
return $1
|
401
|
-
end
|
402
|
-
str
|
403
|
-
end
|
404
|
-
end
|
405
|
-
|
406
|
-
plugin = RSSFeedsPlugin.new
|
407
|
-
plugin.register("rss")
|
408
|
-
plugin.register("addrss")
|
409
|
-
plugin.register("rmrss")
|
410
|
-
plugin.register("listrss")
|
411
|
-
plugin.register("rewatch")
|
412
|
-
plugin.register("watchrss")
|
413
|
-
plugin.register("listwatches")
|
414
|
-
plugin.register("rmwatch")
|