rubot 0.0.1 → 0.0.2
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/lib/extensions.rb +1 -0
- data/lib/extensions/object.rb +7 -0
- data/lib/irc.rb +1 -0
- data/lib/irc/message_queue.rb +40 -0
- data/lib/irc/server.rb +17 -5
- metadata +5 -3
data/lib/extensions.rb
CHANGED
data/lib/irc.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Rubot
|
2
|
+
module Irc
|
3
|
+
class MessageQueue
|
4
|
+
attr_accessor :delay
|
5
|
+
|
6
|
+
def initialize(delay)
|
7
|
+
@delay = delay
|
8
|
+
@lock = Mutex.new
|
9
|
+
@queue = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(method, *args, &block)
|
13
|
+
if block
|
14
|
+
eigen_class.instance_eval do
|
15
|
+
define_method method do |destination, *messages|
|
16
|
+
messages.flatten.each do |message|
|
17
|
+
@queue << {:block => block, :destination => destination, :message => message}
|
18
|
+
end
|
19
|
+
@lock.synchronize do
|
20
|
+
@thread = Thread.new { flush } unless @thread && @thread.alive?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
nil
|
25
|
+
else
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def flush
|
32
|
+
until @queue.empty?
|
33
|
+
element = @queue.shift
|
34
|
+
element[:block].call(element[:destination], element[:message])
|
35
|
+
sleep @delay unless @queue.empty?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/irc/server.rb
CHANGED
@@ -12,6 +12,16 @@ module Rubot
|
|
12
12
|
end
|
13
13
|
@channels = @channels.split(",").collect(&:strip)
|
14
14
|
@dispatcher = dispatcher
|
15
|
+
|
16
|
+
@message_queue = MessageQueue.new(@message_delay)
|
17
|
+
|
18
|
+
@message_queue.message do |destination, message|
|
19
|
+
raw "PRIVMSG #{destination} :#{message}"
|
20
|
+
end
|
21
|
+
|
22
|
+
@message_queue.action do |destination, action|
|
23
|
+
raw "PRIVMSG #{destination} :\001ACTION #{action}\001"
|
24
|
+
end
|
15
25
|
end
|
16
26
|
|
17
27
|
def connect
|
@@ -55,14 +65,16 @@ module Rubot
|
|
55
65
|
end
|
56
66
|
|
57
67
|
def msg(destination, message)
|
58
|
-
message
|
59
|
-
|
60
|
-
|
61
|
-
|
68
|
+
@message_queue.message(destination, message)
|
69
|
+
#message = message.to_s.split("\n") unless message.is_a? Array
|
70
|
+
#build_message_array(message).each do |l|
|
71
|
+
# raw "PRIVMSG #{destination} :#{l}"
|
72
|
+
#end
|
62
73
|
end
|
63
74
|
|
64
75
|
def action(destination, message)
|
65
|
-
|
76
|
+
@message_queue.action(destination, message)
|
77
|
+
#msg(destination, "\001ACTION #{message}\001")
|
66
78
|
end
|
67
79
|
|
68
80
|
def raw(message)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Chris Thorn
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-18 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -33,11 +33,13 @@ files:
|
|
33
33
|
- lib/core/runner.rb
|
34
34
|
- lib/core.rb
|
35
35
|
- lib/extensions/kernel.rb
|
36
|
+
- lib/extensions/object.rb
|
36
37
|
- lib/extensions/string.rb
|
37
38
|
- lib/extensions.rb
|
38
39
|
- lib/init/bundler.rb
|
39
40
|
- lib/irc/constants.rb
|
40
41
|
- lib/irc/message.rb
|
42
|
+
- lib/irc/message_queue.rb
|
41
43
|
- lib/irc/server.rb
|
42
44
|
- lib/irc.rb
|
43
45
|
- lib/rubot.rb
|