mod_spox 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +31 -1
- data/LICENSE +674 -0
- data/README.rdoc +73 -0
- data/bin/mod_spox +28 -28
- data/data/mod_spox/extras/AOLSpeak.rb +2 -3
- data/data/mod_spox/extras/AutoKick.rb +10 -23
- data/data/mod_spox/extras/AutoMode.rb +12 -23
- data/data/mod_spox/extras/Bash.rb +55 -0
- data/data/mod_spox/extras/Bouncer.rb +85 -57
- data/data/mod_spox/extras/Bullshit.rb +1 -1
- data/data/mod_spox/extras/Bytes.rb +1 -2
- data/data/mod_spox/extras/Confess.rb +27 -29
- data/data/mod_spox/extras/DCC.rb +11 -20
- data/data/mod_spox/extras/DevWatch.rb +21 -23
- data/data/mod_spox/extras/DownForEveryoneOrJustMe.rb +47 -0
- data/data/mod_spox/extras/EightBall.rb +1 -1
- data/data/mod_spox/extras/FML.rb +35 -0
- data/data/mod_spox/extras/Headers.rb +31 -50
- data/data/mod_spox/extras/Karma.rb +81 -29
- data/data/mod_spox/extras/Logger.rb +2 -2
- data/data/mod_spox/extras/LolSpeak.rb +1 -2
- data/data/mod_spox/extras/PhpCli.rb +138 -8
- data/data/mod_spox/extras/PhpFuncLookup.rb +20 -23
- data/data/mod_spox/extras/Pinger.rb +1 -1
- data/data/mod_spox/extras/Quotes.rb +8 -10
- data/data/mod_spox/extras/RegexTracker.rb +2 -4
- data/data/mod_spox/extras/Roulette.rb +20 -27
- data/data/mod_spox/extras/RubyCli.rb +93 -0
- data/data/mod_spox/extras/Search.rb +17 -3
- data/data/mod_spox/extras/Seen.rb +150 -0
- data/data/mod_spox/extras/SlashdotHeadlineGenerator.rb +500 -0
- data/data/mod_spox/extras/Talk.rb +2 -4
- data/data/mod_spox/extras/Topten.rb +10 -12
- data/data/mod_spox/extras/TracTicket.rb +3 -5
- data/data/mod_spox/extras/Translate.rb +20 -22
- data/data/mod_spox/extras/Twitter.rb +118 -33
- data/data/mod_spox/extras/UrbanDictionary.rb +8 -17
- data/data/mod_spox/extras/Weather.rb +1 -2
- data/data/mod_spox/plugins/Authenticator.rb +93 -98
- data/data/mod_spox/plugins/Banner.rb +26 -56
- data/data/mod_spox/plugins/Helper.rb +5 -6
- data/data/mod_spox/plugins/Initializer.rb +4 -14
- data/data/mod_spox/plugins/Joiner.rb +1 -1
- data/data/mod_spox/plugins/Nicker.rb +13 -0
- data/data/mod_spox/plugins/Parter.rb +2 -2
- data/data/mod_spox/plugins/Permissions.rb +60 -0
- data/data/mod_spox/plugins/PluginLoader.rb +7 -12
- data/data/mod_spox/plugins/Ponger.rb +51 -0
- data/data/mod_spox/plugins/Quitter.rb +1 -2
- data/data/mod_spox/plugins/Servers.rb +57 -0
- data/data/mod_spox/plugins/Status.rb +3 -2
- data/data/mod_spox/plugins/Triggers.rb +9 -9
- data/lib/mod_spox/Bot.rb +109 -33
- data/lib/mod_spox/BotConfig.rb +2 -2
- data/lib/mod_spox/ConfigurationWizard.rb +12 -12
- data/lib/mod_spox/Database.rb +1 -4
- data/lib/mod_spox/Exceptions.rb +26 -0
- data/lib/mod_spox/Helpers.rb +29 -68
- data/lib/mod_spox/Loader.rb +23 -24
- data/lib/mod_spox/Logger.rb +19 -17
- data/lib/mod_spox/MessageFactory.rb +50 -24
- data/lib/mod_spox/Pipeline.rb +21 -7
- data/lib/mod_spox/Plugin.rb +27 -3
- data/lib/mod_spox/PluginManager.rb +28 -15
- data/lib/mod_spox/PriorityQueue.rb +69 -0
- data/lib/mod_spox/Socket.rb +93 -51
- data/lib/mod_spox/Sockets.rb +76 -63
- data/lib/mod_spox/Timer.rb +21 -141
- data/lib/mod_spox/Version.rb +14 -0
- data/lib/mod_spox/handlers/BadNick.rb +1 -1
- data/lib/mod_spox/handlers/Bounce.rb +5 -5
- data/lib/mod_spox/handlers/Created.rb +13 -5
- data/lib/mod_spox/handlers/Handler.rb +12 -3
- data/lib/mod_spox/handlers/Invite.rb +14 -8
- data/lib/mod_spox/handlers/Join.rb +24 -20
- data/lib/mod_spox/handlers/Kick.rb +22 -13
- data/lib/mod_spox/handlers/Mode.rb +42 -36
- data/lib/mod_spox/handlers/Motd.rb +4 -0
- data/lib/mod_spox/handlers/Names.rb +66 -39
- data/lib/mod_spox/handlers/Nick.rb +20 -14
- data/lib/mod_spox/handlers/Part.rb +25 -8
- data/lib/mod_spox/handlers/Ping.rb +11 -5
- data/lib/mod_spox/handlers/Pong.rb +9 -5
- data/lib/mod_spox/handlers/Privmsg.rb +25 -17
- data/lib/mod_spox/handlers/Quit.rb +13 -8
- data/lib/mod_spox/handlers/Topic.rb +4 -0
- data/lib/mod_spox/handlers/Welcome.rb +16 -24
- data/lib/mod_spox/handlers/Who.rb +64 -48
- data/lib/mod_spox/handlers/Whois.rb +92 -60
- data/lib/mod_spox/messages/incoming/Nick.rb +2 -2
- data/lib/mod_spox/messages/incoming/Privmsg.rb +1 -1
- data/lib/mod_spox/messages/incoming/Whois.rb +1 -0
- data/lib/mod_spox/messages/internal/EstablishConnection.rb +1 -1
- data/lib/mod_spox/messages/internal/PluginsReady.rb +10 -0
- data/lib/mod_spox/messages/internal/QueueSocket.rb +8 -0
- data/lib/mod_spox/messages/internal/Reconnect.rb +8 -0
- data/lib/mod_spox/messages/internal/UnqueueSocket.rb +8 -0
- data/lib/mod_spox/migrations/002_persistent_sigs.rb +14 -0
- data/lib/mod_spox/migrations/003_auth_restructure.rb +31 -0
- data/lib/mod_spox/migrations/004_mode_index_fix.rb +18 -0
- data/lib/mod_spox/migrations/005_nick_mode_nopark.rb +18 -0
- data/lib/mod_spox/models/Auth.rb +16 -46
- data/lib/mod_spox/models/AuthMask.rb +13 -0
- data/lib/mod_spox/models/Channel.rb +46 -27
- data/lib/mod_spox/models/Config.rb +10 -19
- data/lib/mod_spox/models/Group.rb +20 -8
- data/lib/mod_spox/models/Models.rb +1 -1
- data/lib/mod_spox/models/Nick.rb +105 -113
- data/lib/mod_spox/models/NickMode.rb +23 -9
- data/lib/mod_spox/models/Server.rb +12 -1
- data/lib/mod_spox/models/Setting.rb +12 -16
- data/lib/mod_spox/models/Signature.rb +28 -8
- data/tests/BotHolder.rb +24 -0
- data/tests/handlers/tc_BadNick.rb +21 -0
- data/tests/handlers/tc_Created.rb +24 -0
- data/tests/handlers/tc_Invite.rb +50 -0
- data/tests/handlers/tc_Join.rb +33 -0
- data/tests/handlers/tc_Kick.rb +32 -0
- data/tests/handlers/tc_Mode.rb +85 -0
- data/tests/handlers/tc_Names.rb +35 -0
- data/tests/handlers/tc_Nick.rb +55 -0
- data/tests/handlers/tc_Part.rb +44 -0
- data/tests/handlers/tc_Ping.rb +40 -0
- data/tests/handlers/tc_Pong.rb +28 -0
- data/tests/handlers/tc_Privmsg.rb +85 -0
- data/tests/handlers/tc_Quit.rb +40 -0
- data/tests/handlers/tc_Who.rb +50 -0
- data/tests/handlers/tc_Whois.rb +61 -0
- data/tests/models/tc_Auth.rb +34 -0
- data/tests/models/tc_Channel.rb +52 -0
- data/tests/models/tc_Config.rb +19 -0
- data/tests/models/tc_Nick.rb +142 -0
- data/tests/models/tc_NickMode.rb +40 -0
- data/tests/models/tc_Setting.rb +21 -0
- data/tests/models/tc_Signature.rb +14 -0
- data/tests/run_tests.rb +4 -0
- metadata +284 -212
- data/README +0 -36
- data/lib/mod_spox/Cache.rb +0 -57
- data/lib/mod_spox/Monitors.rb +0 -84
- data/lib/mod_spox/Pool.rb +0 -164
- data/lib/mod_spox/models/AuthGroup.rb +0 -16
- data/lib/mod_spox/models/ChannelMode.rb +0 -14
- data/lib/mod_spox/models/NickChannel.rb +0 -45
- data/lib/mod_spox/models/NickGroup.rb +0 -16
data/README
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
mod_spox
|
2
|
-
http://modspox.rubyforge.org
|
3
|
-
Author: spox
|
4
|
-
|
5
|
-
== Description
|
6
|
-
|
7
|
-
A Ruby IRC bot
|
8
|
-
|
9
|
-
== Usage
|
10
|
-
|
11
|
-
Configuration:
|
12
|
-
|
13
|
-
mod_spox --config
|
14
|
-
|
15
|
-
Running:
|
16
|
-
|
17
|
-
mod_spox
|
18
|
-
|
19
|
-
== Requirements
|
20
|
-
|
21
|
-
* sequel
|
22
|
-
* database driver
|
23
|
-
|
24
|
-
== Optional
|
25
|
-
|
26
|
-
* fastthread
|
27
|
-
|
28
|
-
== Install
|
29
|
-
|
30
|
-
sudo gem install --include-dependencies mod_spox
|
31
|
-
|
32
|
-
== License
|
33
|
-
|
34
|
-
mod_spox is licensed under the GPLv3
|
35
|
-
|
36
|
-
Copyright (c) 2008 spox <spox@modspox.com>
|
data/lib/mod_spox/Cache.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
module ModSpox
|
2
|
-
class Cache
|
3
|
-
def initialize(size)
|
4
|
-
@size = size
|
5
|
-
@cache = Hash.new
|
6
|
-
@times = Hash.new
|
7
|
-
@store_lock = Mutex.new
|
8
|
-
@read_lock = Mutex.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def [](key)
|
12
|
-
if(@cache.has_key?(key.to_sym))
|
13
|
-
@times[key.to_sym] = Time.now
|
14
|
-
return @cache[key.to_sym]
|
15
|
-
else
|
16
|
-
return nil
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def has_key?(key)
|
21
|
-
@read_lock.synchronize do
|
22
|
-
return @cache.has_key?(key.to_sym)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def []=(key, value)
|
27
|
-
@store_lock.synchronize do
|
28
|
-
if(@cache.size > @size)
|
29
|
-
del_key = oldest_key
|
30
|
-
unless(key.nil?)
|
31
|
-
@cache.delete(del_key)
|
32
|
-
@times.delete(del_key)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
@cache[key.to_sym] = value
|
36
|
-
@times[key.to_sym] = Time.now
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def delete(key)
|
41
|
-
@read_lock.synchronize do
|
42
|
-
@cache.delete(key.to_sym) if @cache.has_key?(key.to_sym)
|
43
|
-
@times.delete(key.to_sym) if @times.has_key?(key.to_sym)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def oldest_key
|
50
|
-
result = nil
|
51
|
-
@read_lock.synchronize do
|
52
|
-
result = @times.sort{|a,b| a[1] <=> b[1]}[0][0]
|
53
|
-
end
|
54
|
-
return result
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
data/lib/mod_spox/Monitors.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
module ModSpox
|
2
|
-
module Monitors
|
3
|
-
|
4
|
-
# The Timer is a time based monitor (thus the
|
5
|
-
# "Timer" part of the name)
|
6
|
-
class Timer
|
7
|
-
|
8
|
-
# Create a new Timer Monitor
|
9
|
-
def initialize
|
10
|
-
@threads = Array.new
|
11
|
-
end
|
12
|
-
|
13
|
-
# Force the monitor to wake everyone up
|
14
|
-
def wakeup
|
15
|
-
@threads.each do |t|
|
16
|
-
begin
|
17
|
-
t.wakeup
|
18
|
-
rescue Object => boom
|
19
|
-
# thread was dead #
|
20
|
-
end
|
21
|
-
end
|
22
|
-
@threads.clear
|
23
|
-
end
|
24
|
-
|
25
|
-
# How long the monitor should wait
|
26
|
-
def wait(time=nil)
|
27
|
-
@threads << Thread.current
|
28
|
-
if(time.nil?)
|
29
|
-
sleep
|
30
|
-
else
|
31
|
-
sleep(time)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
# The Boolean is a boolean based monitor (thus the
|
38
|
-
# "Boolean" part of the name)
|
39
|
-
class Boolean
|
40
|
-
|
41
|
-
# Create a new Boolean Monitor
|
42
|
-
def initialize
|
43
|
-
@threads = []
|
44
|
-
end
|
45
|
-
|
46
|
-
# Stop waiting
|
47
|
-
def wakeup
|
48
|
-
return if @threads.empty?
|
49
|
-
@threads.each do |t|
|
50
|
-
begin
|
51
|
-
t.wakeup
|
52
|
-
rescue Object => boom
|
53
|
-
# thread was dead #
|
54
|
-
end
|
55
|
-
end
|
56
|
-
@threads.clear
|
57
|
-
end
|
58
|
-
|
59
|
-
# Start waiting
|
60
|
-
def wait
|
61
|
-
@threads << Thread.current
|
62
|
-
sleep
|
63
|
-
end
|
64
|
-
|
65
|
-
# Returns if a thread is currently waiting in this monitor
|
66
|
-
def thread_waiting?(thread)
|
67
|
-
return @threads.include?(thread)
|
68
|
-
end
|
69
|
-
|
70
|
-
# Removes a thread from the list of waiting. Will be removed automatically
|
71
|
-
# if thread has been killed on next call to wakeup
|
72
|
-
def remove_thread(thread)
|
73
|
-
@threads.delete(thread) if @threads.include?(thread)
|
74
|
-
end
|
75
|
-
|
76
|
-
# Returns the number of threads currently waiting in this monitor
|
77
|
-
def count
|
78
|
-
@threads.size
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
data/lib/mod_spox/Pool.rb
DELETED
@@ -1,164 +0,0 @@
|
|
1
|
-
['mod_spox/Logger',
|
2
|
-
'mod_spox/Exceptions',
|
3
|
-
'timeout',
|
4
|
-
'singleton'].each{|f|require f}
|
5
|
-
|
6
|
-
module ModSpox
|
7
|
-
|
8
|
-
class PoolThread
|
9
|
-
def initialize(pool, timeout)
|
10
|
-
@pool = pool
|
11
|
-
@timeout = timeout
|
12
|
-
@kill = false
|
13
|
-
@thread = Thread.new do
|
14
|
-
until @kill do
|
15
|
-
begin
|
16
|
-
action = nil
|
17
|
-
if(Pool.workers > Pool.workers_min)
|
18
|
-
Timeout::timeout(60) do
|
19
|
-
action = @pool.queue.pop
|
20
|
-
end
|
21
|
-
else
|
22
|
-
action = @pool.queue.pop
|
23
|
-
end
|
24
|
-
run(action) unless action.nil?
|
25
|
-
rescue Timeout::Error => boom
|
26
|
-
@kill = true
|
27
|
-
rescue Object => boom
|
28
|
-
Logger.warn("Pool thread error: #{boom}")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
@pool.remove(self)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def run(action)
|
38
|
-
begin
|
39
|
-
if(@timeout > 0)
|
40
|
-
Timeout::timeout(@timeout) do
|
41
|
-
action.call
|
42
|
-
end
|
43
|
-
else
|
44
|
-
action.call
|
45
|
-
end
|
46
|
-
rescue Timeout::Error => boom
|
47
|
-
Logger.warn("Pool worker timed out during execution of action (#{@timeout} sec limit): #{action}")
|
48
|
-
rescue Object => boom
|
49
|
-
Logger.warn("Pool worker caught an unknown exception: #{boom}")
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# The Pool class is used to reduce thread creation. It provides
|
55
|
-
# an easy way to process many actions in an asynchronous manner.
|
56
|
-
class Pool
|
57
|
-
|
58
|
-
include Singleton
|
59
|
-
|
60
|
-
# Add an action to the pool to be processed
|
61
|
-
def Pool.<<(action)
|
62
|
-
Pool.instance.add(action)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Alias of Pool.<<(action)
|
66
|
-
def Pool.queue(action)
|
67
|
-
Pool << action
|
68
|
-
end
|
69
|
-
|
70
|
-
def Pool.workers
|
71
|
-
Pool.instance.threads.size
|
72
|
-
end
|
73
|
-
|
74
|
-
def Pool.workers_min
|
75
|
-
return Pool.instance.min
|
76
|
-
end
|
77
|
-
|
78
|
-
def Pool.workers_max
|
79
|
-
return Pool.instance.max
|
80
|
-
end
|
81
|
-
|
82
|
-
def remove(pt)
|
83
|
-
@threads.delete(pt)
|
84
|
-
Logger.info("Pool thread has been removed: #{pt}")
|
85
|
-
end
|
86
|
-
|
87
|
-
def add(action)
|
88
|
-
@queue << action
|
89
|
-
create_pool_thread if @queue.size > @min
|
90
|
-
end
|
91
|
-
|
92
|
-
# Return maximum number of seconds actions are allowed to process
|
93
|
-
def Pool.worker_timeout
|
94
|
-
Pool.instance.timeout
|
95
|
-
end
|
96
|
-
|
97
|
-
# time:: number of seconds actions are allowed
|
98
|
-
# Set number of seconds actions are allowed to work
|
99
|
-
def Pool.worker_timeout=(time)
|
100
|
-
Pool.instance.timeout = time
|
101
|
-
end
|
102
|
-
|
103
|
-
# Set maximum number of workers to process tasks
|
104
|
-
def Pool.workers_max=(max)
|
105
|
-
Pool.instance.workers_max = max
|
106
|
-
end
|
107
|
-
|
108
|
-
# Not currently implemented
|
109
|
-
def Pool.workers_min=(min)
|
110
|
-
Pool.instance.workers_min = min
|
111
|
-
end
|
112
|
-
|
113
|
-
attr_reader :threads
|
114
|
-
attr_reader :queue
|
115
|
-
attr_reader :min
|
116
|
-
attr_reader :max
|
117
|
-
attr_reader :timeout
|
118
|
-
|
119
|
-
def initialize
|
120
|
-
@queue = Queue.new
|
121
|
-
@threads = []
|
122
|
-
@lock = Mutex.new
|
123
|
-
@timeout = get_value('pool_timeout', 0).to_i
|
124
|
-
@max = Database.type != :pgsql ? 1 : get_value('pool_workers_max', 7).to_i
|
125
|
-
@min = Database.type != :pgsql ? 1 : get_value('pool_workers_min', 5).to_i
|
126
|
-
@min.times{create_pool_thread}
|
127
|
-
end
|
128
|
-
|
129
|
-
def create_pool_thread(force=false)
|
130
|
-
return nil unless @threads.size < @max || force
|
131
|
-
pt = PoolThread.new(self, @timeout)
|
132
|
-
@threads << pt
|
133
|
-
return pt
|
134
|
-
end
|
135
|
-
|
136
|
-
def get_value(n, default)
|
137
|
-
m = Models::Config.filter(:name => n).first
|
138
|
-
return m.nil? ? default : m.value
|
139
|
-
end
|
140
|
-
|
141
|
-
def set_value(n, v)
|
142
|
-
m = Models::Config.find_or_create(:name => n)
|
143
|
-
m.value = v
|
144
|
-
m.save
|
145
|
-
end
|
146
|
-
|
147
|
-
def timeout=(v)
|
148
|
-
set_value('pool_timeout', v.to_i)
|
149
|
-
@timeout = v.to_i
|
150
|
-
end
|
151
|
-
|
152
|
-
def workers_max=(v)
|
153
|
-
set_value('pool_workers_max', v.to_i)
|
154
|
-
@max = v.to_i
|
155
|
-
end
|
156
|
-
|
157
|
-
def workers_min=(v)
|
158
|
-
set_value('pool_workers_min', v.to_i)
|
159
|
-
@min = v.to_i
|
160
|
-
end
|
161
|
-
|
162
|
-
end
|
163
|
-
|
164
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module ModSpox
|
2
|
-
module Models
|
3
|
-
# This model is for internal use only to provide a
|
4
|
-
# proper relation between Nick and Channel
|
5
|
-
class NickChannel < Sequel::Model
|
6
|
-
|
7
|
-
include Models
|
8
|
-
|
9
|
-
set_primary_key [:nick_id, :channel_id]
|
10
|
-
|
11
|
-
after_save do
|
12
|
-
c = Channel[channel_id]
|
13
|
-
n = Nick[nick_id]
|
14
|
-
n.visible = true
|
15
|
-
n.save
|
16
|
-
c.parked = true
|
17
|
-
c.save
|
18
|
-
end
|
19
|
-
|
20
|
-
after_destroy do
|
21
|
-
c = Channel[channel_id]
|
22
|
-
n = Nick[nick_id]
|
23
|
-
if(n.channels.size < 1)
|
24
|
-
n.visible = false
|
25
|
-
n.save
|
26
|
-
NickMode.filter(:nick_id => nick_id).each{|n|n.destroy}
|
27
|
-
end
|
28
|
-
if(c.nicks.size < 1)
|
29
|
-
c.parked = false
|
30
|
-
c.save
|
31
|
-
NickMode.filter(:channel_id => channel_id).each{|n|n.destroy}
|
32
|
-
ChannelMode.filter(:channel_id => channel_id).each{|n|n.destroy}
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def nick
|
37
|
-
Nick[nick_id]
|
38
|
-
end
|
39
|
-
|
40
|
-
def channel
|
41
|
-
Channel[channel_id]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|