nadoka 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/ChangeLog.old +1553 -0
- data/Gemfile +4 -0
- data/README.org +31 -0
- data/Rakefile +1 -0
- data/bin/nadoka +13 -0
- data/lib/rss_check.rb +206 -0
- data/lib/tagparts.rb +206 -0
- data/nadoka.gemspec +29 -0
- data/nadoka.rb +123 -0
- data/nadokarc +267 -0
- data/ndk/bot.rb +241 -0
- data/ndk/client.rb +288 -0
- data/ndk/config.rb +571 -0
- data/ndk/error.rb +61 -0
- data/ndk/logger.rb +311 -0
- data/ndk/server.rb +784 -0
- data/ndk/server_state.rb +324 -0
- data/ndk/version.rb +44 -0
- data/plugins/autoawaybot.nb +66 -0
- data/plugins/autodumpbot.nb +227 -0
- data/plugins/autoop.nb +56 -0
- data/plugins/backlogbot.nb +88 -0
- data/plugins/checkbot.nb +64 -0
- data/plugins/cronbot.nb +20 -0
- data/plugins/dictbot.nb +53 -0
- data/plugins/drbcl.rb +39 -0
- data/plugins/drbot.nb +93 -0
- data/plugins/evalbot.nb +49 -0
- data/plugins/gonzuibot.nb +41 -0
- data/plugins/googlebot.nb +345 -0
- data/plugins/identifynickserv.nb +43 -0
- data/plugins/mailcheckbot.nb +0 -0
- data/plugins/marldiabot.nb +99 -0
- data/plugins/messagebot.nb +96 -0
- data/plugins/modemanager.nb +150 -0
- data/plugins/opensearchbot.nb +156 -0
- data/plugins/opshop.nb +23 -0
- data/plugins/pastebot.nb +46 -0
- data/plugins/roulettebot.nb +33 -0
- data/plugins/rss_checkbot.nb +121 -0
- data/plugins/samplebot.nb +24 -0
- data/plugins/sendpingbot.nb +17 -0
- data/plugins/shellbot.nb +59 -0
- data/plugins/sixamobot.nb +77 -0
- data/plugins/tenkibot.nb +111 -0
- data/plugins/timestampbot.nb +62 -0
- data/plugins/titlebot.nb +226 -0
- data/plugins/translatebot.nb +301 -0
- data/plugins/twitterbot.nb +138 -0
- data/plugins/weba.nb +209 -0
- data/plugins/xibot.nb +113 -0
- data/rice/irc.rb +780 -0
- metadata +102 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
This plugin is test version.
|
4
|
+
|
5
|
+
=end
|
6
|
+
|
7
|
+
require 'shellwords'
|
8
|
+
require 'kconv'
|
9
|
+
|
10
|
+
class RouletteBot < Nadoka::NDK_Bot
|
11
|
+
def bot_initialize
|
12
|
+
@available_channel = @bot_config[:ch] || /.*/
|
13
|
+
end
|
14
|
+
|
15
|
+
def on_privmsg prefix, ch, msg
|
16
|
+
if @available_channel === ch
|
17
|
+
if /\Aroulette>\s*(.+)\s*/ =~ msg
|
18
|
+
send_notice(ch, "roulette bot: #{randomize($1)[0].tojis}")
|
19
|
+
elsif /\Ashuffle>\s*(.+)\s*/ =~ msg
|
20
|
+
send_notice(ch, "shuffle bot: #{ randomize($1).join(' ').tojis}")
|
21
|
+
elsif /\Arandom>\s*((\d+)|)/ =~ msg
|
22
|
+
num = $2 ? $2.to_i : 1000
|
23
|
+
send_notice(ch, "random bot: #{prefix.nick} -> #{rand num}")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def randomize msgs
|
29
|
+
res = Shellwords.shellwords(msgs.toeuc).sort_by{rand}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# -*-ruby-*-
|
2
|
+
#
|
3
|
+
# Copyright (c) 2004-2005 SASADA Koichi <ko1 at atdot.net>
|
4
|
+
#
|
5
|
+
# This program is free software with ABSOLUTELY NO WARRANTY.
|
6
|
+
# You can re-distribute and/or modify this program under
|
7
|
+
# the same terms of the Ruby's license.
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# $Id$
|
11
|
+
#
|
12
|
+
|
13
|
+
=begin
|
14
|
+
configuration like follows:
|
15
|
+
|
16
|
+
BotConfig = [
|
17
|
+
{
|
18
|
+
:name => :RSS_CheckBot,
|
19
|
+
:rss_paths =>
|
20
|
+
[
|
21
|
+
'http://www.ruby-lang.org/ja/index.rdf',
|
22
|
+
],
|
23
|
+
:cache => "./rss-cache",
|
24
|
+
:ch => '#nadoka_check',
|
25
|
+
:tm => 30 # check interval time(minute)
|
26
|
+
:over_message => nil #
|
27
|
+
}
|
28
|
+
|
29
|
+
=end
|
30
|
+
|
31
|
+
require 'lib/rss_check'
|
32
|
+
require 'iconv'
|
33
|
+
require 'kconv'
|
34
|
+
|
35
|
+
class RSS_CheckBot < Nadoka::NDK_Bot
|
36
|
+
def bot_initialize
|
37
|
+
@cache = File.expand_path(@bot_config.fetch(:cache, '~/.rss_check'))
|
38
|
+
@paths = @bot_config.fetch(:rss_paths, ['http://www.ruby-lang.org/ja/index.rdf'])
|
39
|
+
@ch = @bot_config.fetch(:ch, '#nadoka_check')
|
40
|
+
@tm = @bot_config.fetch(:tm,30) # min
|
41
|
+
@over = @bot_config.fetch(:over_message, nil)
|
42
|
+
@rssc = RSS_Check.new(@paths, @cache, true)
|
43
|
+
@ic = Iconv.open("EUC-JP", "UTF-8")
|
44
|
+
@prevtm= Time.now
|
45
|
+
end
|
46
|
+
|
47
|
+
def bot_state
|
48
|
+
nt = Time.at(@prevtm.to_i + @tm * 60)
|
49
|
+
"<#{self.class}: next check at #{nt.asctime}@#{@ch}>"
|
50
|
+
end
|
51
|
+
|
52
|
+
def __on_privmsg prefix, ch, msg
|
53
|
+
if /^rss> check/ =~ msg && ch == @ch && prefix.nick == @state.nick
|
54
|
+
make_notice Time.now
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def send_notice(ch, msg)
|
59
|
+
if ch.respond_to? :each
|
60
|
+
ch.each{|c|
|
61
|
+
super(c, msg)
|
62
|
+
sleep 5 # Flood Protection
|
63
|
+
}
|
64
|
+
else
|
65
|
+
super(ch, msg)
|
66
|
+
sleep 5 # Flood Protection
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def on_timer tm
|
71
|
+
check
|
72
|
+
end
|
73
|
+
|
74
|
+
def check
|
75
|
+
tm = Time.now
|
76
|
+
if tm.to_i - @tm * 60 > @prevtm.to_i
|
77
|
+
make_notice tm
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def make_notice tm
|
82
|
+
@prevtm = tm
|
83
|
+
begin
|
84
|
+
items = @rssc.check
|
85
|
+
@rssc.save
|
86
|
+
rescue => e
|
87
|
+
send_notice(@ch, "rss bot error: #{e}")
|
88
|
+
@manager.ndk_error e
|
89
|
+
return
|
90
|
+
end
|
91
|
+
make_notice_thread items
|
92
|
+
end
|
93
|
+
|
94
|
+
def make_notice_thread items
|
95
|
+
Thread.new{
|
96
|
+
begin
|
97
|
+
items.each{|e|
|
98
|
+
if e[:ccode] == 'UTF-8'
|
99
|
+
begin
|
100
|
+
title = e[:title].gsub(/\357\275\236/u, "\343\200\234")
|
101
|
+
title = @ic.iconv(title).tojis
|
102
|
+
rescue Exception
|
103
|
+
# maybe, char code translation error
|
104
|
+
next
|
105
|
+
end
|
106
|
+
else
|
107
|
+
title = e[:title].tojis
|
108
|
+
end
|
109
|
+
|
110
|
+
send_notice(@ch, "rss bot: #{title} - #{e[:about]}")
|
111
|
+
}
|
112
|
+
rescue Exception => e
|
113
|
+
send_notice(@ch, "rss bot error: #{e}")
|
114
|
+
@manager.ndk_error e
|
115
|
+
end
|
116
|
+
send_notice(@ch, "rss bot: #{@over}") if @over
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*-ruby-*-
|
2
|
+
#
|
3
|
+
# Copyright (c) 2004-2005 SASADA Koichi <ko1 at atdot.net>
|
4
|
+
#
|
5
|
+
# This program is free software with ABSOLUTELY NO WARRANTY.
|
6
|
+
# You can re-distribute and/or modify this program under
|
7
|
+
# the same terms of the Ruby's license.
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# $Id$
|
11
|
+
#
|
12
|
+
|
13
|
+
# bot_file_name and BotClassName must be same name
|
14
|
+
# (BotClassName.downcase == bot_file_name)
|
15
|
+
|
16
|
+
class SampleBot < Nadoka::NDK_Bot
|
17
|
+
|
18
|
+
# Yes person
|
19
|
+
def on_privmsg prefix, ch, msg
|
20
|
+
send_notice(ch, "Yes, #{prefix.nick}!")
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*-ruby-*-
|
2
|
+
#
|
3
|
+
# Copyright (c) 2004-2006 SASADA Koichi <ko1 at atdot.net>
|
4
|
+
#
|
5
|
+
# This program is free software with ABSOLUTELY NO WARRANTY.
|
6
|
+
# You can re-distribute and/or modify this program under
|
7
|
+
# the same terms of the Ruby's license.
|
8
|
+
#
|
9
|
+
#
|
10
|
+
#
|
11
|
+
|
12
|
+
class SendPingBot < Nadoka::NDK_Bot
|
13
|
+
def on_timer *args
|
14
|
+
@manager.ping_to_clients
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
data/plugins/shellbot.nb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# -*-ruby-*-
|
2
|
+
#
|
3
|
+
# Copyright (c) 2004-2005 SASADA Koichi <ko1 at atdot.net>
|
4
|
+
#
|
5
|
+
# This program is free software with ABSOLUTELY NO WARRANTY.
|
6
|
+
# You can re-distribute and/or modify this program under
|
7
|
+
# the same terms of the Ruby's license.
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# shell command bot
|
11
|
+
#
|
12
|
+
# $Id$
|
13
|
+
#
|
14
|
+
|
15
|
+
require 'timeout'
|
16
|
+
require 'kconv'
|
17
|
+
|
18
|
+
class ShellBot < Nadoka::NDK_Bot
|
19
|
+
ShellNick = 'nadoka_shell'
|
20
|
+
|
21
|
+
def on_client_privmsg client, ch, message
|
22
|
+
|
23
|
+
if ch == ShellNick
|
24
|
+
ans = exec_shell(message)
|
25
|
+
ans.each{|line|
|
26
|
+
msg = Cmd.privmsg(@state.nick, 'ans: ' + line)
|
27
|
+
client.send_to_client client.add_prefix(msg, ShellNick)
|
28
|
+
}
|
29
|
+
raise ::Nadoka::NDK_BotSendCancel
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def on_nadoka_command client, command, *params
|
34
|
+
if command == 'shell'
|
35
|
+
msg = Cmd.privmsg(@state.nick, 'Hello, this is shell command executor')
|
36
|
+
client.send_to_client client.add_prefix(msg, ShellNick)
|
37
|
+
raise ::Nadoka::NDK_BotSendCancel
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def exec_shell message
|
42
|
+
begin
|
43
|
+
ans = Thread.new{
|
44
|
+
begin
|
45
|
+
timeout(3){
|
46
|
+
str = `#{message}`.to_s
|
47
|
+
str.tojis
|
48
|
+
}
|
49
|
+
rescue Exception => e
|
50
|
+
e.message
|
51
|
+
end
|
52
|
+
}.value
|
53
|
+
rescue Exception => e
|
54
|
+
ans = e.message
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#-*-ruby-*-
|
2
|
+
#
|
3
|
+
# Copyright (c) 2004-2005 SASADA Koichi <ko1 at atdot.net>
|
4
|
+
#
|
5
|
+
# This program is free software with ABSOLUTELY NO WARRANTY.
|
6
|
+
# You can re-distribute and/or modify this program under
|
7
|
+
# the same terms of the Ruby's license.
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# Sixamo bot
|
11
|
+
#
|
12
|
+
# add config like this:
|
13
|
+
#
|
14
|
+
=begin
|
15
|
+
BotConfig = [
|
16
|
+
{
|
17
|
+
:name => :SixamoBot,
|
18
|
+
:dir => '~/sixamo',
|
19
|
+
:ch => '#nadoka',
|
20
|
+
:tm => 10,
|
21
|
+
:id => /(sixamo)|(�������)/,
|
22
|
+
:rt => [10, 5, 4, 4, 3, 2],
|
23
|
+
}
|
24
|
+
=end
|
25
|
+
#
|
26
|
+
# $Id$
|
27
|
+
#
|
28
|
+
|
29
|
+
require 'sixamo'
|
30
|
+
require 'kconv'
|
31
|
+
class SixamoBot < Nadoka::NDK_Bot
|
32
|
+
def bot_initialize
|
33
|
+
@sixamo_dir = @bot_config[:dir] || '~/sixamo'
|
34
|
+
@sixamo_ch = @bot_config[:ch] || '#nadoka'
|
35
|
+
@sixamo_tm = @bot_config[:tm] || 10
|
36
|
+
@sixamo_id = @bot_config[:id] || /(sixamo)|(�������)/
|
37
|
+
@sixamo_rt = @bot_config[:rt] || [10, 5, 4, 4, 3, 2]
|
38
|
+
@prev = Time.now
|
39
|
+
make_sixamo
|
40
|
+
end
|
41
|
+
|
42
|
+
def make_sixamo
|
43
|
+
@sixamo = Sixamo.new(File.expand_path(@sixamo_dir))
|
44
|
+
end
|
45
|
+
|
46
|
+
def on_privmsg prefix, ch, msg
|
47
|
+
return unless @sixamo_ch === ch
|
48
|
+
|
49
|
+
begin
|
50
|
+
msg = Kconv.toeuc(msg)
|
51
|
+
@sixamo.memorize msg
|
52
|
+
|
53
|
+
unless @sixamo_id === msg
|
54
|
+
rnd = case Time.now - @prev
|
55
|
+
when 0..10; @sixamo_rt[0]
|
56
|
+
when 10..20; @sixamo_rt[1]
|
57
|
+
when 20..30; @sixamo_rt[2]
|
58
|
+
when 30..60; @sixamo_rt[3]
|
59
|
+
when 60..120;@sixamo_rt[4]
|
60
|
+
else ; @sixamo_rt[5]
|
61
|
+
end
|
62
|
+
|
63
|
+
return if Kernel.rand(rnd) != 1
|
64
|
+
end
|
65
|
+
@prev = Time.now
|
66
|
+
|
67
|
+
talk = @sixamo.talk(msg)
|
68
|
+
@sixamo.memorize talk
|
69
|
+
|
70
|
+
send_notice ch, 'sixamo: ' + talk.tojis
|
71
|
+
rescue
|
72
|
+
make_sixamo
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
data/plugins/tenkibot.nb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# -*-ruby-*-
|
2
|
+
#
|
3
|
+
# Copyright (c) 2004-2006 SASADA Koichi <ko1 at atdot.net>
|
4
|
+
#
|
5
|
+
# This program is free software with ABSOLUTELY NO WARRANTY.
|
6
|
+
# You can re-distribute and/or modify this program under
|
7
|
+
# the same terms of the Ruby's license.
|
8
|
+
#
|
9
|
+
|
10
|
+
=begin
|
11
|
+
|
12
|
+
== Abstract
|
13
|
+
|
14
|
+
Answer weather information using "Livedoor Weather Web Service / LWWS".
|
15
|
+
|
16
|
+
LWWS: http://weather.livedoor.com/weather_hacks/webservice.html
|
17
|
+
|
18
|
+
|
19
|
+
== Usage
|
20
|
+
|
21
|
+
tenki> [CITY]
|
22
|
+
tenki:[today|tomorrow|dayaftertomorrow]> [CITY]
|
23
|
+
|
24
|
+
[CITY] should be city name in Kanji listed on following table.
|
25
|
+
http://weather.livedoor.com/forecast/rss/forecastmap.xml
|
26
|
+
|
27
|
+
If timing is not specified, show today's information.
|
28
|
+
|
29
|
+
|
30
|
+
== Configuration
|
31
|
+
|
32
|
+
BotConfig = [
|
33
|
+
{
|
34
|
+
:name => :TenkiBot,
|
35
|
+
:ch => /nadoka/, # default: /.*/
|
36
|
+
}
|
37
|
+
]
|
38
|
+
|
39
|
+
|
40
|
+
=end
|
41
|
+
|
42
|
+
require 'open-uri'
|
43
|
+
require 'pp'
|
44
|
+
require 'kconv'
|
45
|
+
require 'rexml/document'
|
46
|
+
require 'date'
|
47
|
+
|
48
|
+
|
49
|
+
class TenkiBot < Nadoka::NDK_Bot
|
50
|
+
|
51
|
+
CityIDs = {}
|
52
|
+
|
53
|
+
def bot_initialize
|
54
|
+
bot_init_utils
|
55
|
+
|
56
|
+
open('http://weather.livedoor.com/forecast/rss/forecastmap.xml'){|f|
|
57
|
+
f.each{|line|
|
58
|
+
if /city title="(.+?)" id="(\d+)"/ =~ line
|
59
|
+
CityIDs[$1.toeuc] = $2.to_i
|
60
|
+
end
|
61
|
+
}
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def tenki city, timing
|
66
|
+
doc = open(
|
67
|
+
"http://weather.livedoor.com/forecast/webservice/rest/v1?" \
|
68
|
+
"city=#{CityIDs.fetch(city)}&day=#{timing}"){|f|
|
69
|
+
REXML::Document.new f.read
|
70
|
+
}
|
71
|
+
|
72
|
+
title = doc.elements['/lwws/title/'].text.toeuc
|
73
|
+
telop = doc.elements['/lwws/telop/'].text.toeuc
|
74
|
+
link = doc.elements['/lwws/link/'].text.toeuc
|
75
|
+
desc = doc.elements['/lwws/description/'].text.toeuc
|
76
|
+
max = doc.elements['/lwws/temperature/max/celsius/'].text
|
77
|
+
min = doc.elements['/lwws/temperature/min/celsius/'].text
|
78
|
+
date = Date.parse(doc.elements['/lwws/forecastdate/'].text)
|
79
|
+
datestr = date.strftime('%m/%d')
|
80
|
+
|
81
|
+
desc.sub!(/\.\.\..*/m, '...')
|
82
|
+
|
83
|
+
celsius = []
|
84
|
+
celsius << "max: #{max}" if max
|
85
|
+
celsius << "min: #{min}" if min
|
86
|
+
unless celsius.empty?
|
87
|
+
celsius = "(#{celsius.join(', ')}) "
|
88
|
+
end
|
89
|
+
"#{title} (#{datestr}): #{telop} - #{celsius}#{desc} - #{link}".tojis
|
90
|
+
end
|
91
|
+
|
92
|
+
def on_privmsg prefix, ch, msg
|
93
|
+
return unless @available_channel === ch
|
94
|
+
return if same_bot?(ch)
|
95
|
+
|
96
|
+
if /\Atenki(|:(today|tomorrow|dayaftertomorrow))>(.+)/ =~ msg
|
97
|
+
city = $3.strip.toeuc
|
98
|
+
timing = ($2 || 'today').strip
|
99
|
+
begin
|
100
|
+
result = tenki(city, timing).gsub(/\n/, ' ')
|
101
|
+
rescue IndexError
|
102
|
+
result = "Unknown city. Check city title on http://weather.livedoor.com/forecast/rss/forecastmap.xml"
|
103
|
+
rescue => e
|
104
|
+
result = "#{e}"
|
105
|
+
end
|
106
|
+
send_notice ch, "tenki bot: #{result}"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
|