cinch 1.1.3 → 2.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/LICENSE +1 -0
  2. data/README.md +3 -3
  3. data/docs/bot_options.md +435 -0
  4. data/docs/changes.md +440 -0
  5. data/docs/common_mistakes.md +35 -0
  6. data/docs/common_tasks.md +47 -0
  7. data/docs/encodings.md +67 -0
  8. data/docs/events.md +272 -0
  9. data/docs/logging.md +5 -0
  10. data/docs/migrating.md +267 -0
  11. data/docs/readme.md +18 -0
  12. data/examples/plugins/custom_prefix.rb +1 -1
  13. data/examples/plugins/dice_roll.rb +38 -0
  14. data/examples/plugins/lambdas.rb +1 -1
  15. data/examples/plugins/memo.rb +16 -10
  16. data/examples/plugins/url_shorten.rb +1 -0
  17. data/lib/cinch.rb +5 -60
  18. data/lib/cinch/ban.rb +13 -7
  19. data/lib/cinch/bot.rb +228 -403
  20. data/lib/cinch/{cache_manager.rb → cached_list.rb} +5 -1
  21. data/lib/cinch/callback.rb +3 -0
  22. data/lib/cinch/channel.rb +119 -195
  23. data/lib/cinch/{channel_manager.rb → channel_list.rb} +6 -3
  24. data/lib/cinch/configuration.rb +73 -0
  25. data/lib/cinch/configuration/bot.rb +47 -0
  26. data/lib/cinch/configuration/dcc.rb +16 -0
  27. data/lib/cinch/configuration/plugins.rb +41 -0
  28. data/lib/cinch/configuration/sasl.rb +17 -0
  29. data/lib/cinch/configuration/ssl.rb +19 -0
  30. data/lib/cinch/configuration/storage.rb +37 -0
  31. data/lib/cinch/configuration/timeouts.rb +14 -0
  32. data/lib/cinch/constants.rb +531 -369
  33. data/lib/cinch/dcc.rb +12 -0
  34. data/lib/cinch/dcc/dccable_object.rb +37 -0
  35. data/lib/cinch/dcc/incoming.rb +1 -0
  36. data/lib/cinch/dcc/incoming/send.rb +131 -0
  37. data/lib/cinch/dcc/outgoing.rb +1 -0
  38. data/lib/cinch/dcc/outgoing/send.rb +115 -0
  39. data/lib/cinch/exceptions.rb +8 -1
  40. data/lib/cinch/formatting.rb +106 -0
  41. data/lib/cinch/handler.rb +104 -0
  42. data/lib/cinch/handler_list.rb +86 -0
  43. data/lib/cinch/helpers.rb +167 -10
  44. data/lib/cinch/irc.rb +525 -110
  45. data/lib/cinch/isupport.rb +11 -9
  46. data/lib/cinch/logger.rb +168 -0
  47. data/lib/cinch/logger/formatted_logger.rb +72 -55
  48. data/lib/cinch/logger/zcbot_logger.rb +9 -24
  49. data/lib/cinch/logger_list.rb +62 -0
  50. data/lib/cinch/mask.rb +19 -10
  51. data/lib/cinch/message.rb +94 -28
  52. data/lib/cinch/message_queue.rb +70 -28
  53. data/lib/cinch/mode_parser.rb +6 -1
  54. data/lib/cinch/network.rb +104 -0
  55. data/lib/cinch/{rubyext/queue.rb → open_ended_queue.rb} +8 -1
  56. data/lib/cinch/pattern.rb +24 -4
  57. data/lib/cinch/plugin.rb +352 -177
  58. data/lib/cinch/plugin_list.rb +35 -0
  59. data/lib/cinch/rubyext/float.rb +3 -0
  60. data/lib/cinch/rubyext/module.rb +7 -0
  61. data/lib/cinch/rubyext/string.rb +9 -0
  62. data/lib/cinch/sasl.rb +34 -0
  63. data/lib/cinch/sasl/dh_blowfish.rb +71 -0
  64. data/lib/cinch/sasl/diffie_hellman.rb +47 -0
  65. data/lib/cinch/sasl/mechanism.rb +6 -0
  66. data/lib/cinch/sasl/plain.rb +26 -0
  67. data/lib/cinch/storage.rb +62 -0
  68. data/lib/cinch/storage/null.rb +12 -0
  69. data/lib/cinch/storage/yaml.rb +96 -0
  70. data/lib/cinch/syncable.rb +13 -1
  71. data/lib/cinch/target.rb +144 -0
  72. data/lib/cinch/timer.rb +145 -0
  73. data/lib/cinch/user.rb +169 -225
  74. data/lib/cinch/{user_manager.rb → user_list.rb} +7 -2
  75. data/lib/cinch/utilities/deprecation.rb +12 -0
  76. data/lib/cinch/utilities/encoding.rb +54 -0
  77. data/lib/cinch/utilities/kernel.rb +13 -0
  78. data/lib/cinch/utilities/string.rb +13 -0
  79. data/lib/cinch/version.rb +4 -0
  80. metadata +88 -47
  81. data/lib/cinch/logger/logger.rb +0 -44
  82. data/lib/cinch/logger/null_logger.rb +0 -18
  83. data/lib/cinch/rubyext/infinity.rb +0 -1
