newton 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/README.md +1 -1
- data/examples/memo.rb +0 -4
- data/lib/newton/bot.rb +10 -10
- data/lib/newton/callback.rb +3 -3
- data/lib/newton/irc.rb +10 -0
- data/lib/newton/user.rb +5 -0
- metadata +3 -3
data/README.md
CHANGED
@@ -119,7 +119,7 @@ unformatted log output of IRC commands? Help is on its way! Newton
|
|
119
119
|
will by default output colorized logs if printing to a terminal –
|
120
120
|
output redirected to a file or pipe will remain without color codes.
|
121
121
|
|
122
|
-
###
|
122
|
+
### Custom logging
|
123
123
|
|
124
124
|
If you want to print debug statements, you can use
|
125
125
|
`FormattedLogger.debug(message)`.
|
data/examples/memo.rb
CHANGED
data/lib/newton/bot.rb
CHANGED
@@ -173,7 +173,8 @@ module Newton
|
|
173
173
|
# though
|
174
174
|
#
|
175
175
|
# @return [void]
|
176
|
-
def on(event,
|
176
|
+
def on(event, regexps = [], *args, &block)
|
177
|
+
regexps = [*regexps]
|
177
178
|
regexps = [//] if regexps.empty?
|
178
179
|
|
179
180
|
event = event.to_sym
|
@@ -186,7 +187,7 @@ module Newton
|
|
186
187
|
regexp
|
187
188
|
end
|
188
189
|
end
|
189
|
-
(@events[event] ||= []) << [regexps, block]
|
190
|
+
(@events[event] ||= []) << [regexps, args, block]
|
190
191
|
end
|
191
192
|
|
192
193
|
# Define helper methods in the context of the bot.
|
@@ -304,8 +305,7 @@ module Newton
|
|
304
305
|
def dispatch(event, msg = nil)
|
305
306
|
if handlers = find(event, msg)
|
306
307
|
handlers.each do |handler|
|
307
|
-
regexps, block = *handler
|
308
|
-
|
308
|
+
regexps, args, block = *handler
|
309
309
|
# calling Message#match multiple times is not a problem
|
310
310
|
# because we cache the result
|
311
311
|
if msg
|
@@ -315,7 +315,7 @@ module Newton
|
|
315
315
|
captures = []
|
316
316
|
end
|
317
317
|
|
318
|
-
invoke(block, msg, captures)
|
318
|
+
invoke(block, args, msg, captures)
|
319
319
|
end
|
320
320
|
end
|
321
321
|
end
|
@@ -327,27 +327,27 @@ module Newton
|
|
327
327
|
return events
|
328
328
|
end
|
329
329
|
|
330
|
-
events.select { |regexps
|
331
|
-
regexps.any? { |regexp|
|
330
|
+
events.select { |regexps|
|
331
|
+
regexps.first.any? { |regexp|
|
332
332
|
msg.match(regexp, type)
|
333
333
|
}
|
334
334
|
}
|
335
335
|
end
|
336
336
|
end
|
337
337
|
|
338
|
-
def invoke(block, msg, match)
|
338
|
+
def invoke(block, args, msg, match)
|
339
339
|
# -1 splat arg, send everything
|
340
340
|
# 0 no args, send nothing
|
341
341
|
# 1 defined number of args, send only those
|
342
342
|
bargs = case block.arity <=> 0
|
343
343
|
when -1; match
|
344
344
|
when 0; []
|
345
|
-
when 1; match[0..block.arity-1]
|
345
|
+
when 1; match[0..block.arity-1 - args.size]
|
346
346
|
end
|
347
347
|
Thread.new do
|
348
348
|
begin
|
349
349
|
catch(:halt) do
|
350
|
-
Callback.new(block, msg, self).call(*bargs)
|
350
|
+
Callback.new(block, args, msg, self).call(*bargs)
|
351
351
|
end
|
352
352
|
rescue => e
|
353
353
|
FormattedLogger.debug "#{e.backtrace.first}: #{e.message} (#{e.class})"
|
data/lib/newton/callback.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Newton
|
2
2
|
# @api private
|
3
3
|
class Callback
|
4
|
-
def initialize(block, msg, bot)
|
5
|
-
@block, @msg, @bot, @bargs = block, msg, bot
|
4
|
+
def initialize(block, args, msg, bot)
|
5
|
+
@block, @args, @msg, @bot, @bargs = block, args, msg, bot
|
6
6
|
end
|
7
7
|
|
8
8
|
# @return [void]
|
9
9
|
def call(*bargs)
|
10
|
-
instance_exec(*bargs, &@block)
|
10
|
+
instance_exec(*@args, *bargs, &@block)
|
11
11
|
end
|
12
12
|
|
13
13
|
# Forwards method calls to the current message and bot instance.
|
data/lib/newton/irc.rb
CHANGED
@@ -75,6 +75,16 @@ module Newton
|
|
75
75
|
[:message, :private]
|
76
76
|
end)
|
77
77
|
|
78
|
+
dispatch_msg = msg
|
79
|
+
elsif msg.command == "NOTICE"
|
80
|
+
events.concat(if msg.ctcp?
|
81
|
+
[:ctcp]
|
82
|
+
elsif msg.channel?
|
83
|
+
[:notice, :channel]
|
84
|
+
else
|
85
|
+
[:notice, :private]
|
86
|
+
end)
|
87
|
+
|
78
88
|
dispatch_msg = msg
|
79
89
|
elsif msg.command == "PING"
|
80
90
|
events << :ping
|
data/lib/newton/user.rb
CHANGED
@@ -115,6 +115,11 @@ module Newton
|
|
115
115
|
@data[:authname]
|
116
116
|
end
|
117
117
|
|
118
|
+
# @see Syncable#attr
|
119
|
+
def attr(attribute, data = true, unsync = false)
|
120
|
+
super
|
121
|
+
end
|
122
|
+
|
118
123
|
# Queries the IRC server for information on the user. This will
|
119
124
|
# set the User's state to not synced. After all information are
|
120
125
|
# received, the object will be set back to synced.
|
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
|
- Dominik Honnef
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-20 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|