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/lib/mod_spox/Sockets.rb
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
'mod_spox/Socket'
|
7
7
|
].each{|f| require f}
|
8
8
|
|
9
|
+
require 'spockets'
|
10
|
+
|
9
11
|
module ModSpox
|
10
12
|
|
11
13
|
class Sockets
|
@@ -17,28 +19,45 @@ module ModSpox
|
|
17
19
|
@irc_socket = nil
|
18
20
|
@dcc_sockets = []
|
19
21
|
@mapped_sockets = {}
|
20
|
-
@
|
22
|
+
@spockets = Spockets::Spockets.new(:pool => bot.pool)
|
21
23
|
@listening_dcc = []
|
22
24
|
@dcc_ports = {:start => 49152, :end => 65535}
|
23
25
|
@dcc_wait = 30
|
24
|
-
@read_thread = nil
|
25
26
|
@pipeline = bot.pipeline
|
26
27
|
@factory = bot.factory
|
27
28
|
@pipeline.hook(self, :check_dcc, :Incoming_Privmsg)
|
28
29
|
@pipeline.hook(self, :return_socket, :Internal_DCCRequest)
|
29
30
|
@pipeline.hook(self, :dcc_listener, :Internal_DCCListener)
|
30
|
-
@
|
31
|
-
@
|
31
|
+
@pipeline.hook(self, :disconnect_irc, :Internal_Disconnected)
|
32
|
+
@pipeline.hook(self, :queue_messages, :Internal_QueueSocket)
|
33
|
+
@pipeline.hook(self, :unqueue_messages, :Internal_UnqueueSocket)
|
34
|
+
@queues = {:irc => Queue.new, :dcc => Queue.new}
|
35
|
+
@queue_messages = false
|
32
36
|
end
|
33
37
|
|
34
38
|
# server:: IRC server string
|
35
39
|
# port:: IRC port
|
36
40
|
# Connect to the given IRC server
|
37
|
-
def irc_connect(server, port)
|
38
|
-
@irc_socket
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
def irc_connect(server=nil, port=nil)
|
42
|
+
if(@irc_socket.nil?)
|
43
|
+
@irc_socket = Socket.new(@bot, server, port)
|
44
|
+
@irc_socket.connect
|
45
|
+
@spockets.add(@irc_socket.socket){|string| process_irc_string(string)}
|
46
|
+
@spockets.on_close(@irc_socket.socket){ irc_reconnect }
|
47
|
+
else
|
48
|
+
irc_reconnect
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def irc_reconnect
|
53
|
+
unless(@irc_socket.nil?)
|
54
|
+
disconnect_irc
|
55
|
+
@spockets.remove(@irc_socket.socket) if @spockets.include?(@irc_socket)
|
56
|
+
@irc_socket.shutdown(true)
|
57
|
+
@spockets.add(@irc_socket.socket){|string| process_irc_string(string)}
|
58
|
+
else
|
59
|
+
irc_connect
|
60
|
+
end
|
42
61
|
end
|
43
62
|
|
44
63
|
def <<(message)
|
@@ -46,11 +65,14 @@ module ModSpox
|
|
46
65
|
id = $1.to_i
|
47
66
|
message = $2 + "\r\n"
|
48
67
|
sock_info = @mapped_sockets[id]
|
49
|
-
|
68
|
+
sock_info[:socket] << message
|
50
69
|
else
|
51
|
-
|
70
|
+
@irc_socket << message
|
52
71
|
end
|
53
|
-
|
72
|
+
end
|
73
|
+
|
74
|
+
def prioritize_message(target, message)
|
75
|
+
@irc_socket.prioritize_message(target, message)
|
54
76
|
end
|
55
77
|
|
56
78
|
# message:: ModSpox::Messages::Incoming::Privmsg
|
@@ -105,11 +127,9 @@ module ModSpox
|
|
105
127
|
cport, cip = Object::Socket.unpack_sockaddr_in(addrinfo)
|
106
128
|
end
|
107
129
|
Logger.info("New DCC socket created for #{message.nick.nick} has connected from: #{cip}:#{cport}")
|
108
|
-
stop_reader
|
109
130
|
@dcc_sockets << client
|
110
131
|
@mapped_sockets[client.object_id] = {:socket => client, :nick => message.nick}
|
111
|
-
@
|
112
|
-
start_reader
|
132
|
+
@spockets.add(socket){|string| process_dcc_string(string, socket)}
|
113
133
|
rescue Timeout::Error => boom
|
114
134
|
Logger.warn("Timeout reached waiting for #{message.nick.nick} to connect to DCC socket. Closing.")
|
115
135
|
client.close
|
@@ -124,13 +144,26 @@ module ModSpox
|
|
124
144
|
|
125
145
|
# Shuts down all active sockets
|
126
146
|
def shutdown
|
127
|
-
|
147
|
+
@spockets.clear
|
128
148
|
@irc_socket.shutdown
|
129
149
|
@dcc_sockets.each do |sock|
|
130
150
|
close_dcc(sock)
|
131
151
|
end
|
132
152
|
end
|
133
153
|
|
154
|
+
def disconnect_irc(m=nil)
|
155
|
+
@spockets.remove(@irc_socket.socket) if @spockets.include?(@irc_socket.socket)
|
156
|
+
end
|
157
|
+
|
158
|
+
def unqueue_messages(m)
|
159
|
+
@queue_messages = false
|
160
|
+
flush_queues
|
161
|
+
end
|
162
|
+
|
163
|
+
def queue_messages(m)
|
164
|
+
@queue_messages = true
|
165
|
+
end
|
166
|
+
|
134
167
|
private
|
135
168
|
|
136
169
|
# ip:: IP address to connect to
|
@@ -140,11 +173,9 @@ module ModSpox
|
|
140
173
|
def build_connection(ip, port, nick)
|
141
174
|
begin
|
142
175
|
socket = TCPSocket.new(ip, port)
|
143
|
-
|
144
|
-
@read_sockets << socket
|
176
|
+
@spockets.add(socket){|string| process_dcc_string(string, socket)}
|
145
177
|
@mapped_sockets[socket.object_id] = {:socket => socket, :nick => nick}
|
146
178
|
@dcc_sockets << socket
|
147
|
-
start_reader
|
148
179
|
Logger.info("New DCC connection established to #{nick.nick} on #{ip}:#{port}")
|
149
180
|
rescue Object => boom
|
150
181
|
Logger.warn("DCC connection to #{nick.nick} on #{ip}:#{port} failed. #{boom}")
|
@@ -152,58 +183,40 @@ module ModSpox
|
|
152
183
|
end
|
153
184
|
|
154
185
|
def close_dcc(sock)
|
155
|
-
@
|
186
|
+
@spockets.remove(sock)
|
156
187
|
@dcc_sockets.delete(sock)
|
157
188
|
@mapped_sockets.delete(sock.object_id)
|
158
189
|
end
|
159
190
|
|
160
|
-
def
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
@
|
165
|
-
@thread_read.kill if @thread_read.alive?
|
166
|
-
@kill = false
|
191
|
+
def process_irc_string(string)
|
192
|
+
if(@queue_messages)
|
193
|
+
@queues[:irc] << string
|
194
|
+
else
|
195
|
+
@irc_socket.process(string)
|
167
196
|
end
|
168
|
-
Logger.info('Reader thread for sockets has been stopped')
|
169
|
-
end
|
170
|
-
|
171
|
-
def restart_reader
|
172
|
-
stop_reader
|
173
|
-
start_reader
|
174
197
|
end
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
if(!@thread_read.nil? && @thread_read.alive?)
|
180
|
-
Logger.warn('ERROR: Cannot start reader. Already running.')
|
198
|
+
|
199
|
+
def process_dcc_string(string, socket)
|
200
|
+
if(@queue_messages)
|
201
|
+
@queues[:dcc] = {:string => string, :socket => socket}
|
181
202
|
else
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
tainted_string = sock.gets
|
189
|
-
string = @ic.iconv(tainted_string + ' ')[0..-2]
|
190
|
-
Logger.info("DCC >> #{string}", false)
|
191
|
-
if(sock.closed? || string.nil?)
|
192
|
-
sock.close
|
193
|
-
close_dcc(sock)
|
194
|
-
else
|
195
|
-
@pipeline << Messages::Incoming::Privmsg.new(string, @mapped_sockets[sock.object_id][:nick], "::#{sock.object_id}::", string)
|
196
|
-
end
|
197
|
-
else
|
198
|
-
@irc_socket.read
|
199
|
-
end
|
200
|
-
end
|
201
|
-
rescue Object => boom
|
202
|
-
Logger.warn("Socket error detected: #{boom}\n#{boom.backtrace}", false)
|
203
|
-
end
|
204
|
-
end
|
203
|
+
Logger.info("DCC >> #{string}")
|
204
|
+
if(socket.closed? || string.nil?)
|
205
|
+
socket.close
|
206
|
+
close_dcc(socket)
|
207
|
+
else
|
208
|
+
@pipeline << Messages::Incoming::Privmsg.new(string, @mapped_sockets[socket.object_id][:nick], "::#{sock.object_id}::", string)
|
205
209
|
end
|
206
|
-
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
def flush_queues
|
214
|
+
until(@queues[:irc].empty?)
|
215
|
+
process_irc_string(@queues[:irc].pop)
|
216
|
+
end
|
217
|
+
until(@queues[:dcc].empty?)
|
218
|
+
con = @queues[:dcc].pop
|
219
|
+
process_dcc_string(con[:string], con[:socket])
|
207
220
|
end
|
208
221
|
end
|
209
222
|
|
data/lib/mod_spox/Timer.rb
CHANGED
@@ -1,23 +1,17 @@
|
|
1
1
|
['mod_spox/Logger',
|
2
|
-
'mod_spox/Pipeline'
|
3
|
-
'mod_spox/Pool',
|
4
|
-
'mod_spox/Action',
|
5
|
-
'mod_spox/Exceptions'].each{|f|require f}
|
2
|
+
'mod_spox/Pipeline'].each{|f|require f}
|
6
3
|
|
7
4
|
module ModSpox
|
8
5
|
|
9
6
|
class Timer
|
10
7
|
|
11
|
-
#
|
12
|
-
#
|
13
|
-
|
8
|
+
# timer:: ActionTimer to use
|
9
|
+
# pipeline:: Message pipeline
|
10
|
+
# Creates a timer handler for interactions
|
11
|
+
# with the ActionTimer
|
12
|
+
def initialize(timer, pipeline)
|
14
13
|
@pipeline = pipeline
|
15
|
-
@
|
16
|
-
@timer_thread = nil
|
17
|
-
@stop_timer = false
|
18
|
-
@awake_lock = Mutex.new
|
19
|
-
@add_lock = Mutex.new
|
20
|
-
@new_actions = Queue.new
|
14
|
+
@timer = timer
|
21
15
|
{:Internal_TimerAdd => :add_message,
|
22
16
|
:Internal_TimerRemove => :remove_message,
|
23
17
|
:Internal_TimerClear => :clear}.each_pair do |type,method|
|
@@ -25,153 +19,39 @@ module ModSpox
|
|
25
19
|
end
|
26
20
|
end
|
27
21
|
|
28
|
-
# Wakes the timer up early
|
29
|
-
def wakeup
|
30
|
-
@awake_lock.synchronize do
|
31
|
-
if(@timer_thread.status == 'sleep')
|
32
|
-
Logger.info('Timer has been explicitly told to wakeup')
|
33
|
-
@timer_thread.wakeup
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
22
|
# message:: TimerAdd message
|
39
23
|
# Add a recurring code block
|
40
24
|
def add_message(message)
|
41
25
|
Logger.info("New block is being added to the timer")
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
26
|
+
begin
|
27
|
+
action = @timer.add(message.period, message.once, message.data, message.requester, &message.block)
|
28
|
+
@pipeline << Messages::Internal::TimerResponse.new(message.requester, action, true, message.id)
|
29
|
+
rescue Object => boom
|
30
|
+
Logger.error("Failed to add new block to timer: #{boom}")
|
31
|
+
@pipeline << Messages::Internal::TimerResponse.new(message.requester, nil, false, message.id)
|
32
|
+
end
|
46
33
|
end
|
47
34
|
|
48
35
|
# message:: TimerRemove message
|
49
36
|
# Remove an action from the timer
|
50
37
|
def remove_message(message)
|
51
|
-
remove(message.action)
|
38
|
+
@timer.remove(message.action)
|
52
39
|
Logger.info("Action has been removed from the Timer")
|
53
40
|
@pipeline << Messages::Internal::TimerResponse.new(nil, message.action, false, message.id)
|
54
41
|
end
|
55
42
|
|
56
|
-
# period:: seconds between running action
|
57
|
-
# once:: only run action once
|
58
|
-
# data:: data to be available
|
59
|
-
# &func:: data block to run
|
60
|
-
# Adds a new action to the timer
|
61
|
-
def add(period, once=false, data=nil, &func)
|
62
|
-
action = Action.new(self, period, data, once, &func)
|
63
|
-
@timers << action
|
64
|
-
return action
|
65
|
-
end
|
66
|
-
|
67
|
-
# action:: Action to add to timer's queue
|
68
|
-
# Adds a new action to the timer
|
69
|
-
def add_action(action)
|
70
|
-
raise Exceptions::InvalidType.new('An Action object must be supplied') unless action.is_a?(Action)
|
71
|
-
@timers << action
|
72
|
-
wakeup
|
73
|
-
end
|
74
|
-
|
75
|
-
# action:: Action to remove from timer's queue
|
76
|
-
# Removes and action from the timer
|
77
|
-
def remove(action)
|
78
|
-
raise Exceptions::InvalidType.new('An Action object must be supplied') unless action.is_a?(Action)
|
79
|
-
@timers.delete(action)
|
80
|
-
wakeup
|
81
|
-
end
|
82
|
-
|
83
|
-
# Starts the timer
|
84
|
-
def start
|
85
|
-
raise Exceptions::AlreadyRunning.new('Timer is already running') unless @timer_thread.nil?
|
86
|
-
@timer_thread = Thread.new do
|
87
|
-
begin
|
88
|
-
until @stop_timer do
|
89
|
-
to_sleep = get_min_sleep
|
90
|
-
Logger.info("Timer is set to sleep for #{to_sleep.nil? ? 'forever' : "#{to_sleep} seconds"}")
|
91
|
-
if((to_sleep.nil? || to_sleep > 0) && @new_actions.empty?)
|
92
|
-
actual_sleep = to_sleep.nil? ? sleep : sleep(to_sleep)
|
93
|
-
else
|
94
|
-
actual_sleep = 0
|
95
|
-
end
|
96
|
-
Logger.info("Timer was set to sleep for #{to_sleep.nil? ? 'forever' : "#{to_sleep} seconds"}. Actual sleep: #{actual_sleep} seconds")
|
97
|
-
tick(actual_sleep)
|
98
|
-
add_waiting_actions
|
99
|
-
end
|
100
|
-
rescue Object => boom
|
101
|
-
Logger.warn("Timer error encountered: #{boom}")
|
102
|
-
end
|
103
|
-
Logger.warn("Timer has completed running.")
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
# Stops the timer
|
108
|
-
def stop
|
109
|
-
raise Exceptions::NotRunning.new('Timer is not running') if @timer_thread.nil?
|
110
|
-
@stop_timer = true
|
111
|
-
wakeup
|
112
|
-
@timer_thread.join
|
113
|
-
end
|
114
|
-
|
115
43
|
# Clears all actions in the timer's queue
|
116
44
|
def clear(message=nil)
|
117
45
|
if(message.nil? || message.plugin.nil?)
|
118
|
-
@
|
119
|
-
@new_actions.clear
|
120
|
-
wakeup
|
46
|
+
@timer.clear
|
121
47
|
else
|
122
|
-
@
|
123
|
-
wakeup
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
private
|
128
|
-
|
129
|
-
def get_min_sleep
|
130
|
-
min = @timers.map{|t| t.remaining}.sort[0]
|
131
|
-
unless(min.nil? || min > 0)
|
132
|
-
@timers.each{|t| @timers.delete(t) if t.remaining == 0} # kill stuck actions
|
133
|
-
min = get_min_sleep
|
134
|
-
end
|
135
|
-
Logger.info("Total number of actions in timer: #{@timers.size}")
|
136
|
-
Logger.info("Actions belong to: #{@timers.map{|a| a.owner}.join(', ')}")
|
137
|
-
return min
|
138
|
-
end
|
139
|
-
|
140
|
-
def add_waiting_actions
|
141
|
-
until(@new_actions.empty?) do
|
142
|
-
a = @new_actions.pop
|
143
|
-
action = add(a[:period], a[:once], a[:data], &a[:block])
|
144
|
-
action.owner = a[:requester]
|
145
|
-
begin
|
146
|
-
@pipeline << Messages::Internal::TimerResponse.new(a[:requester], action, true, a[:m_id])
|
147
|
-
Logger.info("New block was successfully added to the timer")
|
148
|
-
rescue Object => boom
|
149
|
-
Logger.warn("Failed to add block to timer: #{boom}")
|
150
|
-
@pipeline << Messages::Internal::TimerResponse.new(a[:requester], action, false, a[:m_id])
|
151
|
-
end
|
48
|
+
@timer.clear(message.plugin)
|
152
49
|
end
|
153
50
|
end
|
154
|
-
|
155
|
-
#
|
156
|
-
|
157
|
-
|
158
|
-
for action in @timers do
|
159
|
-
action.tick(time_passed)
|
160
|
-
if(action.due?)
|
161
|
-
remove(action) if action.is_complete?
|
162
|
-
block = action.schedule
|
163
|
-
Pool << lambda{processor(block)}
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
# Process the actions
|
169
|
-
def processor(action)
|
170
|
-
begin
|
171
|
-
action.run
|
172
|
-
rescue Object => boom
|
173
|
-
Logger.warn("Timer block generated an exception: #{boom}\n#{boom.backtrace.join("\n")}")
|
174
|
-
end
|
51
|
+
|
52
|
+
# stop the timer
|
53
|
+
def stop
|
54
|
+
@timer.stop
|
175
55
|
end
|
176
56
|
|
177
57
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ModSpox
|
2
|
+
@botversion='0.3.0'
|
3
|
+
@botcodename='potato flamer'
|
4
|
+
@verbosity = 0
|
5
|
+
@mod_spox_path = nil
|
6
|
+
@daemon_bot = false
|
7
|
+
@logto = nil
|
8
|
+
@loglevel = :fatal
|
9
|
+
@jdbc = false
|
10
|
+
class << self
|
11
|
+
attr_reader :botversion, :botcodename
|
12
|
+
attr_accessor :verbosity, :mod_spox_path, :daemon_bot, :logto, :loglevel, :jdbc
|
13
|
+
end
|
14
|
+
end
|
@@ -6,7 +6,7 @@ module ModSpox
|
|
6
6
|
handlers[ERR_ERRONEOUSNICKNAME] = self
|
7
7
|
end
|
8
8
|
def process(string)
|
9
|
-
if(string =~ /#{
|
9
|
+
if(string =~ /#{ERR_ERRONEOUSNICKNAME}\s\S+\s(\S+)\s:/)
|
10
10
|
return Messages::Incoming::BadNick.new(string, $1)
|
11
11
|
else
|
12
12
|
Logger.warn('Failed to process RPL_ERRORONEOUSNICK message')
|
@@ -7,11 +7,11 @@ module ModSpox
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def process(string)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
orig = string.dup
|
11
|
+
2.times{string.slice!(0..string.index(' '))}
|
12
|
+
server = string.slice!(0..string.index(',')-1)
|
13
|
+
string.slice!(0..string.index(' ',4))
|
14
|
+
return Messages::Incoming::Bounce.new(orig, server, string)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|