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
data/plugins/autoop.nb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# -*-ruby-*-
|
2
|
+
#
|
3
|
+
# $Id$
|
4
|
+
#
|
5
|
+
|
6
|
+
=begin
|
7
|
+
|
8
|
+
== Name
|
9
|
+
|
10
|
+
Auto OP
|
11
|
+
|
12
|
+
== Abstract
|
13
|
+
|
14
|
+
Auto OP
|
15
|
+
|
16
|
+
== Configuration
|
17
|
+
|
18
|
+
BotConfig = [
|
19
|
+
{
|
20
|
+
:name => :AutoOP,
|
21
|
+
:friends => [
|
22
|
+
{ :nick => 'hoge' },
|
23
|
+
{ :user => 'fuga' },
|
24
|
+
]
|
25
|
+
},
|
26
|
+
]
|
27
|
+
|
28
|
+
== License
|
29
|
+
|
30
|
+
This program is free software with ABSOLUTELY NO WARRANTY.
|
31
|
+
You can re-distribute and/or modify this program under
|
32
|
+
the same terms of the Ruby's lisence.
|
33
|
+
|
34
|
+
== Author
|
35
|
+
|
36
|
+
NARUSE, Yui <naruse@airemix.com>
|
37
|
+
|
38
|
+
=end
|
39
|
+
|
40
|
+
|
41
|
+
class AutoOP < Nadoka::NDK_Bot
|
42
|
+
def bot_initialize
|
43
|
+
@friends = @bot_config.fetch(:friends, [])
|
44
|
+
end
|
45
|
+
def friend?(prefix)
|
46
|
+
@friends.any? do |friend|
|
47
|
+
friend[:nick] == prefix.nick or friend[:user] == prefix.user[/~?(.*)\z/, 1]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
def on_join(prefix, ch)
|
51
|
+
return unless /o/ =~ @state.channel_user_mode(ch, @state.nick)
|
52
|
+
if prefix.nick != @state.nick && friend?(prefix)
|
53
|
+
change_mode(ch, "+o", prefix.nick)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,88 @@
|
|
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
|
+
|
15
|
+
== Abstract
|
16
|
+
|
17
|
+
BackLogBot support rich backlog management scheme.
|
18
|
+
|
19
|
+
|
20
|
+
== Configuration
|
21
|
+
|
22
|
+
#
|
23
|
+
# Maybe you don't have to write config(default setting is very useful)
|
24
|
+
#
|
25
|
+
BotConfig = [
|
26
|
+
{
|
27
|
+
:name => :BackLogBot,
|
28
|
+
|
29
|
+
:clear => false, # if true, clear backlogs when output once
|
30
|
+
:talker => false, # if true, talker will be pseudo talker
|
31
|
+
:prefix => 'BL',
|
32
|
+
:sender => 'backlogbot',
|
33
|
+
:time_format => '%m/%d-%H:%M',
|
34
|
+
}
|
35
|
+
]
|
36
|
+
|
37
|
+
=end
|
38
|
+
|
39
|
+
|
40
|
+
class BackLogBot < Nadoka::NDK_Bot
|
41
|
+
def bot_initialize
|
42
|
+
@stores = @logger.message_stores
|
43
|
+
@talker = @bot_config.fetch(:talker, false)
|
44
|
+
@clear = @bot_config.fetch(:clear, false)
|
45
|
+
@prefix = @bot_config.fetch(:prefix, 'BL')
|
46
|
+
@sender = @bot_config.fetch(:sender, 'backlogbot')
|
47
|
+
@sepr = @bot_config.fetch(:separate, true)
|
48
|
+
@tmfmt = @bot_config.fetch(:time_format, '%m/%d-%H:%M')
|
49
|
+
@msgfmts= @bot_config.fetch(:message_format, @config.default_log[:message_format])
|
50
|
+
@pattern= @bot_config.fetch(:pattern, nil)
|
51
|
+
end
|
52
|
+
|
53
|
+
def channel_message? ch
|
54
|
+
/\A[\&\#\+\!]/ =~ ch
|
55
|
+
end
|
56
|
+
|
57
|
+
def on_client_login client_count, client
|
58
|
+
@stores.each_channel_pool{|ch, msgobjs|
|
59
|
+
if @state.current_channels[ch]
|
60
|
+
msgobjs.each{|msgobj|
|
61
|
+
msg = @config.log_format_message(@msgfmts, msgobj)
|
62
|
+
rch = msgobj[:ch]
|
63
|
+
time = msgobj[:time]
|
64
|
+
|
65
|
+
cmd = Cmd.notice(rch, "#{@prefix}(#{time.strftime(@tmfmt)}) #{msg}")
|
66
|
+
client.add_prefix(cmd, @talker ? nick : @sender)
|
67
|
+
client.send_msg cmd
|
68
|
+
}
|
69
|
+
else
|
70
|
+
msgobjs.each{|msgobj|
|
71
|
+
if ch == :__talk__
|
72
|
+
msg = @config.log_format_message(@config.talk_log[:message_format], msgobj)
|
73
|
+
else
|
74
|
+
msg = @config.log_format_message(@config.system_log[:message_format], msgobj)
|
75
|
+
end
|
76
|
+
next unless @pattern.nil? || @pattern =~ msg
|
77
|
+
|
78
|
+
rch = msgobj[:ch]
|
79
|
+
time = msgobj[:time]
|
80
|
+
|
81
|
+
cmd = Cmd.notice(@state.nick, "#{@prefix}(#{time.strftime(@tmfmt)}) #{msg}")
|
82
|
+
client.send_msg cmd
|
83
|
+
}
|
84
|
+
end
|
85
|
+
}
|
86
|
+
@stores.clear if @clear
|
87
|
+
end
|
88
|
+
end
|
data/plugins/checkbot.nb
ADDED
@@ -0,0 +1,64 @@
|
|
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
|
+
class CheckBot < Nadoka::NDK_Bot
|
13
|
+
def bot_initialize
|
14
|
+
@ch = @bot_config[:ch] || '#nadoka'
|
15
|
+
@tm = @bot_config[:tm] || 30 # min
|
16
|
+
@prevtm = Time.now
|
17
|
+
|
18
|
+
# override me
|
19
|
+
@botheader = 'checkbot'
|
20
|
+
end
|
21
|
+
|
22
|
+
def on_timer tm
|
23
|
+
if time? && need_check?
|
24
|
+
check
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def time?
|
29
|
+
tm = Time.now
|
30
|
+
if tm.to_i - @tm * 60 > @prevtm.to_i
|
31
|
+
@prevtm = tm
|
32
|
+
true
|
33
|
+
else
|
34
|
+
false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
##############################
|
39
|
+
# use this
|
40
|
+
|
41
|
+
def check_notice text
|
42
|
+
if @ch.respond_to? :each
|
43
|
+
@ch.each{|ch|
|
44
|
+
send_notice(ch, "#{@botheader}: #{text}")
|
45
|
+
sleep 5 # Flood Protection
|
46
|
+
}
|
47
|
+
else
|
48
|
+
send_notice(@ch, "#{@botheader}: #{text}")
|
49
|
+
sleep 5 # Flood Protection
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
############################
|
54
|
+
# override me
|
55
|
+
|
56
|
+
def need_check?
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
60
|
+
def check
|
61
|
+
# some work
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
data/plugins/cronbot.nb
ADDED
@@ -0,0 +1,20 @@
|
|
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
|
+
class CronBot < Nadoka::NDK_Bot
|
14
|
+
def on_timer t
|
15
|
+
@state.channels.each{|ch|
|
16
|
+
send_notice(ch, t.to_s)
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
data/plugins/dictbot.nb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
This plugin is test version.
|
4
|
+
|
5
|
+
=end
|
6
|
+
|
7
|
+
require 'uri'
|
8
|
+
require 'open-uri'
|
9
|
+
require 'kconv'
|
10
|
+
|
11
|
+
class DictBot < Nadoka::NDK_Bot
|
12
|
+
def bot_initialize
|
13
|
+
@available_channel = @bot_config[:ch] || /.*/
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def on_privmsg prefix, ch, msg
|
19
|
+
if @available_channel === ch
|
20
|
+
if /\Adic(.)>\s*(.+)\s*/ =~ msg
|
21
|
+
res = yahoo_dict $1, $2.toeuc
|
22
|
+
send_notice(ch, res)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
YAHOO_DICT_TYPE ={
|
29
|
+
't' => 2,
|
30
|
+
'e' => 1,
|
31
|
+
'j' => 0,
|
32
|
+
'w' => 3,
|
33
|
+
'r' => 5,
|
34
|
+
}
|
35
|
+
def yahoo_dict type, word
|
36
|
+
"dict bot> " +
|
37
|
+
if type = YAHOO_DICT_TYPE[type]
|
38
|
+
word = URI.encode(word)
|
39
|
+
uri = "http://dic.yahoo.co.jp/dsearch?p=#{word}&stype=0&dtype=#{type}"
|
40
|
+
open(uri){|f|
|
41
|
+
if /<meta name="description" content=\"(.+?)\">/ =~ f.read
|
42
|
+
"#{$1.tosjis.tojis} - #{uri}"
|
43
|
+
else
|
44
|
+
uri
|
45
|
+
end
|
46
|
+
}
|
47
|
+
else
|
48
|
+
"unknown type: #{type}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
data/plugins/drbcl.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# An example for drbot.nb
|
3
|
+
#
|
4
|
+
#
|
5
|
+
|
6
|
+
require 'drb/drb'
|
7
|
+
|
8
|
+
class Invokee
|
9
|
+
include DRbUndumped
|
10
|
+
|
11
|
+
def initialize invoker
|
12
|
+
@invoker = invoker
|
13
|
+
@invoker.add_observer self
|
14
|
+
end
|
15
|
+
|
16
|
+
def update *args
|
17
|
+
p args
|
18
|
+
end
|
19
|
+
|
20
|
+
def destruct
|
21
|
+
@invoker.delete_observer self
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
uri = ARGV.shift || raise
|
26
|
+
DRb.start_service
|
27
|
+
|
28
|
+
invoker = DRbObject.new(nil, uri)
|
29
|
+
|
30
|
+
begin
|
31
|
+
invokee = Invokee.new(invoker)
|
32
|
+
p invoker
|
33
|
+
puts '---'
|
34
|
+
gets
|
35
|
+
ensure
|
36
|
+
invokee.destruct
|
37
|
+
end
|
38
|
+
|
39
|
+
|
data/plugins/drbot.nb
ADDED
@@ -0,0 +1,93 @@
|
|
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
|
+
|
15
|
+
== Abstract
|
16
|
+
|
17
|
+
An example using DRb. You can access to nadoka via DRb protocol.
|
18
|
+
See sample drbcl.rb
|
19
|
+
|
20
|
+
|
21
|
+
== Configuration
|
22
|
+
|
23
|
+
BotConfig = [
|
24
|
+
{
|
25
|
+
:name => :DRbot,
|
26
|
+
:port => 12345,
|
27
|
+
:host => '',
|
28
|
+
}
|
29
|
+
]
|
30
|
+
|
31
|
+
|
32
|
+
=end
|
33
|
+
|
34
|
+
|
35
|
+
require 'drb/drb'
|
36
|
+
require 'observer'
|
37
|
+
|
38
|
+
class DRbot < Nadoka::NDK_Bot
|
39
|
+
class Dispatcher
|
40
|
+
include Observable
|
41
|
+
|
42
|
+
def initialize bot
|
43
|
+
@bot = bot
|
44
|
+
end
|
45
|
+
|
46
|
+
def send_to_client prefix, command, args
|
47
|
+
changed
|
48
|
+
notify_observers(prefix, command, args)
|
49
|
+
end
|
50
|
+
|
51
|
+
def recv_from_client *args
|
52
|
+
@bot.kick_from_client args
|
53
|
+
end
|
54
|
+
|
55
|
+
def notify_observers(*arg)
|
56
|
+
if defined? @observer_state and @observer_state
|
57
|
+
if defined? @observer_peers
|
58
|
+
@observer_peers.dup.each{|e|
|
59
|
+
begin
|
60
|
+
e.update(*arg)
|
61
|
+
rescue Exception
|
62
|
+
@observer_peers.delete e
|
63
|
+
end
|
64
|
+
}
|
65
|
+
end
|
66
|
+
@observer_state = false
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
def bot_initialize
|
73
|
+
@port = @bot_config.fetch(:port, 12346)
|
74
|
+
@host = @bot_config.fetch(:host, '')
|
75
|
+
@invoker = Dispatcher.new(self)
|
76
|
+
@uri = "druby://#{@host}:#{@port}"
|
77
|
+
@drbserver = DRb.start_service(@uri, @invoker)
|
78
|
+
end
|
79
|
+
|
80
|
+
def bot_destruct
|
81
|
+
@drbserver.stop_service
|
82
|
+
end
|
83
|
+
|
84
|
+
def on_every_message prefix, command, *args
|
85
|
+
@invoker.send_to_client prefix, command, args
|
86
|
+
end
|
87
|
+
|
88
|
+
def recv_from_client *args
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
data/plugins/evalbot.nb
ADDED
@@ -0,0 +1,49 @@
|
|
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
|
+
# ruby evaluator on IRC
|
11
|
+
#
|
12
|
+
# $Id$
|
13
|
+
#
|
14
|
+
require 'timeout'
|
15
|
+
class EvalBot < Nadoka::NDK_Bot
|
16
|
+
EvalNick = 'nadoka_eval'
|
17
|
+
|
18
|
+
def on_client_privmsg client, ch, message
|
19
|
+
if ch == EvalNick
|
20
|
+
ans = eval_message(message)
|
21
|
+
msg = Cmd.privmsg(@state.nick, 'ans: ' + ans)
|
22
|
+
client.send_to_client client.add_prefix(msg, EvalNick)
|
23
|
+
raise ::Nadoka::NDK_BotSendCancel
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def on_nadoka_command client, command, *params
|
28
|
+
if command == 'eval'
|
29
|
+
msg = Cmd.privmsg(@state.nick, 'Hello, this is ruby evaluator')
|
30
|
+
client.send_to_client client.add_prefix(msg, EvalNick)
|
31
|
+
raise ::Nadoka::NDK_BotSendCancel
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def eval_message message
|
36
|
+
begin
|
37
|
+
ans = Thread.new{
|
38
|
+
$SAFE = 4
|
39
|
+
timeout(3){
|
40
|
+
Kernel.eval(message)
|
41
|
+
}
|
42
|
+
}.value.to_s
|
43
|
+
rescue Exception => e
|
44
|
+
ans = e.message
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|