@@ -0,0 +1,440 @@
1
+ # @title What has changed?
2
+
3
+ # What has changed in 2.0?
4
+ 1. **Added support for SASL**
5
+ 1. **Added support for DCC SEND**
6
+ 1. **Added a fair scheduler for outgoing messages**
7
+ 1. **Added required plugin options**
8
+ 1. **Added support for colors/formatting**
9
+ 1. **Added network discovery**
10
+ 1. **Added match groups**
11
+ 1. **Added match options overwriting plugin options**
12
+ 1. **Added support for actions (/me)**
13
+ 1. **Added support for broken IRC networks**
14
+ 1. **Dynamic timers**
15
+ 1. **Reworked logging facilities**
16
+
17
+ 1. **API improvements**
18
+ 1. **Helper changes**
19
+ 1. **Added a Cinch::Target Target class**
20
+ 1. **Cinch::Constants**
21
+ 1. **New methods**
22
+ 1. **Cinch::Bot**
23
+ 1. **Cinch::Channel**
24
+ 1. **Cinch::Helpers**
25
+ 1. **Cinch::IRC**
26
+ 1. **Cinch::Message**
27
+ 1. **Cinch::User**
28
+ 1. **Removed/Renamed methods**
29
+ 1. **Handlers**
30
+ 1. The Plugin class
31
+ 1. **Channel/Target/User implement Comparable**
32
+ 1. **Renamed `*Manager` to `*List`**
33
+
34
+ 1. **New events**
35
+
36
+ ## Added support for SASL
37
+
38
+ Cinch now supports authenticating to services via SASL. For more
39
+ information check {Cinch::SASL}.
40
+
41
+ ## Added support for DCC SEND
42
+
43
+ Support for sending and receiving files via DCC has been added to
44
+ Cinch. Check {Cinch::DCC} for more information.
45
+
46
+ ## Added a fair scheduler for outgoing messages
47
+ Cinch always provided sophisticated throttling to avoid getting kicked
48
+ due to _excess flood_. One major flaw, however, was that it used a
49
+ single FIFO for all messages, thus preferring early message targets
50
+ and penalizing later ones.
51
+
52
+ Now Cinch uses a round-robin approach, having one queue per message
53
+ target (channels and users) and one for generic commands.
54
+
55
+ ## Added required plugin options
56
+
57
+ Plugins can now require specific options to be set. If any of those
58
+ options are not set, the plugin will automatically refuse being
59
+ loaded.
60
+
61
+ This is useful for example for plugins that require API keys to
62
+ interact with web services.
63
+
64
+ The new attribute is called
65
+ {Cinch::Plugin::ClassMethods#required_options required_options}.
66
+
67
+ Example:
68
+
69
+ class MyPlugin
70
+ include Cinch::Plugin
71
+
72
+ set :required_options, [:foo, :bar]
73
+ # ...
74
+ end
75
+
76
+ # ...
77
+
78
+ bot.configure do |c|
79
+ c.plugins.plugins = [MyPlugin]
80
+ c.plugins.options[MyPlugin] = {:foo => 1}
81
+ end
82
+
83
+ # The plugin won't load because the option :bar is not set.
84
+ # Instead it will print a warning.
85
+
86
+ ## Added support for colors/formatting
87
+
88
+ A new {Cinch::Formatting module} and {Cinch::Helpers#Format helper}
89
+ for adding colors and formatting to messages has been added. See the
90
+ {Cinch::Formatting module's documentation} for more information on
91
+ usage.
92
+
93
+ ## Added support for network discovery
94
+
95
+ Cinch now tries to detect the network it connects to, including the
96
+ running IRCd. For most parts this is only interesting internally, but
97
+ if you're writing advanced plugins that hook directly into IRC and
98
+ needs to be aware of available features/quirks, check out
99
+ {Cinch::IRC#network} and {Cinch::Network}.
100
+
101
+ ## Reworked logging facilities
102
+
103
+ The logging API has been drastically improved. Check the
104
+ {file:logging.md logging documentation} for more information.
105
+
106
+
107
+ ## Added match groups
108
+
109
+ A new option for matchers, `:group`, allows grouping multiple matchers
110
+ to a group. What's special is that in any group, only the first
111
+ matching handler will be executed.
112
+
113
+ Example:
114
+
115
+ class Foo
116
+ include Cinch::Plugin
117
+
118
+ match /foo (\d+)/, group: :blegh, method: :foo1
119
+ match /foo (.+)/, group: :blegh, method: :foo2
120
+ match /foo .+/, method: :foo3
121
+ def foo1(m, arg)
122
+ m.reply "foo1"
123
+ end
124
+
125
+ def foo2(m, arg)
126
+ m.reply "foo2"
127
+ end
128
+
129
+ def foo3(m)
130
+ m.reply "foo3"
131
+ end
132
+ end
133
+ # 02:05:39 dominikh │ !foo 123
134
+ # 02:05:40 cinch │ foo1
135
+ # 02:05:40 cinch │ foo3
136
+
137
+ # 02:05:43 dominikh │ !foo bar
138
+ # 02:05:44 cinch │ foo2
139
+ # 02:05:44 cinch │ foo3
140
+
141
+
142
+ ## Added match options overwriting plugin options
143
+
144
+ Matchers now have their own `:prefix`, `:suffix` and `:reacting_on`
145
+ options which overwrite plugin options for single matchers.
146
+
147
+
148
+ ## Added support for actions (/me)
149
+
150
+ A new event, {`:action`} has been added and can be used for matching
151
+ actions as follows:
152
+
153
+ match "kicks the bot", reacting_on: :action
154
+ def execute(m)
155
+ m.reply "Ouch!"
156
+ end
157
+
158
+ ## API improvements
159
+
160
+ ### Helper changes
161
+
162
+ The helper methods {Cinch::Helpers#User User()} and
163
+ {Cinch::Helpers#Channel Channel()} have been extracted from
164
+ {Cinch::Bot} and moved to {Cinch::Helpers their own module} which can
165
+ be reused in various places.
166
+
167
+ ### Added a {Cinch::Target Target} class
168
+
169
+ Since {Cinch::Channel} and {Cinch::User} share one common interface
170
+ for sending messages, it only makes sense to have a common base class.
171
+ {Cinch::Target This new class} takes care of sending messages and
172
+ removes this responsibility from {Cinch::Channel}, {Cinch::User} and
173
+ {Cinch::Bot}
174
+
175
+ ### {Cinch::Constants}
176
+
177
+ All constants for IRC numeric replies (`RPL_*` and `ERR_*`) have been
178
+ moved from {Cinch} to {Cinch::Constants}
179
+
180
+ ### New methods
181
+
182
+ #### {Cinch::Bot}
183
+
184
+ - {Cinch::Bot#channel_list}
185
+ - {Cinch::Bot#handlers}
186
+ - {Cinch::Bot#loggers}
187
+ - {Cinch::Bot#loggers=}
188
+ - {Cinch::Bot#modes}
189
+ - {Cinch::Bot#modes=}
190
+ - {Cinch::Bot#set_mode}
191
+ - {Cinch::Bot#stop}
192
+ - {Cinch::Bot#unset_mode}
193
+ - {Cinch::Bot#user_list}
194
+
195
+ #### {Cinch::Channel}
196
+
197
+ - {Cinch::Channel#admins}
198
+ - {Cinch::Channel#half_ops}
199
+ - {Cinch::Channel#ops}
200
+ - {Cinch::Channel#owners}
201
+ - {Cinch::Channel#voiced}
202
+
203
+ #### {Cinch::Helpers}
204
+
205
+ - {Cinch::Helpers#Target} -- For creating a {Cinch::Target Target} which can receive messages
206
+ - {Cinch::Helpers#Timer} -- For creating new timers anywhere
207
+ - {Cinch::Helpers#rescue_exception} -- For rescueing and automatically logging an exception
208
+ - {Cinch::Helpers#Format} -- For adding colors and formatting to messages
209
+
210
+ ##### Logging shortcuts
211
+ - {Cinch::Helpers#debug}
212
+ - {Cinch::Helpers#error}
213
+ - {Cinch::Helpers#exception}
214
+ - {Cinch::Helpers#fatal}
215
+ - {Cinch::Helpers#incoming}
216
+ - {Cinch::Helpers#info}
217
+ - {Cinch::Helpers#log}
218
+ - {Cinch::Helpers#outgoing}
219
+ - {Cinch::Helpers#warn}
220
+
221
+ #### {Cinch::IRC}
222
+
223
+ - {Cinch::IRC#network}
224
+
225
+ #### {Cinch::Message}
226
+
227
+ - {Cinch::Message#action?}
228
+ - {Cinch::Message#action_message}
229
+ - {Cinch::Message#target}
230
+ - {Cinch::Message#time}
231
+
232
+ #### {Cinch::Plugin}
233
+
234
+ - {Cinch::Plugin#handlers}
235
+ - {Cinch::Plugin#storage}
236
+ - {Cinch::Plugin#timers}
237
+ - {Cinch::Plugin#unregister}
238
+
239
+ #### {Cinch::User}
240
+
241
+ - {Cinch::User#away}
242
+ - {Cinch::User#dcc_send} - See {Cinch::DCC::Outgoing::Send}
243
+ - {Cinch::User#match}
244
+ - {Cinch::User#monitor} - See {file:common_tasks.md#checking-if-a-user-is-online Checking if a user is online}
245
+ - {Cinch::User#monitored}
246
+ - {Cinch::User#online?}
247
+ - {Cinch::User#unmonitor}
248
+
249
+ ### Handlers
250
+
251
+ Internally, Cinch uses {Cinch::Handler Handlers} for listening to and
252
+ matching events. In previous versions, this was hidden from the user,
253
+ but now they're part of the public API, providing valuable information
254
+ and the chance to {Cinch::Handler#unregister unregister handlers}
255
+ alltogether.
256
+
257
+ {Cinch::Bot#on} now returns the created handler and
258
+ {Cinch::Plugin#handlers} allows getting a plugin's registered
259
+ handlers.
260
+
261
+ ### Removed/Renamed methods
262
+ The following methods have been removed:
263
+
264
+ | Removed method | Replacement |
265
+ |----------------------------------------+---------------------------------------------------------------------------------|
266
+ | Cinch::Bot#halt | `next` or `break` (Ruby keywords) |
267
+ | Cinch::Bot#raw | {Cinch::IRC#send} |
268
+ | Cinch::Bot#msg | {Cinch::Target#msg} |
269
+ | Cinch::Bot#notice | {Cinch::Target#notice} |
270
+ | Cinch::Bot#safe_msg | {Cinch::Target#safe_msg} |
271
+ | Cinch::Bot#safe_notice | {Cinch::Target#safe_notice} |
272
+ | Cinch::Bot#action | {Cinch::Target#action} |
273
+ | Cinch::Bot#safe_action | {Cinch::Target#safe_action} |
274
+ | Cinch::Bot#dispatch | {Cinch::HandlerList#dispatch} |
275
+ | Cinch::Bot#register_plugins | {Cinch::PluginList#register_plugins} |
276
+ | Cinch::Bot#register_plugin | {Cinch::PluginList#register_plugin} |
277
+ | Cinch::Bot#logger | {Cinch::Bot#loggers} |
278
+ | Cinch::Bot#logger= | |
279
+ | Cinch::Bot#debug | {Cinch::LoggerList#debug} |
280
+ | Cinch::IRC#message | {Cinch::IRC#send} |
281
+ | Cinch::Logger::Logger#log_exception | {Cinch::Logger#exception} |
282
+ | Class methods in Plugin to set options | A new {Cinch::Plugin::ClassMethods#set set} method as well as attribute setters |
283
+
284
+
285
+ ### The Plugin class
286
+
287
+ The {Cinch::Plugin Plugin} class has been drastically improved to look
288
+ and behave more like a proper Ruby class instead of being some
289
+ abstract black box.
290
+
291
+ All attributes of a plugin (name, help message, matchers, …) are being
292
+ made available via attribute getters and setters. Furthermore, it is
293
+ possible to access a Plugin instance's registered handlers and timers,
294
+ as well as unregister plugins.
295
+
296
+ For a complete overview of available attributes and methods, see
297
+ {Cinch::Plugin} and {Cinch::Plugin::ClassMethods}.
298
+
299
+ ### Plugin options
300
+
301
+ The aforementioned changes also affect the way plugin options are
302
+ being set: Plugin options aren't set with DSL-like methods anymore but
303
+ instead are made available via {Cinch::Plugin::ClassMethods#set a
304
+ `set` method} or alternatively plain attribute setters.
305
+
306
+ See
307
+ {file:migrating.md#plugin-options the migration guide} for more
308
+ information.
309
+
310
+ ### Channel/Target/User implement Comparable
311
+
312
+ {Cinch::Target} and thus {Cinch::Channel} and {Cinch::User} now
313
+ implement the Comparable interface, which makes them sortable by all
314
+ usual Ruby means.
315
+
316
+ ### Renamed `*Manager` to `*List`
317
+
318
+ `Cinch::ChannelManager` and `Cinch::UserManager` have been renamed to
319
+ {Cinch::ChannelList} and {Cinch::UserList} respectively.
320
+
321
+ ## Added support for broken IRC networks
322
+ Special support for the following flawed IRC networks has been added:
323
+
324
+ - JustinTV
325
+ - NGameTV
326
+ - IRCnet
327
+
328
+ ## Dynamic timers
329
+
330
+ It is now possible to create new timers from any method/handler. It is
331
+ also possible to {Cinch::Timer#stop stop existing timers} or
332
+ {Cinch::Timer#start restart them}.
333
+
334
+ The easiest way of creating new timers is by using the
335
+ {Cinch::Helpers#Timer Timer helper method}, even though it is also
336
+ possible, albeit more complex, to create instances of {Cinch::Timer}
337
+ directly.
338
+
339
+ Example:
340
+
341
+ match /remind me in (\d+) seconds/
342
+ def execute(m, seconds)
343
+ Timer(seconds.to_i, shots: 1) do
344
+ m.reply "This is your reminder.", true
345
+ end
346
+ end
347
+
348
+ For more information on timers, see the {Cinch::Timer Timer documentation}.
349
+
350
+ ## New options
351
+
352
+ - :{file:bot_options.md#dccownip dcc.own_ip}
353
+ - :{file:bot_options.md#modes modes}
354
+ - :{file:bot_options.md#maxreconnectdelay max_reconnect_delay}
355
+ - :{file:bot_options.md#localhost local_host}
356
+ - :{file:bot_options.md#delayjoins delay_joins}
357
+ - :{file:bot_options.md#saslusername sasl.username}
358
+ - :{file:bot_options.md#saslpassword sasl.password}
359
+
360
+ ## New events
361
+ - :{file:events.md#action action}
362
+ - :{file:events.md#away away}
363
+ - :{file:events.md#unaway unaway}
364
+ - :{file:events.md#dccsend dcc_send}
365
+ - :{file:events.md#owner owner}
366
+ - :{file:events.md#dehalfop-deop-deowner-devoice deowner}
367
+ - :{file:events.md#leaving leaving}
368
+ - :{file:events.md#online online}
369
+ - :{file:events.md#offline offline}
370
+
371
+
372
+ # What has changed in 1.1?
373
+ 1. **New events**
374
+ 2. **New methods**
375
+ 3. **New options**
376
+ 4. **Improved logger**
377
+ x. **Deprecated methods**
378
+
379
+ ## New events
380
+
381
+ - :{file:events.md#op op}
382
+ - :{file:events.md#dehalfop-deop-deowner-devoice deop}
383
+ - :{file:events.md#voice voice}
384
+ - :{file:events.md#dehalfop-deop-deowner-devoice devoice}
385
+ - :{file:events.md#halfop halfop}
386
+ - :{file:events.md#dehalfop-deop-deowner-devoice dehalfop}
387
+ - :{file:events.md#ban ban}
388
+ - :{file:events.md#unban unban}
389
+ - :{file:events.md#modechange mode_change}
390
+ - :{file:events.md#catchall catchall}
391
+
392
+ Additionally, plugins are now able to send their own events by using
393
+ Cinch::Bot#dispatch.
394
+
395
+ ## New methods
396
+
397
+ ### {Cinch::User#last_nick}
398
+ Stores the last nick of a user. This can for example be used in `on
399
+ :nick` to compare a user's old nick against the new one.
400
+
401
+ ### Cinch::User#notice, Cinch::Channel#notice and Cinch::Bot#notice
402
+ For sending notices.
403
+
404
+ ### {Cinch::Message#to_s}
405
+ Provides a nicer representation of {Cinch::Message} objects.
406
+
407
+ ### {Cinch::Channel#has_user?}
408
+ Provides an easier way of checking if a given user is in a channel
409
+
410
+ ## New options
411
+ - {file:bot_options.md#pluginssuffix plugins.suffix}
412
+ - {file:bot_options.md#ssluse ssl.use}
413
+ - {file:bot_options.md#sslverify ssl.verify}
414
+ - {file:bot_options.md#sslcapath ssl.ca_path}
415
+ - {file:bot_options.md#sslclientcert ssl.client_cert}
416
+ - {file:bot_options.md#nicks nicks}
417
+ - {file:bot_options.md#timeoutsread timeouts.read}
418
+ - {file:bot_options.md#timeoutsconnect timeouts.connect}
419
+ - {file:bot_options.md#pinginterval ping_interval}
420
+ - {file:bot_options.md#reconnect reconnect}
421
+
422
+
423
+
424
+ ## Improved logger
425
+ The {Cinch::Logger::FormattedLogger formatted logger} (which is the
426
+ default one) now contains timestamps. Furthermore, it won't emit color
427
+ codes if not writing to a TTY.
428
+
429
+ Additionally, it can now log any kind of object, not only strings.
430
+
431
+ ## Deprecated methods
432
+
433
+ | Deprecated method | Replacement |
434
+ |-----------------------------+------------------------------------|
435
+ | Cinch::User.find_ensured | Cinch::UserManager#find_ensured |
436
+ | Cinch::User.find | Cinch::UserManager#find |
437
+ | Cinch::User.all | Cinch::UserManager#each |
438
+ | Cinch::Channel.find_ensured | Cinch::ChannelManager#find_ensured |
439
+ | Cinch::Channel.find | Cinch::ChannelManager#find |
440
+ | Cinch::Channel.all | Cinch::ChannelManager#each |
@@ -0,0 +1,35 @@
1
+ # @title Common mistakes
2
+
3
+ # I defined an initialize method in my plugin and now it doesn't work properly anymore
4
+
5
+ Cinch requires plugins to set certain states for them to work
6
+ properly. This is done by the initialize method of the Plugin module.
7
+ If you define your own initializer, make sure to accept an arbitrary
8
+ number of arguments (`*args`) and to call `super` as soon as possible.
9
+
10
+ ## Example
11
+
12
+ class MyPlugin
13
+ include Cinch::Plugin
14
+
15
+ def initialize(*args)
16
+ super
17
+ my own stuff here
18
+ end
19
+ end
20
+
21
+
22
+ # I am trying to use plugin options, but Ruby says it cannot find the `config` method
23
+
24
+ A common mistake is to try and use plugin options on class level, for example to manipulate matches. This cannot work because the class itself is not connected to any bot. Plugin options only work in instance methods of plugins.
25
+
26
+ The following is not possible:
27
+
28
+ class MyPlugin
29
+ include Cinch::Plugin
30
+
31
+ match(config[:pattern])
32
+ def execute(m)
33
+ # ...
34
+ end
35
+ end