grinch 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/cinch.rb +7 -5
- data/lib/cinch/ban.rb +6 -2
- data/lib/cinch/bot.rb +21 -31
- data/lib/cinch/cached_list.rb +2 -0
- data/lib/cinch/callback.rb +2 -0
- data/lib/cinch/channel.rb +43 -44
- data/lib/cinch/channel_list.rb +2 -0
- data/lib/cinch/configuration.rb +8 -6
- data/lib/cinch/configuration/bot.rb +35 -33
- data/lib/cinch/configuration/dcc.rb +4 -2
- data/lib/cinch/configuration/plugins.rb +8 -6
- data/lib/cinch/configuration/sasl.rb +6 -4
- data/lib/cinch/configuration/ssl.rb +7 -5
- data/lib/cinch/configuration/timeouts.rb +4 -2
- data/lib/cinch/constants.rb +3 -1
- data/lib/cinch/dcc.rb +2 -0
- data/lib/cinch/dcc/dccable_object.rb +6 -8
- data/lib/cinch/dcc/incoming.rb +2 -0
- data/lib/cinch/dcc/incoming/send.rb +10 -8
- data/lib/cinch/dcc/outgoing.rb +2 -0
- data/lib/cinch/dcc/outgoing/send.rb +13 -14
- data/lib/cinch/exceptions.rb +2 -0
- data/lib/cinch/formatting.rb +32 -30
- data/lib/cinch/handler.rb +15 -13
- data/lib/cinch/handler_list.rb +13 -13
- data/lib/cinch/helpers.rb +16 -16
- data/lib/cinch/irc.rb +118 -142
- data/lib/cinch/isupport.rb +22 -20
- data/lib/cinch/log_filter.rb +3 -2
- data/lib/cinch/logger.rb +7 -2
- data/lib/cinch/logger/formatted_logger.rb +17 -13
- data/lib/cinch/logger/zcbot_logger.rb +4 -0
- data/lib/cinch/logger_list.rb +15 -14
- data/lib/cinch/mask.rb +11 -9
- data/lib/cinch/message.rb +6 -6
- data/lib/cinch/message_queue.rb +5 -4
- data/lib/cinch/mode_parser.rb +7 -5
- data/lib/cinch/network.rb +2 -0
- data/lib/cinch/open_ended_queue.rb +5 -5
- data/lib/cinch/pattern.rb +11 -8
- data/lib/cinch/plugin.rb +43 -49
- data/lib/cinch/plugin_list.rb +4 -4
- data/lib/cinch/rubyext/float.rb +3 -3
- data/lib/cinch/rubyext/module.rb +2 -0
- data/lib/cinch/rubyext/string.rb +8 -6
- data/lib/cinch/sasl.rb +2 -0
- data/lib/cinch/sasl/dh_blowfish.rb +5 -3
- data/lib/cinch/sasl/diffie_hellman.rb +6 -3
- data/lib/cinch/sasl/mechanism.rb +2 -0
- data/lib/cinch/sasl/plain.rb +2 -0
- data/lib/cinch/syncable.rb +10 -9
- data/lib/cinch/target.rb +15 -17
- data/lib/cinch/timer.rb +9 -7
- data/lib/cinch/user.rb +52 -48
- data/lib/cinch/user_list.rb +8 -11
- data/lib/cinch/utilities/deprecation.rb +5 -5
- data/lib/cinch/utilities/encoding.rb +9 -9
- data/lib/cinch/utilities/kernel.rb +4 -1
- data/lib/cinch/version.rb +3 -1
- metadata +4 -4
data/lib/cinch/handler.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Cinch
|
2
4
|
# @since 2.0.0
|
3
5
|
class Handler
|
@@ -39,16 +41,16 @@ module Cinch
|
|
39
41
|
# @option options [Array] :args ([]) Additional arguments to pass
|
40
42
|
# to the block
|
41
43
|
def initialize(bot, event, pattern, options = {}, &block)
|
42
|
-
options
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
44
|
+
options = {
|
45
|
+
group: nil,
|
46
|
+
execute_in_callback: false,
|
47
|
+
strip_colors: false,
|
48
|
+
args: [],
|
47
49
|
}.merge(options)
|
48
|
-
@bot
|
49
|
-
@event
|
50
|
-
@pattern
|
51
|
-
@group
|
50
|
+
@bot = bot
|
51
|
+
@event = event
|
52
|
+
@pattern = pattern
|
53
|
+
@group = options[:group]
|
52
54
|
@execute_in_callback = options[:execute_in_callback]
|
53
55
|
@strip_colors = options[:strip_colors]
|
54
56
|
@args = options[:args]
|
@@ -89,7 +91,7 @@ module Cinch
|
|
89
91
|
def call(message, captures, arguments)
|
90
92
|
bargs = captures + arguments
|
91
93
|
|
92
|
-
thread = Thread.new
|
94
|
+
thread = Thread.new do
|
93
95
|
@bot.loggers.debug "[New thread] For #{self}: #{Thread.current} -- #{@thread_group.list.size} in total."
|
94
96
|
|
95
97
|
begin
|
@@ -98,12 +100,12 @@ module Cinch
|
|
98
100
|
else
|
99
101
|
@block.call(message, *@args, *bargs)
|
100
102
|
end
|
101
|
-
rescue => e
|
103
|
+
rescue StandardError => e
|
102
104
|
@bot.loggers.exception(e)
|
103
105
|
ensure
|
104
106
|
@bot.loggers.debug "[Thread done] For #{self}: #{Thread.current} -- #{@thread_group.list.size - 1} remaining."
|
105
107
|
end
|
106
|
-
|
108
|
+
end
|
107
109
|
|
108
110
|
@thread_group.add(thread)
|
109
111
|
thread
|
@@ -111,7 +113,7 @@ module Cinch
|
|
111
113
|
|
112
114
|
# @return [String]
|
113
115
|
def to_s
|
114
|
-
# TODO maybe add the number of running threads to the output?
|
116
|
+
# TODO: maybe add the number of running threads to the output?
|
115
117
|
"#<Cinch::Handler @event=#{@event.inspect} pattern=#{@pattern.inspect}>"
|
116
118
|
end
|
117
119
|
end
|
data/lib/cinch/handler_list.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "set"
|
3
4
|
require "cinch/cached_list"
|
4
5
|
|
@@ -8,7 +9,7 @@ module Cinch
|
|
8
9
|
include Enumerable
|
9
10
|
|
10
11
|
def initialize
|
11
|
-
@handlers = Hash.new {|h,k| h[k] = []}
|
12
|
+
@handlers = Hash.new { |h, k| h[k] = [] }
|
12
13
|
@mutex = Mutex.new
|
13
14
|
end
|
14
15
|
|
@@ -34,13 +35,11 @@ module Cinch
|
|
34
35
|
# @return [Array<Handler>]
|
35
36
|
def find(type, msg = nil)
|
36
37
|
if handlers = @handlers[type]
|
37
|
-
if msg.nil?
|
38
|
-
return handlers
|
39
|
-
end
|
38
|
+
return handlers if msg.nil?
|
40
39
|
|
41
|
-
handlers = handlers.select
|
40
|
+
handlers = handlers.select do |handler|
|
42
41
|
msg.match(handler.pattern.to_r(msg), type, handler.strip_colors)
|
43
|
-
|
42
|
+
end.group_by(&:group)
|
44
43
|
|
45
44
|
handlers.values_at(*(handlers.keys - [nil])).map(&:first) + (handlers[nil] || [])
|
46
45
|
end
|
@@ -59,14 +58,15 @@ module Cinch
|
|
59
58
|
already_run = Set.new
|
60
59
|
handlers.each do |handler|
|
61
60
|
next if already_run.include?(handler.block)
|
61
|
+
|
62
62
|
already_run << handler.block
|
63
63
|
# calling Message#match multiple times is not a problem
|
64
64
|
# because we cache the result
|
65
|
-
if msg
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
captures = if msg
|
66
|
+
msg.match(handler.pattern.to_r(msg), event, handler.strip_colors).captures
|
67
|
+
else
|
68
|
+
[]
|
69
|
+
end
|
70
70
|
|
71
71
|
threads << handler.call(msg, captures, arguments)
|
72
72
|
end
|
@@ -84,7 +84,7 @@ module Cinch
|
|
84
84
|
|
85
85
|
# @api private
|
86
86
|
def stop_all
|
87
|
-
each
|
87
|
+
each(&:stop)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
data/lib/cinch/helpers.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Cinch
|
3
4
|
# The Helpers module contains a number of methods whose purpose is
|
4
5
|
# to make writing plugins easier by hiding parts of the API. The
|
@@ -22,6 +23,7 @@ module Cinch
|
|
22
23
|
# @since 2.0.0
|
23
24
|
def Target(target)
|
24
25
|
return target if target.is_a?(Target)
|
26
|
+
|
25
27
|
Target.new(target, bot)
|
26
28
|
end
|
27
29
|
|
@@ -36,6 +38,7 @@ module Cinch
|
|
36
38
|
# @since 1.0.0
|
37
39
|
def Channel(channel)
|
38
40
|
return channel if channel.is_a?(Channel)
|
41
|
+
|
39
42
|
bot.channel_list.find_ensured(channel)
|
40
43
|
end
|
41
44
|
|
@@ -51,6 +54,7 @@ module Cinch
|
|
51
54
|
# @since 1.0.0
|
52
55
|
def User(user)
|
53
56
|
return user if user.is_a?(User)
|
57
|
+
|
54
58
|
if user == bot.nick
|
55
59
|
bot
|
56
60
|
else
|
@@ -91,14 +95,12 @@ module Cinch
|
|
91
95
|
# @return [Timer]
|
92
96
|
# @since 2.0.0
|
93
97
|
def Timer(interval, options = {}, &block)
|
94
|
-
options = {:
|
95
|
-
block ||=
|
98
|
+
options = { method: :timer, threaded: true, interval: interval }.merge(options)
|
99
|
+
block ||= method(options[:method])
|
96
100
|
timer = Cinch::Timer.new(bot, options, &block)
|
97
101
|
timer.start
|
98
102
|
|
99
|
-
if
|
100
|
-
timers << timer
|
101
|
-
end
|
103
|
+
timers << timer if respond_to?(:timers)
|
102
104
|
|
103
105
|
timer
|
104
106
|
end
|
@@ -119,19 +121,17 @@ module Cinch
|
|
119
121
|
# @return [void]
|
120
122
|
# @since 2.0.0
|
121
123
|
def rescue_exception
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
bot.loggers.exception(e)
|
126
|
-
end
|
124
|
+
yield
|
125
|
+
rescue StandardError => e
|
126
|
+
bot.loggers.exception(e)
|
127
127
|
end
|
128
128
|
|
129
129
|
# (see Logger#log)
|
130
130
|
def log(messages, event = :debug, level = event)
|
131
|
-
if
|
132
|
-
messages = Array(messages).map
|
131
|
+
if is_a?(Cinch::Plugin)
|
132
|
+
messages = Array(messages).map do |m|
|
133
133
|
"[#{self.class}] " + m
|
134
|
-
|
134
|
+
end
|
135
135
|
end
|
136
136
|
@bot.loggers.log(messages, event, level)
|
137
137
|
end
|
@@ -183,7 +183,7 @@ module Cinch
|
|
183
183
|
def Format(*settings, string)
|
184
184
|
Formatting.format(*settings, string)
|
185
185
|
end
|
186
|
-
|
186
|
+
alias Color Format # deprecated
|
187
187
|
undef_method(:Color) # yardoc hack
|
188
188
|
|
189
189
|
def Color(*args)
|
@@ -218,7 +218,7 @@ module Cinch
|
|
218
218
|
# @return [String] The filtered string
|
219
219
|
# @since 2.2.0
|
220
220
|
def self.sanitize(string)
|
221
|
-
string.gsub(/[\x00-\x08\x0a-\x1f\x7f]/,
|
221
|
+
string.gsub(/[\x00-\x08\x0a-\x1f\x7f]/, "")
|
222
222
|
end
|
223
223
|
|
224
224
|
# (see Formatting.unformat)
|
data/lib/cinch/irc.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "timeout"
|
2
4
|
require "net/protocol"
|
3
5
|
require "cinch/network"
|
@@ -46,7 +48,7 @@ module Cinch
|
|
46
48
|
tcp_socket = nil
|
47
49
|
|
48
50
|
begin
|
49
|
-
Timeout
|
51
|
+
Timeout.timeout(@bot.config.timeouts.connect) do
|
50
52
|
tcp_socket = TCPSocket.new(@bot.config.server, @bot.config.port, @bot.config.local_host)
|
51
53
|
end
|
52
54
|
rescue Timeout::Error
|
@@ -55,7 +57,7 @@ module Cinch
|
|
55
57
|
rescue SocketError => e
|
56
58
|
@bot.loggers.warn("Could not connect to the IRC server. Please check your network: #{e.message}")
|
57
59
|
return false
|
58
|
-
rescue => e
|
60
|
+
rescue StandardError => e
|
59
61
|
@bot.loggers.exception(e)
|
60
62
|
return false
|
61
63
|
end
|
@@ -70,7 +72,7 @@ module Cinch
|
|
70
72
|
@socket.read_timeout = @bot.config.timeouts.read
|
71
73
|
@queue = MessageQueue.new(@socket, @bot)
|
72
74
|
|
73
|
-
|
75
|
+
true
|
74
76
|
end
|
75
77
|
|
76
78
|
# @api private
|
@@ -79,7 +81,7 @@ module Cinch
|
|
79
81
|
def setup_ssl(socket)
|
80
82
|
# require openssl in this method so the bot doesn't break for
|
81
83
|
# people who don't have SSL but don't want to use SSL anyway.
|
82
|
-
require
|
84
|
+
require "openssl"
|
83
85
|
|
84
86
|
ssl_context = OpenSSL::SSL::SSLContext.new
|
85
87
|
|
@@ -112,11 +114,11 @@ module Cinch
|
|
112
114
|
# @return [void]
|
113
115
|
# @since 2.0.0
|
114
116
|
def send_cap_req
|
115
|
-
caps = [
|
117
|
+
caps = %i[away-notify multi-prefix sasl twitch.tv/tags] & @network.capabilities
|
116
118
|
|
117
119
|
# InspIRCd doesn't respond to empty REQs, so send an END in that
|
118
120
|
# case.
|
119
|
-
if caps.
|
121
|
+
if !caps.empty?
|
120
122
|
send "CAP REQ :" + caps.join(" ")
|
121
123
|
else
|
122
124
|
send_cap_end
|
@@ -155,13 +157,13 @@ module Cinch
|
|
155
157
|
@bot.loggers.warn "Connection timed out."
|
156
158
|
rescue EOFError
|
157
159
|
@bot.loggers.warn "Lost connection."
|
158
|
-
rescue => e
|
160
|
+
rescue StandardError => e
|
159
161
|
@bot.loggers.exception(e)
|
160
162
|
end
|
161
163
|
|
162
164
|
@socket.close
|
163
165
|
@bot.handlers.dispatch(:disconnect)
|
164
|
-
# FIXME won't we kill all :disconnect handlers here? prolly
|
166
|
+
# FIXME: won't we kill all :disconnect handlers here? prolly
|
165
167
|
# not, as they have 10 seconds to finish. that should be
|
166
168
|
# plenty of time
|
167
169
|
@bot.handlers.stop_all
|
@@ -184,7 +186,7 @@ module Cinch
|
|
184
186
|
# @since 2.0.0
|
185
187
|
def start_ping_thread
|
186
188
|
Thread.new do
|
187
|
-
|
189
|
+
loop do
|
188
190
|
sleep @bot.config.ping_interval
|
189
191
|
# PING requires a single argument. In our case the value
|
190
192
|
# doesn't matter though.
|
@@ -228,12 +230,13 @@ module Cinch
|
|
228
230
|
# @return [void]
|
229
231
|
def parse(input)
|
230
232
|
return if input.chomp.empty?
|
233
|
+
|
231
234
|
@bot.loggers.incoming(input)
|
232
235
|
|
233
236
|
msg = Message.new(input, @bot)
|
234
237
|
events = [[:catchall]]
|
235
238
|
|
236
|
-
if [
|
239
|
+
if %w[001 002 003 004 422].include?(msg.command)
|
237
240
|
@registration << msg.command
|
238
241
|
if registered?
|
239
242
|
events << [:connect]
|
@@ -242,29 +245,23 @@ module Cinch
|
|
242
245
|
end
|
243
246
|
end
|
244
247
|
|
245
|
-
if [
|
248
|
+
if %w[PRIVMSG NOTICE].include?(msg.command)
|
246
249
|
events << [:ctcp] if msg.ctcp?
|
247
|
-
if msg.channel?
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
250
|
+
events << if msg.channel?
|
251
|
+
[:channel]
|
252
|
+
else
|
253
|
+
[:private]
|
254
|
+
end
|
252
255
|
|
253
|
-
if msg.command == "PRIVMSG"
|
254
|
-
events << [:message]
|
255
|
-
end
|
256
|
+
events << [:message] if msg.command == "PRIVMSG"
|
256
257
|
|
257
|
-
if msg.action?
|
258
|
-
events << [:action]
|
259
|
-
end
|
258
|
+
events << [:action] if msg.action?
|
260
259
|
end
|
261
260
|
|
262
261
|
meth = "on_#{msg.command.downcase}"
|
263
262
|
__send__(meth, msg, events) if respond_to?(meth, true)
|
264
263
|
|
265
|
-
if msg.error?
|
266
|
-
events << [:error]
|
267
|
-
end
|
264
|
+
events << [:error] if msg.error?
|
268
265
|
|
269
266
|
events << [msg.command.downcase.to_sym]
|
270
267
|
|
@@ -287,7 +284,8 @@ module Cinch
|
|
287
284
|
end
|
288
285
|
|
289
286
|
private
|
290
|
-
|
287
|
+
|
288
|
+
def set_leaving_user(_message, user, events)
|
291
289
|
events << [:leaving, user]
|
292
290
|
end
|
293
291
|
|
@@ -299,20 +297,20 @@ module Cinch
|
|
299
297
|
case event
|
300
298
|
when "002"
|
301
299
|
if msg.params.last =~ /^Your host is .+?, running version (.+)$/
|
302
|
-
case
|
300
|
+
case Regexp.last_match(1)
|
303
301
|
when /\+snircd\(/
|
304
302
|
new_ircd = :snircd
|
305
303
|
when /^u[\d\.]+$/
|
306
304
|
new_ircd = :ircu
|
307
305
|
when /^(.+?)-?\d+/
|
308
|
-
new_ircd =
|
306
|
+
new_ircd = Regexp.last_match(1).downcase.to_sym
|
309
307
|
end
|
310
308
|
elsif msg.params.last == "Your host is jtvchat"
|
311
309
|
new_network = :jtv
|
312
310
|
new_ircd = :jtv
|
313
311
|
end
|
314
312
|
when "004"
|
315
|
-
if msg.params == %w
|
313
|
+
if msg.params == %w[irc.tinyspeck.com IRC-SLACK gateway]
|
316
314
|
new_network = :slack
|
317
315
|
new_ircd = :slack
|
318
316
|
end
|
@@ -355,7 +353,7 @@ module Cinch
|
|
355
353
|
msg.channel.bans_unsynced << ban
|
356
354
|
events << [:ban, ban]
|
357
355
|
else
|
358
|
-
msg.channel.bans_unsynced.delete_if {|b| b.mask == ban.mask}
|
356
|
+
msg.channel.bans_unsynced.delete_if { |b| b.mask == ban.mask }
|
359
357
|
events << [:unban, ban]
|
360
358
|
end
|
361
359
|
end
|
@@ -390,7 +388,7 @@ module Cinch
|
|
390
388
|
end
|
391
389
|
|
392
390
|
# @since 2.0.0
|
393
|
-
def on_cap(msg,
|
391
|
+
def on_cap(msg, _events)
|
394
392
|
case msg.params[1]
|
395
393
|
when "LS"
|
396
394
|
@network.capabilities.concat msg.message.split(" ").map(&:to_sym)
|
@@ -407,11 +405,11 @@ module Cinch
|
|
407
405
|
end
|
408
406
|
|
409
407
|
# @since 2.0.0
|
410
|
-
def on_connect(
|
408
|
+
def on_connect(_msg, _events)
|
411
409
|
@bot.modes = @bot.config.modes
|
412
410
|
end
|
413
411
|
|
414
|
-
def on_join(msg,
|
412
|
+
def on_join(msg, _events)
|
415
413
|
if msg.user == @bot
|
416
414
|
@bot.channels << msg.channel
|
417
415
|
msg.channel.sync_modes
|
@@ -422,9 +420,7 @@ module Cinch
|
|
422
420
|
|
423
421
|
def on_kick(msg, events)
|
424
422
|
target = User(msg.params[1])
|
425
|
-
if target == @bot
|
426
|
-
@bot.channels.delete(msg.channel)
|
427
|
-
end
|
423
|
+
@bot.channels.delete(msg.channel) if target == @bot
|
428
424
|
msg.channel.remove_user(target)
|
429
425
|
|
430
426
|
set_leaving_user(msg, target, events)
|
@@ -449,23 +445,20 @@ module Cinch
|
|
449
445
|
parse_channel_modes(msg, events)
|
450
446
|
return
|
451
447
|
end
|
452
|
-
if msg.params.first == bot.nick
|
453
|
-
parse_bot_modes(msg)
|
454
|
-
end
|
448
|
+
parse_bot_modes(msg) if msg.params.first == bot.nick
|
455
449
|
end
|
456
450
|
|
457
451
|
def parse_channel_modes(msg, events)
|
458
452
|
add_and_remove = @bot.irc.isupport["CHANMODES"]["A"] + @bot.irc.isupport["CHANMODES"]["B"] + @bot.irc.isupport["PREFIX"].keys
|
459
453
|
|
460
454
|
param_modes = {
|
461
|
-
:
|
462
|
-
:
|
455
|
+
add: @bot.irc.isupport["CHANMODES"]["C"] + add_and_remove,
|
456
|
+
remove: add_and_remove,
|
463
457
|
}
|
464
458
|
|
465
|
-
|
466
459
|
modes, err = ModeParser.parse_modes(msg.params[1], msg.params[2..-1], param_modes)
|
467
|
-
|
468
|
-
if
|
460
|
+
unless err.nil?
|
461
|
+
if @network.ircd != :slack || !err.is_a?(ModeParser::TooManyParametersError)
|
469
462
|
raise Exceptions::InvalidModeString, err
|
470
463
|
end
|
471
464
|
end
|
@@ -483,9 +476,9 @@ module Cinch
|
|
483
476
|
user_events = {
|
484
477
|
"o" => "op",
|
485
478
|
"v" => "voice",
|
486
|
-
"h" => "halfop"
|
479
|
+
"h" => "halfop",
|
487
480
|
}
|
488
|
-
if user_events.
|
481
|
+
if user_events.key?(mode)
|
489
482
|
event = (direction == :add ? "" : "de") + user_events[mode]
|
490
483
|
events << [event.to_sym, target]
|
491
484
|
end
|
@@ -513,9 +506,8 @@ module Cinch
|
|
513
506
|
|
514
507
|
def parse_bot_modes(msg)
|
515
508
|
modes, err = ModeParser.parse_modes(msg.params[1], msg.params[2..-1])
|
516
|
-
|
517
|
-
|
518
|
-
end
|
509
|
+
raise Exceptions::InvalidModeString, err unless err.nil?
|
510
|
+
|
519
511
|
modes.each do |direction, mode, _|
|
520
512
|
if direction == :add
|
521
513
|
@bot.modes << mode unless @bot.modes.include?(mode)
|
@@ -525,13 +517,13 @@ module Cinch
|
|
525
517
|
end
|
526
518
|
end
|
527
519
|
|
528
|
-
def on_nick(msg,
|
529
|
-
if msg.user == @bot
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
520
|
+
def on_nick(msg, _events)
|
521
|
+
target = if msg.user == @bot
|
522
|
+
# @bot.set_nick msg.params.last
|
523
|
+
@bot
|
524
|
+
else
|
525
|
+
msg.user
|
526
|
+
end
|
535
527
|
|
536
528
|
target.update_nick(msg.params.last)
|
537
529
|
target.online = true
|
@@ -541,18 +533,16 @@ module Cinch
|
|
541
533
|
msg.channel.remove_user(msg.user)
|
542
534
|
msg.user.channels_unsynced.delete msg.channel
|
543
535
|
|
544
|
-
if msg.user == @bot
|
545
|
-
@bot.channels.delete(msg.channel)
|
546
|
-
end
|
536
|
+
@bot.channels.delete(msg.channel) if msg.user == @bot
|
547
537
|
|
548
538
|
set_leaving_user(msg, msg.user, events)
|
549
539
|
end
|
550
540
|
|
551
|
-
def on_ping(msg,
|
541
|
+
def on_ping(msg, _events)
|
552
542
|
send "PONG :#{msg.params.first}"
|
553
543
|
end
|
554
544
|
|
555
|
-
def on_topic(msg,
|
545
|
+
def on_topic(msg, _events)
|
556
546
|
msg.channel.sync(:topic, msg.params[1])
|
557
547
|
end
|
558
548
|
|
@@ -576,12 +566,10 @@ module Cinch
|
|
576
566
|
|
577
567
|
# @since 2.0.0
|
578
568
|
def on_privmsg(msg, events)
|
579
|
-
if msg.user
|
580
|
-
msg.user.online = true
|
581
|
-
end
|
569
|
+
msg.user.online = true if msg.user
|
582
570
|
|
583
571
|
if msg.message =~ /^\001DCC SEND (?:"([^"]+)"|(\S+)) (\S+) (\d+)(?: (\d+))?\001$/
|
584
|
-
process_dcc_send(
|
572
|
+
process_dcc_send(Regexp.last_match(1) || Regexp.last_match(2), Regexp.last_match(3), Regexp.last_match(4), Regexp.last_match(5), msg, events)
|
585
573
|
end
|
586
574
|
end
|
587
575
|
|
@@ -594,7 +582,7 @@ module Cinch
|
|
594
582
|
# If it's not valid, let someone higher up the chain notice
|
595
583
|
# that.
|
596
584
|
ip = ip.to_i
|
597
|
-
ip = [24, 16, 8, 0].collect {|b| (ip >> b) & 255}.join(
|
585
|
+
ip = [24, 16, 8, 0].collect { |b| (ip >> b) & 255 }.join(".")
|
598
586
|
end
|
599
587
|
|
600
588
|
port = port.to_i
|
@@ -607,119 +595,117 @@ module Cinch
|
|
607
595
|
end
|
608
596
|
|
609
597
|
# @since 2.0.0
|
610
|
-
def on_001(msg,
|
598
|
+
def on_001(msg, _events)
|
611
599
|
# Ensure that we know our real, possibly truncated or otherwise
|
612
600
|
# modified nick.
|
613
601
|
@bot.set_nick msg.params.first
|
614
602
|
end
|
615
603
|
|
616
604
|
# @since 2.0.0
|
617
|
-
def on_002(msg,
|
605
|
+
def on_002(msg, _events)
|
618
606
|
detect_network(msg, "002")
|
619
607
|
end
|
620
608
|
|
621
609
|
# @since 2.2.6
|
622
|
-
def on_004(msg,
|
610
|
+
def on_004(msg, _events)
|
623
611
|
detect_network(msg, "004")
|
624
612
|
end
|
625
613
|
|
626
|
-
def on_005(msg,
|
614
|
+
def on_005(msg, _events)
|
627
615
|
# ISUPPORT
|
628
|
-
@isupport.parse(*msg.params[1..-2].map {|v| v.split(" ")}.flatten)
|
616
|
+
@isupport.parse(*msg.params[1..-2].map { |v| v.split(" ") }.flatten)
|
629
617
|
detect_network(msg, "005")
|
630
618
|
end
|
631
619
|
|
632
620
|
# @since 2.0.0
|
633
|
-
def on_301(msg,
|
621
|
+
def on_301(msg, _events)
|
634
622
|
# RPL_AWAY
|
635
623
|
user = User(msg.params[1])
|
636
624
|
away = msg.params.last
|
637
625
|
|
638
|
-
if @whois_updates[user]
|
639
|
-
update_whois(user, {:away => away})
|
640
|
-
end
|
626
|
+
update_whois(user, { away: away }) if @whois_updates[user]
|
641
627
|
end
|
642
628
|
|
643
629
|
# @since 1.1.0
|
644
|
-
def on_307(msg,
|
630
|
+
def on_307(msg, _events)
|
645
631
|
# RPL_WHOISREGNICK
|
646
632
|
user = User(msg.params[1])
|
647
|
-
update_whois(user, {:
|
633
|
+
update_whois(user, { registered: true })
|
648
634
|
end
|
649
635
|
|
650
|
-
def on_311(msg,
|
636
|
+
def on_311(msg, _events)
|
651
637
|
# RPL_WHOISUSER
|
652
638
|
user = User(msg.params[1])
|
653
639
|
update_whois(user, {
|
654
|
-
:
|
655
|
-
:
|
656
|
-
:
|
640
|
+
user: msg.params[2],
|
641
|
+
host: msg.params[3],
|
642
|
+
realname: msg.params[5],
|
657
643
|
})
|
658
644
|
end
|
659
645
|
|
660
|
-
def on_313(msg,
|
646
|
+
def on_313(msg, _events)
|
661
647
|
# RPL_WHOISOPERATOR
|
662
648
|
user = User(msg.params[1])
|
663
|
-
update_whois(user, {
|
649
|
+
update_whois(user, { oper?: true })
|
664
650
|
end
|
665
651
|
|
666
|
-
def on_317(msg,
|
652
|
+
def on_317(msg, _events)
|
667
653
|
# RPL_WHOISIDLE
|
668
654
|
user = User(msg.params[1])
|
669
655
|
update_whois(user, {
|
670
|
-
:
|
671
|
-
:
|
656
|
+
idle: msg.params[2].to_i,
|
657
|
+
signed_on_at: Time.at(msg.params[3].to_i),
|
672
658
|
})
|
673
659
|
end
|
674
660
|
|
675
|
-
def on_318(msg,
|
661
|
+
def on_318(msg, _events)
|
676
662
|
# RPL_ENDOFWHOIS
|
677
663
|
user = User(msg.params[1])
|
678
664
|
user.end_of_whois(@whois_updates[user])
|
679
665
|
@whois_updates.delete user
|
680
666
|
end
|
681
667
|
|
682
|
-
def on_319(msg,
|
668
|
+
def on_319(msg, _events)
|
683
669
|
# RPL_WHOISCHANNELS
|
684
670
|
user = User(msg.params[1])
|
685
|
-
channels = msg.params[2].scan(/[#{@isupport["CHANTYPES"].join}][^ ]+/o).map {|c| Channel(c) }
|
686
|
-
update_whois(user, {:channels
|
671
|
+
channels = msg.params[2].scan(/[#{@isupport["CHANTYPES"].join}][^ ]+/o).map { |c| Channel(c) }
|
672
|
+
update_whois(user, { channels: channels })
|
687
673
|
end
|
688
674
|
|
689
|
-
def on_324(msg,
|
675
|
+
def on_324(msg, _events)
|
690
676
|
# RPL_CHANNELMODEIS
|
691
677
|
modes = {}
|
692
678
|
arguments = msg.params[3..-1]
|
693
679
|
|
694
680
|
msg.params[2][1..-1].split("").each do |mode|
|
695
|
-
if (@isupport["CHANMODES"]["B"] + @isupport["CHANMODES"]["C"]).include?(mode)
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
681
|
+
modes[mode] = if (@isupport["CHANMODES"]["B"] + @isupport["CHANMODES"]["C"]).include?(mode)
|
682
|
+
arguments.shift
|
683
|
+
else
|
684
|
+
true
|
685
|
+
end
|
700
686
|
end
|
701
687
|
|
702
688
|
msg.channel.sync(:modes, modes, false)
|
703
689
|
end
|
704
690
|
|
705
|
-
def on_330(msg,
|
691
|
+
def on_330(msg, _events)
|
706
692
|
# RPL_WHOISACCOUNT
|
707
693
|
user = User(msg.params[1])
|
708
694
|
authname = msg.params[2]
|
709
|
-
update_whois(user, {:authname
|
695
|
+
update_whois(user, { authname: authname })
|
710
696
|
end
|
711
697
|
|
712
|
-
def on_331(msg,
|
698
|
+
def on_331(msg, _events)
|
713
699
|
# RPL_NOTOPIC
|
714
700
|
msg.channel.sync(:topic, "")
|
715
701
|
end
|
716
702
|
|
717
|
-
def on_332(msg,
|
703
|
+
def on_332(msg, _events)
|
718
704
|
# RPL_TOPIC
|
719
705
|
msg.channel.sync(:topic, msg.params[2])
|
720
706
|
end
|
721
707
|
|
722
|
-
def on_352(msg,
|
708
|
+
def on_352(msg, _events)
|
723
709
|
# RPL_WHOREPLY
|
724
710
|
# "<channel> <user> <host> <server> <nick> <H|G>[*][@|+] :<hopcount> <real name>"
|
725
711
|
_, channel, user, host, _, nick, _, hopsrealname = msg.params
|
@@ -731,7 +717,7 @@ module Cinch
|
|
731
717
|
user_object.sync(:realname, realname, true)
|
732
718
|
end
|
733
719
|
|
734
|
-
def on_354(msg,
|
720
|
+
def on_354(msg, _events)
|
735
721
|
# RPL_WHOSPCRPL
|
736
722
|
# We are using the following format: %acfhnru
|
737
723
|
|
@@ -750,41 +736,37 @@ module Cinch
|
|
750
736
|
user_object.sync(:authname, account == "0" ? nil : account, true)
|
751
737
|
end
|
752
738
|
|
753
|
-
def on_353(msg,
|
739
|
+
def on_353(msg, _events)
|
754
740
|
# RPL_NAMEREPLY
|
755
|
-
unless @in_lists.include?(:names)
|
756
|
-
msg.channel.clear_users
|
757
|
-
end
|
741
|
+
msg.channel.clear_users unless @in_lists.include?(:names)
|
758
742
|
@in_lists << :names
|
759
743
|
|
760
744
|
msg.params[3].split(" ").each do |user|
|
761
745
|
m = user.match(/^([#{@isupport["PREFIX"].values.join}]+)/)
|
762
746
|
if m
|
763
|
-
prefixes = m[1].split("").map {|s| @isupport["PREFIX"].key(s)}
|
764
|
-
nick
|
747
|
+
prefixes = m[1].split("").map { |s| @isupport["PREFIX"].key(s) }
|
748
|
+
nick = user[prefixes.size..-1]
|
765
749
|
else
|
766
|
-
nick
|
750
|
+
nick = user
|
767
751
|
prefixes = []
|
768
752
|
end
|
769
|
-
user
|
753
|
+
user = User(nick)
|
770
754
|
user.online = true
|
771
755
|
msg.channel.add_user(user, prefixes)
|
772
756
|
user.channels_unsynced << msg.channel unless user.channels_unsynced.include?(msg.channel)
|
773
757
|
end
|
774
758
|
end
|
775
759
|
|
776
|
-
def on_366(msg,
|
760
|
+
def on_366(msg, _events)
|
777
761
|
# RPL_ENDOFNAMES
|
778
762
|
@in_lists.delete :names
|
779
763
|
msg.channel.mark_as_synced(:users)
|
780
764
|
end
|
781
765
|
|
782
766
|
# @version 2.0.0
|
783
|
-
def on_367(msg,
|
767
|
+
def on_367(msg, _events)
|
784
768
|
# RPL_BANLIST
|
785
|
-
unless @in_lists.include?(:bans)
|
786
|
-
msg.channel.bans_unsynced.clear
|
787
|
-
end
|
769
|
+
msg.channel.bans_unsynced.clear unless @in_lists.include?(:bans)
|
788
770
|
@in_lists << :bans
|
789
771
|
|
790
772
|
mask = msg.params[2]
|
@@ -794,18 +776,14 @@ module Cinch
|
|
794
776
|
mask = "%s!%s@%s" % [mask, mask, mask + ".irc.justin.tv"]
|
795
777
|
end
|
796
778
|
|
797
|
-
if msg.params[3]
|
798
|
-
by = User(msg.params[3].split("!").first)
|
799
|
-
else
|
800
|
-
by = nil
|
801
|
-
end
|
779
|
+
by = (User(msg.params[3].split("!").first) if msg.params[3])
|
802
780
|
|
803
781
|
at = Time.at(msg.params[4].to_i)
|
804
782
|
ban = Ban.new(mask, by, at)
|
805
783
|
msg.channel.bans_unsynced << ban
|
806
784
|
end
|
807
785
|
|
808
|
-
def on_368(msg,
|
786
|
+
def on_368(msg, _events)
|
809
787
|
# RPL_ENDOFBANLIST
|
810
788
|
if @in_lists.include?(:bans)
|
811
789
|
@in_lists.delete :bans
|
@@ -817,64 +795,62 @@ module Cinch
|
|
817
795
|
msg.channel.mark_as_synced(:bans)
|
818
796
|
end
|
819
797
|
|
820
|
-
def on_386(msg,
|
798
|
+
def on_386(msg, _events)
|
821
799
|
# RPL_QLIST
|
822
|
-
unless @in_lists.include?(:owners)
|
823
|
-
msg.channel.owners_unsynced.clear
|
824
|
-
end
|
800
|
+
msg.channel.owners_unsynced.clear unless @in_lists.include?(:owners)
|
825
801
|
@in_lists << :owners
|
826
802
|
|
827
803
|
owner = User(msg.params[2])
|
828
804
|
msg.channel.owners_unsynced << owner
|
829
805
|
end
|
830
806
|
|
831
|
-
def on_387(msg,
|
807
|
+
def on_387(msg, _events)
|
832
808
|
# RPL_ENDOFQLIST
|
833
809
|
if @in_lists.include?(:owners)
|
834
810
|
@in_lists.delete :owners
|
835
811
|
else
|
836
|
-
#we never received an owner, yet an end of list -> no owners
|
812
|
+
# we never received an owner, yet an end of list -> no owners
|
837
813
|
msg.channel.owners_unsynced.clear
|
838
814
|
end
|
839
815
|
|
840
816
|
msg.channel.mark_as_synced(:owners)
|
841
817
|
end
|
842
818
|
|
843
|
-
def on_396(msg,
|
819
|
+
def on_396(msg, _events)
|
844
820
|
# RPL_HOSTHIDDEN
|
845
821
|
# note: designed for freenode
|
846
822
|
User(msg.params[0]).sync(:host, msg.params[1], true)
|
847
823
|
end
|
848
824
|
|
849
|
-
def on_401(msg,
|
825
|
+
def on_401(msg, _events)
|
850
826
|
# ERR_NOSUCHNICK
|
851
827
|
if user = @bot.user_list.find(msg.params[1])
|
852
|
-
update_whois(user, {
|
828
|
+
update_whois(user, { unknown?: true })
|
853
829
|
end
|
854
830
|
end
|
855
831
|
|
856
|
-
def on_402(msg,
|
832
|
+
def on_402(msg, _events)
|
857
833
|
# ERR_NOSUCHSERVER
|
858
834
|
|
859
835
|
if user = @bot.user_list.find(msg.params[1]) # not _ensured, we only want a user that already exists
|
860
|
-
user.end_of_whois({
|
836
|
+
user.end_of_whois({ unknown?: true })
|
861
837
|
@whois_updates.delete user
|
862
|
-
# TODO freenode specific, test on other IRCd
|
838
|
+
# TODO: freenode specific, test on other IRCd
|
863
839
|
end
|
864
840
|
end
|
865
841
|
|
866
|
-
def on_433(msg,
|
842
|
+
def on_433(msg, _events)
|
867
843
|
# ERR_NICKNAMEINUSE
|
868
844
|
@bot.nick = @bot.generate_next_nick!(msg.params[1])
|
869
845
|
end
|
870
846
|
|
871
|
-
def on_671(msg,
|
847
|
+
def on_671(msg, _events)
|
872
848
|
user = User(msg.params[1])
|
873
|
-
update_whois(user, {
|
849
|
+
update_whois(user, { secure?: true })
|
874
850
|
end
|
875
851
|
|
876
852
|
# @since 2.0.0
|
877
|
-
def on_730(msg,
|
853
|
+
def on_730(msg, _events)
|
878
854
|
# RPL_MONONLINE
|
879
855
|
msg.params.last.split(",").each do |mask|
|
880
856
|
user = User(Mask.new(mask).nick)
|
@@ -884,7 +860,7 @@ module Cinch
|
|
884
860
|
end
|
885
861
|
|
886
862
|
# @since 2.0.0
|
887
|
-
def on_731(msg,
|
863
|
+
def on_731(msg, _events)
|
888
864
|
# RPL_MONOFFLINE
|
889
865
|
msg.params.last.split(",").each do |nick|
|
890
866
|
user = User(nick)
|
@@ -894,28 +870,28 @@ module Cinch
|
|
894
870
|
end
|
895
871
|
|
896
872
|
# @since 2.0.0
|
897
|
-
def on_734(msg,
|
873
|
+
def on_734(msg, _events)
|
898
874
|
# ERR_MONLISTFULL
|
899
875
|
user = User(msg.params[2])
|
900
876
|
user.monitored = false
|
901
877
|
end
|
902
878
|
|
903
879
|
# @since 2.0.0
|
904
|
-
def on_903(
|
880
|
+
def on_903(_msg, _events)
|
905
881
|
# SASL authentication successful
|
906
882
|
@bot.loggers.info "[SASL] SASL authentication with #{@sasl_current_method.mechanism_name} successful"
|
907
883
|
send_cap_end
|
908
884
|
end
|
909
885
|
|
910
886
|
# @since 2.0.0
|
911
|
-
def on_904(
|
887
|
+
def on_904(_msg, _events)
|
912
888
|
# SASL authentication failed
|
913
889
|
@bot.loggers.info "[SASL] SASL authentication with #{@sasl_current_method.mechanism_name} failed"
|
914
890
|
send_sasl
|
915
891
|
end
|
916
892
|
|
917
893
|
# @since 2.0.0
|
918
|
-
def on_authenticate(msg,
|
894
|
+
def on_authenticate(msg, _events)
|
919
895
|
send "AUTHENTICATE " + @sasl_current_method.generate(@bot.config.sasl.username,
|
920
896
|
@bot.config.sasl.password,
|
921
897
|
msg.params.last)
|