cakewalk 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +1 -0
- data/LICENSE +22 -0
- data/README.md +169 -0
- data/docs/bot_options.md +454 -0
- data/docs/changes.md +541 -0
- data/docs/common_mistakes.md +60 -0
- data/docs/common_tasks.md +57 -0
- data/docs/encodings.md +69 -0
- data/docs/events.md +273 -0
- data/docs/getting_started.md +184 -0
- data/docs/logging.md +90 -0
- data/docs/migrating.md +267 -0
- data/docs/plugins.md +4 -0
- data/docs/readme.md +20 -0
- data/examples/basic/autovoice.rb +32 -0
- data/examples/basic/google.rb +35 -0
- data/examples/basic/hello.rb +15 -0
- data/examples/basic/join_part.rb +34 -0
- data/examples/basic/memo.rb +39 -0
- data/examples/basic/msg.rb +16 -0
- data/examples/basic/seen.rb +36 -0
- data/examples/basic/urban_dict.rb +35 -0
- data/examples/basic/url_shorten.rb +35 -0
- data/examples/plugins/autovoice.rb +37 -0
- data/examples/plugins/custom_prefix.rb +23 -0
- data/examples/plugins/dice_roll.rb +38 -0
- data/examples/plugins/google.rb +36 -0
- data/examples/plugins/hello.rb +22 -0
- data/examples/plugins/hooks.rb +36 -0
- data/examples/plugins/join_part.rb +42 -0
- data/examples/plugins/lambdas.rb +35 -0
- data/examples/plugins/last_nick.rb +24 -0
- data/examples/plugins/msg.rb +22 -0
- data/examples/plugins/multiple_matches.rb +32 -0
- data/examples/plugins/own_events.rb +37 -0
- data/examples/plugins/seen.rb +45 -0
- data/examples/plugins/timer.rb +22 -0
- data/examples/plugins/url_shorten.rb +33 -0
- data/lib/cakewalk/ban.rb +50 -0
- data/lib/cakewalk/bot.rb +479 -0
- data/lib/cakewalk/cached_list.rb +19 -0
- data/lib/cakewalk/callback.rb +20 -0
- data/lib/cakewalk/channel.rb +463 -0
- data/lib/cakewalk/channel_list.rb +29 -0
- data/lib/cakewalk/configuration/bot.rb +48 -0
- data/lib/cakewalk/configuration/dcc.rb +16 -0
- data/lib/cakewalk/configuration/plugins.rb +41 -0
- data/lib/cakewalk/configuration/sasl.rb +19 -0
- data/lib/cakewalk/configuration/ssl.rb +19 -0
- data/lib/cakewalk/configuration/timeouts.rb +14 -0
- data/lib/cakewalk/configuration.rb +73 -0
- data/lib/cakewalk/constants.rb +533 -0
- data/lib/cakewalk/dcc/dccable_object.rb +37 -0
- data/lib/cakewalk/dcc/incoming/send.rb +147 -0
- data/lib/cakewalk/dcc/incoming.rb +1 -0
- data/lib/cakewalk/dcc/outgoing/send.rb +122 -0
- data/lib/cakewalk/dcc/outgoing.rb +1 -0
- data/lib/cakewalk/dcc.rb +12 -0
- data/lib/cakewalk/exceptions.rb +46 -0
- data/lib/cakewalk/formatting.rb +125 -0
- data/lib/cakewalk/handler.rb +118 -0
- data/lib/cakewalk/handler_list.rb +90 -0
- data/lib/cakewalk/helpers.rb +231 -0
- data/lib/cakewalk/irc.rb +913 -0
- data/lib/cakewalk/isupport.rb +98 -0
- data/lib/cakewalk/log_filter.rb +21 -0
- data/lib/cakewalk/logger/formatted_logger.rb +97 -0
- data/lib/cakewalk/logger/zcbot_logger.rb +22 -0
- data/lib/cakewalk/logger.rb +168 -0
- data/lib/cakewalk/logger_list.rb +85 -0
- data/lib/cakewalk/mask.rb +69 -0
- data/lib/cakewalk/message.rb +391 -0
- data/lib/cakewalk/message_queue.rb +107 -0
- data/lib/cakewalk/mode_parser.rb +76 -0
- data/lib/cakewalk/network.rb +89 -0
- data/lib/cakewalk/open_ended_queue.rb +26 -0
- data/lib/cakewalk/pattern.rb +65 -0
- data/lib/cakewalk/plugin.rb +515 -0
- data/lib/cakewalk/plugin_list.rb +38 -0
- data/lib/cakewalk/rubyext/float.rb +3 -0
- data/lib/cakewalk/rubyext/module.rb +26 -0
- data/lib/cakewalk/rubyext/string.rb +33 -0
- data/lib/cakewalk/sasl/dh_blowfish.rb +71 -0
- data/lib/cakewalk/sasl/diffie_hellman.rb +47 -0
- data/lib/cakewalk/sasl/mechanism.rb +6 -0
- data/lib/cakewalk/sasl/plain.rb +26 -0
- data/lib/cakewalk/sasl.rb +34 -0
- data/lib/cakewalk/syncable.rb +83 -0
- data/lib/cakewalk/target.rb +199 -0
- data/lib/cakewalk/timer.rb +145 -0
- data/lib/cakewalk/user.rb +488 -0
- data/lib/cakewalk/user_list.rb +87 -0
- data/lib/cakewalk/utilities/deprecation.rb +16 -0
- data/lib/cakewalk/utilities/encoding.rb +37 -0
- data/lib/cakewalk/utilities/kernel.rb +13 -0
- data/lib/cakewalk/version.rb +4 -0
- data/lib/cakewalk.rb +5 -0
- metadata +140 -0
@@ -0,0 +1,463 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "set"
|
3
|
+
require "cakewalk/target"
|
4
|
+
|
5
|
+
module Cakewalk
|
6
|
+
# @attr limit
|
7
|
+
# @attr secret
|
8
|
+
# @attr moderated
|
9
|
+
# @attr invite_only
|
10
|
+
# @attr key
|
11
|
+
#
|
12
|
+
# @version 2.0.0
|
13
|
+
class Channel < Target
|
14
|
+
include Syncable
|
15
|
+
include Helpers
|
16
|
+
|
17
|
+
# Users are represented by a Hash, mapping individual users to an
|
18
|
+
# array of modes (e.g. "o" for opped).
|
19
|
+
#
|
20
|
+
# @return [Hash{User => Array<String}>] all users in the channel
|
21
|
+
# @version 1.1.0
|
22
|
+
attr_reader :users
|
23
|
+
synced_attr_reader :users
|
24
|
+
|
25
|
+
# @return [String] the channel's topic
|
26
|
+
attr_accessor :topic
|
27
|
+
synced_attr_reader :topic
|
28
|
+
|
29
|
+
# @return [Array<Ban>] all active bans
|
30
|
+
attr_reader :bans
|
31
|
+
synced_attr_reader :bans
|
32
|
+
|
33
|
+
# @return [Array<User>] all channel owners
|
34
|
+
# @note Only some networks implement this
|
35
|
+
attr_reader :owners
|
36
|
+
synced_attr_reader :owners
|
37
|
+
|
38
|
+
# This attribute describes all modes set in the channel. They're
|
39
|
+
# represented as a Hash, mapping the mode (e.g. "i", "k", …) to
|
40
|
+
# either a value in the case of modes that take an option (e.g.
|
41
|
+
# "k" for the channel key) or true.
|
42
|
+
#
|
43
|
+
# @return [Hash{String => Object}]
|
44
|
+
attr_reader :modes
|
45
|
+
synced_attr_reader :modes
|
46
|
+
|
47
|
+
# @note Generally, you shouldn't initialize new instances of this
|
48
|
+
# class. Use {ChannelList#find_ensured} instead.
|
49
|
+
def initialize(name, bot)
|
50
|
+
@bot = bot
|
51
|
+
@name = name
|
52
|
+
@users = Hash.new {|h, k| h[k] = []}
|
53
|
+
@bans = []
|
54
|
+
@owners = []
|
55
|
+
|
56
|
+
@modes = {}
|
57
|
+
# TODO raise if not a channel
|
58
|
+
|
59
|
+
@topic = nil
|
60
|
+
|
61
|
+
@in_channel = false
|
62
|
+
|
63
|
+
@synced_attributes = Set.new
|
64
|
+
@when_requesting_synced_attribute = lambda {|attr|
|
65
|
+
if @in_channel && attr == :topic && !attribute_synced?(:topic)
|
66
|
+
# Even if we are in the channel, if there's no topic set,
|
67
|
+
# the attribute won't be synchronised yet. Explicitly
|
68
|
+
# request the topic.
|
69
|
+
@bot.irc.send "TOPIC #@name"
|
70
|
+
next
|
71
|
+
end
|
72
|
+
|
73
|
+
unless @in_channel
|
74
|
+
unsync(attr)
|
75
|
+
case attr
|
76
|
+
when :users
|
77
|
+
@bot.irc.send "NAMES #@name"
|
78
|
+
when :topic
|
79
|
+
@bot.irc.send "TOPIC #@name"
|
80
|
+
when :bans
|
81
|
+
@bot.irc.send "MODE #@name +b"
|
82
|
+
when :owners
|
83
|
+
if @bot.irc.network.owner_list_mode
|
84
|
+
@bot.irc.send "MODE #@name +#{@bot.irc.network.owner_list_mode}"
|
85
|
+
else
|
86
|
+
# the current IRCd does not support channel owners, so
|
87
|
+
# just mark the empty array as synced
|
88
|
+
mark_as_synced(:owners)
|
89
|
+
end
|
90
|
+
when :modes
|
91
|
+
@bot.irc.send "MODE #@name"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
# @group Checks
|
98
|
+
|
99
|
+
# @param [User, String] user An {User}-object or a nickname
|
100
|
+
# @return [Boolean] Check if a user is in the channel
|
101
|
+
# @since 1.1.0
|
102
|
+
# @version 1.1.2
|
103
|
+
def has_user?(user)
|
104
|
+
@users.has_key?(User(user))
|
105
|
+
end
|
106
|
+
|
107
|
+
# @return [Boolean] true if `user` is opped in the channel
|
108
|
+
# @since 1.1.0
|
109
|
+
def opped?(user)
|
110
|
+
@users[User(user)].include? "o"
|
111
|
+
end
|
112
|
+
|
113
|
+
# @return [Boolean] true if `user` is half-opped in the channel
|
114
|
+
# @since 1.1.0
|
115
|
+
def half_opped?(user)
|
116
|
+
@users[User(user)].include? "h"
|
117
|
+
end
|
118
|
+
|
119
|
+
# @return [Boolean] true if `user` is voiced in the channel
|
120
|
+
# @since 1.1.0
|
121
|
+
def voiced?(user)
|
122
|
+
@users[User(user)].include? "v"
|
123
|
+
end
|
124
|
+
|
125
|
+
# @endgroup
|
126
|
+
|
127
|
+
# @group User groups
|
128
|
+
# @return [Array<User>] All ops in the channel
|
129
|
+
# @since 2.0.0
|
130
|
+
def ops
|
131
|
+
@users.select {|user, modes| modes.include?("o")}.keys
|
132
|
+
end
|
133
|
+
|
134
|
+
# @return [Array<User>] All half-ops in the channel
|
135
|
+
# @since 2.0.0
|
136
|
+
def half_ops
|
137
|
+
@users.select {|user, modes| modes.include?("h")}.keys
|
138
|
+
end
|
139
|
+
|
140
|
+
# @return [Array<User>] All voiced users in the channel
|
141
|
+
# @since 2.0.0
|
142
|
+
def voiced
|
143
|
+
@users.select {|user, modes| modes.include?("v")}.keys
|
144
|
+
end
|
145
|
+
|
146
|
+
# @return [Array<User>] All admins in the channel
|
147
|
+
# @since 2.0.0
|
148
|
+
def admins
|
149
|
+
@users.select {|user, modes| modes.include?("a")}.keys
|
150
|
+
end
|
151
|
+
# @endgroup
|
152
|
+
|
153
|
+
# @return [Integer] The maximum number of allowed users in the
|
154
|
+
# channel. 0 if unlimited.
|
155
|
+
def limit
|
156
|
+
@modes["l"].to_i
|
157
|
+
end
|
158
|
+
|
159
|
+
def limit=(val)
|
160
|
+
if val == -1 or val.nil?
|
161
|
+
mode "-l"
|
162
|
+
else
|
163
|
+
mode "+l #{val}"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
# @return [Boolean] true if the channel is secret (+s)
|
168
|
+
def secret
|
169
|
+
@modes["s"]
|
170
|
+
end
|
171
|
+
alias_method :secret?, :secret
|
172
|
+
|
173
|
+
def secret=(bool)
|
174
|
+
if bool
|
175
|
+
mode "+s"
|
176
|
+
else
|
177
|
+
mode "-s"
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
# @return [Boolean] true if the channel is moderated
|
182
|
+
def moderated
|
183
|
+
@modes["m"]
|
184
|
+
end
|
185
|
+
alias_method :moderated?, :moderated
|
186
|
+
|
187
|
+
def moderated=(bool)
|
188
|
+
if bool
|
189
|
+
mode "+m"
|
190
|
+
else
|
191
|
+
mode "-m"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
# @return [Boolean] true if the channel is invite only (+i)
|
196
|
+
def invite_only
|
197
|
+
@modes["i"]
|
198
|
+
end
|
199
|
+
alias_method :invite_only?, :invite_only
|
200
|
+
|
201
|
+
def invite_only=(bool)
|
202
|
+
if bool
|
203
|
+
mode "+i"
|
204
|
+
else
|
205
|
+
mode "-i"
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
# @return [String, nil] The channel's key (aka password)
|
210
|
+
def key
|
211
|
+
@modes["k"]
|
212
|
+
end
|
213
|
+
|
214
|
+
def key=(new_key)
|
215
|
+
if new_key.nil?
|
216
|
+
mode "-k #{key}"
|
217
|
+
else
|
218
|
+
mode "+k #{new_key}"
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
# @api private
|
223
|
+
# @return [void]
|
224
|
+
def sync_modes
|
225
|
+
unsync :users
|
226
|
+
unsync :bans
|
227
|
+
unsync :modes
|
228
|
+
unsync :owners
|
229
|
+
|
230
|
+
if @bot.irc.isupport["WHOX"]
|
231
|
+
@bot.irc.send "WHO #@name %acfhnru"
|
232
|
+
else
|
233
|
+
@bot.irc.send "WHO #@name"
|
234
|
+
end
|
235
|
+
@bot.irc.send "MODE #@name +b" # bans
|
236
|
+
@bot.irc.send "MODE #@name"
|
237
|
+
if @bot.irc.network.owner_list_mode
|
238
|
+
@bot.irc.send "MODE #@name +#{@bot.irc.network.owner_list_mode}"
|
239
|
+
else
|
240
|
+
mark_as_synced :owners
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
# @group Channel Manipulation
|
245
|
+
|
246
|
+
# Bans someone from the channel.
|
247
|
+
#
|
248
|
+
# @param [Mask, String, #mask] target the mask, or an object having a mask, to ban
|
249
|
+
# @return [Mask] the mask used for banning
|
250
|
+
# @see #unban #unban for unbanning users
|
251
|
+
def ban(target)
|
252
|
+
mask = Mask.from(target)
|
253
|
+
|
254
|
+
@bot.irc.send "MODE #@name +b #{mask}"
|
255
|
+
mask
|
256
|
+
end
|
257
|
+
|
258
|
+
# Unbans someone from the channel.
|
259
|
+
#
|
260
|
+
# @param [Mask, String, #mask] target the mask to unban
|
261
|
+
# @return [Mask] the mask used for unbanning
|
262
|
+
# @see #ban #ban for banning users
|
263
|
+
def unban(target)
|
264
|
+
mask = Mask.from(target)
|
265
|
+
|
266
|
+
@bot.irc.send "MODE #@name -b #{mask}"
|
267
|
+
mask
|
268
|
+
end
|
269
|
+
|
270
|
+
# Ops a user.
|
271
|
+
#
|
272
|
+
# @param [String, User] user the user to op
|
273
|
+
# @return [void]
|
274
|
+
def op(user)
|
275
|
+
@bot.irc.send "MODE #@name +o #{user}"
|
276
|
+
end
|
277
|
+
|
278
|
+
# Deops a user.
|
279
|
+
#
|
280
|
+
# @param [String, User] user the user to deop
|
281
|
+
# @return [void]
|
282
|
+
def deop(user)
|
283
|
+
@bot.irc.send "MODE #@name -o #{user}"
|
284
|
+
end
|
285
|
+
|
286
|
+
# Voices a user.
|
287
|
+
#
|
288
|
+
# @param [String, User] user the user to voice
|
289
|
+
# @return [void]
|
290
|
+
def voice(user)
|
291
|
+
@bot.irc.send "MODE #@name +v #{user}"
|
292
|
+
end
|
293
|
+
|
294
|
+
# Devoices a user.
|
295
|
+
#
|
296
|
+
# @param [String, User] user the user to devoice
|
297
|
+
# @return [void]
|
298
|
+
def devoice(user)
|
299
|
+
@bot.irc.send "MODE #@name -v #{user}"
|
300
|
+
end
|
301
|
+
|
302
|
+
# Invites a user to the channel.
|
303
|
+
#
|
304
|
+
# @param [String, User] user the user to invite
|
305
|
+
# @return [void]
|
306
|
+
def invite(user)
|
307
|
+
@bot.irc.send("INVITE #{user} #@name")
|
308
|
+
end
|
309
|
+
|
310
|
+
undef_method(:topic=)
|
311
|
+
# Sets the topic.
|
312
|
+
#
|
313
|
+
# @param [String] new_topic the new topic
|
314
|
+
# @raise [Exceptions::TopicTooLong] Raised if the bot is operating
|
315
|
+
# in {Bot#strict? strict mode} and when the new topic is too long.
|
316
|
+
def topic=(new_topic)
|
317
|
+
if new_topic.size > @bot.irc.isupport["TOPICLEN"] && @bot.strict?
|
318
|
+
raise Exceptions::TopicTooLong, new_topic
|
319
|
+
end
|
320
|
+
|
321
|
+
@bot.irc.send "TOPIC #@name :#{new_topic}"
|
322
|
+
end
|
323
|
+
|
324
|
+
# Kicks a user from the channel.
|
325
|
+
#
|
326
|
+
# @param [String, User] user the user to kick
|
327
|
+
# @param [String] reason a reason for the kick
|
328
|
+
# @raise [Exceptions::KickReasonTooLong]
|
329
|
+
# @return [void]
|
330
|
+
def kick(user, reason = nil)
|
331
|
+
if reason.to_s.size > @bot.irc.isupport["KICKLEN"] && @bot.strict?
|
332
|
+
raise Exceptions::KickReasonTooLong, reason
|
333
|
+
end
|
334
|
+
|
335
|
+
@bot.irc.send("KICK #@name #{user} :#{reason}")
|
336
|
+
end
|
337
|
+
|
338
|
+
# Removes a user from the channel.
|
339
|
+
#
|
340
|
+
# This uses the REMOVE command, which is a non-standardized
|
341
|
+
# extension. Unlike a kick, it makes a user part. This prevents
|
342
|
+
# auto-rejoin scripts from firing and might also be perceived as
|
343
|
+
# less aggressive by some. Not all IRC networks support this
|
344
|
+
# command.
|
345
|
+
#
|
346
|
+
# @param [User] user the user to remove
|
347
|
+
# @param [String] reason a reason for the removal
|
348
|
+
# @return [void]
|
349
|
+
def remove(user, reason = nil)
|
350
|
+
@bot.irc.send("REMOVE #@name #{user} :#{reason}")
|
351
|
+
end
|
352
|
+
|
353
|
+
# Sets or unsets modes. Most of the time you won't need this but
|
354
|
+
# use setter methods like {Channel#invite_only=}.
|
355
|
+
#
|
356
|
+
# @param [String] s a mode string
|
357
|
+
# @return [void]
|
358
|
+
# @example
|
359
|
+
# channel.mode "+n"
|
360
|
+
def mode(s)
|
361
|
+
@bot.irc.send "MODE #@name #{s}"
|
362
|
+
end
|
363
|
+
|
364
|
+
# Causes the bot to part from the channel.
|
365
|
+
#
|
366
|
+
# @param [String] message the part message.
|
367
|
+
# @return [void]
|
368
|
+
def part(message = nil)
|
369
|
+
@bot.irc.send "PART #@name :#{message}"
|
370
|
+
end
|
371
|
+
|
372
|
+
# Joins the channel
|
373
|
+
#
|
374
|
+
# @param [String] key the channel key, if any. If none is
|
375
|
+
# specified but @key is set, @key will be used
|
376
|
+
# @return [void]
|
377
|
+
def join(key = nil)
|
378
|
+
if key.nil? and self.key != true
|
379
|
+
key = self.key
|
380
|
+
end
|
381
|
+
@bot.irc.send "JOIN #{[@name, key].compact.join(" ")}"
|
382
|
+
end
|
383
|
+
|
384
|
+
# @endgroup
|
385
|
+
|
386
|
+
# @api private
|
387
|
+
# @return [User] The added user
|
388
|
+
def add_user(user, modes = [])
|
389
|
+
@in_channel = true if user == @bot
|
390
|
+
@users[user] = modes
|
391
|
+
user
|
392
|
+
end
|
393
|
+
|
394
|
+
# @api private
|
395
|
+
# @return [User, nil] The removed user
|
396
|
+
def remove_user(user)
|
397
|
+
@in_channel = false if user == @bot
|
398
|
+
@users.delete(user)
|
399
|
+
end
|
400
|
+
|
401
|
+
# Removes all users
|
402
|
+
#
|
403
|
+
# @api private
|
404
|
+
# @return [void]
|
405
|
+
def clear_users
|
406
|
+
@users.clear
|
407
|
+
end
|
408
|
+
|
409
|
+
# @note The aliases `msg` and `privmsg` are deprecated and will be
|
410
|
+
# removed in a future version.
|
411
|
+
def send(text, notice = false)
|
412
|
+
# TODO deprecate 'notice' argument
|
413
|
+
text = text.to_s
|
414
|
+
if @modes["c"]
|
415
|
+
# Remove all formatting and colors if the channel doesn't
|
416
|
+
# allow colors.
|
417
|
+
text = Cakewalk::Formatting.unformat(text)
|
418
|
+
end
|
419
|
+
super(text, notice)
|
420
|
+
end
|
421
|
+
alias_method :msg, :send # deprecated
|
422
|
+
alias_method :privmsg, :send # deprecated
|
423
|
+
undef_method(:msg) # yardoc hack
|
424
|
+
undef_method(:privmsg) # yardoc hack
|
425
|
+
|
426
|
+
# @deprecated
|
427
|
+
def msg(*args)
|
428
|
+
Cakewalk::Utilities::Deprecation.print_deprecation("2.2.0", "Channel#msg", "Channel#send")
|
429
|
+
send(*args)
|
430
|
+
end
|
431
|
+
|
432
|
+
# @deprecated
|
433
|
+
def privmsg(*args)
|
434
|
+
Cakewalk::Utilities::Deprecation.print_deprecation("2.2.0", "Channel#privmsg", "Channel#send")
|
435
|
+
send(*args)
|
436
|
+
end
|
437
|
+
|
438
|
+
# @return [Fixnum]
|
439
|
+
def hash
|
440
|
+
@name.hash
|
441
|
+
end
|
442
|
+
|
443
|
+
# @return [String]
|
444
|
+
# @note The alias `to_str` is deprecated and will be removed in a
|
445
|
+
# future version. Channel objects should not be treated like
|
446
|
+
# strings.
|
447
|
+
def to_s
|
448
|
+
@name
|
449
|
+
end
|
450
|
+
alias_method :to_str, :to_s # deprecated
|
451
|
+
undef_method(:to_str) # yardoc hack
|
452
|
+
|
453
|
+
def to_str
|
454
|
+
Cakewalk::Utilities::Deprecation.print_deprecation("2.2.0", "Channel#to_str", "Channel#to_s")
|
455
|
+
to_s
|
456
|
+
end
|
457
|
+
|
458
|
+
# @return [String]
|
459
|
+
def inspect
|
460
|
+
"#<Channel name=#{@name.inspect}>"
|
461
|
+
end
|
462
|
+
end
|
463
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "cakewalk/cached_list"
|
2
|
+
|
3
|
+
module Cakewalk
|
4
|
+
# @since 2.0.0
|
5
|
+
# @version 1.1.0
|
6
|
+
# @note In prior versions, this class was called ChannelManager
|
7
|
+
class ChannelList < CachedList
|
8
|
+
# Finds or creates a channel.
|
9
|
+
#
|
10
|
+
# @param [String] name name of a channel
|
11
|
+
# @return [Channel]
|
12
|
+
# @see Helpers#Channel
|
13
|
+
def find_ensured(name)
|
14
|
+
downcased_name = name.irc_downcase(@bot.irc.isupport["CASEMAPPING"])
|
15
|
+
@mutex.synchronize do
|
16
|
+
@cache[downcased_name] ||= Channel.new(name, @bot)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Finds a channel.
|
21
|
+
#
|
22
|
+
# @param [String] name name of a channel
|
23
|
+
# @return [Channel, nil]
|
24
|
+
def find(name)
|
25
|
+
downcased_name = name.irc_downcase(@bot.irc.isupport["CASEMAPPING"])
|
26
|
+
@cache[downcased_name]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "cakewalk/configuration"
|
2
|
+
|
3
|
+
module Cakewalk
|
4
|
+
class Configuration
|
5
|
+
# @since 2.0.0
|
6
|
+
class Bot < Configuration
|
7
|
+
KnownOptions = [:server, :port, :ssl, :password, :nick, :nicks,
|
8
|
+
:realname, :user, :messages_per_second, :server_queue_size,
|
9
|
+
:strictness, :message_split_start, :message_split_end,
|
10
|
+
:max_messages, :plugins, :channels, :encoding, :reconnect, :max_reconnect_delay,
|
11
|
+
:local_host, :timeouts, :ping_interval, :delay_joins, :dcc, :shared, :sasl, :default_logger_level]
|
12
|
+
|
13
|
+
# (see Configuration.default_config)
|
14
|
+
def self.default_config
|
15
|
+
{
|
16
|
+
:server => "localhost",
|
17
|
+
:port => 6667,
|
18
|
+
:ssl => Configuration::SSL.new,
|
19
|
+
:password => nil,
|
20
|
+
:nick => "cakewalk",
|
21
|
+
:nicks => nil,
|
22
|
+
:realname => "cakewalk",
|
23
|
+
:user => "cakewalk",
|
24
|
+
:modes => [],
|
25
|
+
:messages_per_second => nil,
|
26
|
+
:server_queue_size => nil,
|
27
|
+
:strictness => :forgiving,
|
28
|
+
:message_split_start => '... ',
|
29
|
+
:message_split_end => ' ...',
|
30
|
+
:max_messages => nil,
|
31
|
+
:plugins => Configuration::Plugins.new,
|
32
|
+
:channels => [],
|
33
|
+
:encoding => :irc,
|
34
|
+
:reconnect => true,
|
35
|
+
:max_reconnect_delay => 300,
|
36
|
+
:local_host => nil,
|
37
|
+
:timeouts => Configuration::Timeouts.new,
|
38
|
+
:ping_interval => 120,
|
39
|
+
:delay_joins => 0,
|
40
|
+
:dcc => Configuration::DCC.new,
|
41
|
+
:sasl => Configuration::SASL.new,
|
42
|
+
:shared => {},
|
43
|
+
:default_logger_level => :debug
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "cakewalk/configuration"
|
2
|
+
|
3
|
+
module Cakewalk
|
4
|
+
class Configuration
|
5
|
+
# @since 2.0.0
|
6
|
+
class Plugins < Configuration
|
7
|
+
KnownOptions = [:plugins, :prefix, :suffix, :options]
|
8
|
+
|
9
|
+
def self.default_config
|
10
|
+
{
|
11
|
+
:plugins => [],
|
12
|
+
:prefix => /^!/,
|
13
|
+
:suffix => nil,
|
14
|
+
:options => Hash.new {|h,k| h[k] = {}},
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def load(new_config, from_default = false)
|
19
|
+
_new_config = {}
|
20
|
+
new_config.each do |option, value|
|
21
|
+
case option
|
22
|
+
when :plugins
|
23
|
+
_new_config[option] = value.map{|v| Cakewalk::Utilities::Kernel.string_to_const(v)}
|
24
|
+
when :options
|
25
|
+
_value = self[:options]
|
26
|
+
value.each do |k, v|
|
27
|
+
k = Cakewalk::Utilities::Kernel.string_to_const(k)
|
28
|
+
v = self[:options][k].merge(v)
|
29
|
+
_value[k] = v
|
30
|
+
end
|
31
|
+
_new_config[option] = _value
|
32
|
+
else
|
33
|
+
_new_config[option] = value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
super(_new_config, from_default)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "cakewalk/configuration"
|
2
|
+
require "cakewalk/sasl"
|
3
|
+
|
4
|
+
module Cakewalk
|
5
|
+
class Configuration
|
6
|
+
# @since 2.0.0
|
7
|
+
class SASL < Configuration
|
8
|
+
KnownOptions = [:username, :password, :mechanisms]
|
9
|
+
|
10
|
+
def self.default_config
|
11
|
+
{
|
12
|
+
:username => nil,
|
13
|
+
:password => nil,
|
14
|
+
:mechanisms => [Cakewalk::SASL::DH_Blowfish, Cakewalk::SASL::Plain]
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "cakewalk/configuration"
|
2
|
+
|
3
|
+
module Cakewalk
|
4
|
+
class Configuration
|
5
|
+
# @since 2.0.0
|
6
|
+
class SSL < Configuration
|
7
|
+
KnownOptions = [:use, :verify, :client_cert, :ca_path]
|
8
|
+
|
9
|
+
def self.default_config
|
10
|
+
{
|
11
|
+
:use => false,
|
12
|
+
:verify => false,
|
13
|
+
:client_cert => nil,
|
14
|
+
:ca_path => "/etc/ssl/certs",
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|