grinch 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +1 -0
  3. data/LICENSE +22 -0
  4. data/README.md +180 -0
  5. data/docs/bot_options.md +454 -0
  6. data/docs/changes.md +541 -0
  7. data/docs/common_mistakes.md +60 -0
  8. data/docs/common_tasks.md +57 -0
  9. data/docs/encodings.md +69 -0
  10. data/docs/events.md +273 -0
  11. data/docs/getting_started.md +184 -0
  12. data/docs/logging.md +90 -0
  13. data/docs/migrating.md +267 -0
  14. data/docs/plugins.md +4 -0
  15. data/docs/readme.md +20 -0
  16. data/examples/basic/autovoice.rb +32 -0
  17. data/examples/basic/google.rb +35 -0
  18. data/examples/basic/hello.rb +15 -0
  19. data/examples/basic/join_part.rb +34 -0
  20. data/examples/basic/memo.rb +39 -0
  21. data/examples/basic/msg.rb +16 -0
  22. data/examples/basic/seen.rb +36 -0
  23. data/examples/basic/urban_dict.rb +35 -0
  24. data/examples/basic/url_shorten.rb +35 -0
  25. data/examples/plugins/autovoice.rb +37 -0
  26. data/examples/plugins/custom_prefix.rb +23 -0
  27. data/examples/plugins/dice_roll.rb +38 -0
  28. data/examples/plugins/google.rb +36 -0
  29. data/examples/plugins/hello.rb +22 -0
  30. data/examples/plugins/hooks.rb +36 -0
  31. data/examples/plugins/join_part.rb +42 -0
  32. data/examples/plugins/lambdas.rb +35 -0
  33. data/examples/plugins/last_nick.rb +24 -0
  34. data/examples/plugins/msg.rb +22 -0
  35. data/examples/plugins/multiple_matches.rb +32 -0
  36. data/examples/plugins/own_events.rb +37 -0
  37. data/examples/plugins/seen.rb +45 -0
  38. data/examples/plugins/timer.rb +22 -0
  39. data/examples/plugins/url_shorten.rb +33 -0
  40. data/lib/cinch.rb +5 -0
  41. data/lib/cinch/ban.rb +50 -0
  42. data/lib/cinch/bot.rb +479 -0
  43. data/lib/cinch/cached_list.rb +19 -0
  44. data/lib/cinch/callback.rb +20 -0
  45. data/lib/cinch/channel.rb +463 -0
  46. data/lib/cinch/channel_list.rb +29 -0
  47. data/lib/cinch/configuration.rb +73 -0
  48. data/lib/cinch/configuration/bot.rb +48 -0
  49. data/lib/cinch/configuration/dcc.rb +16 -0
  50. data/lib/cinch/configuration/plugins.rb +41 -0
  51. data/lib/cinch/configuration/sasl.rb +19 -0
  52. data/lib/cinch/configuration/ssl.rb +19 -0
  53. data/lib/cinch/configuration/timeouts.rb +14 -0
  54. data/lib/cinch/constants.rb +533 -0
  55. data/lib/cinch/dcc.rb +12 -0
  56. data/lib/cinch/dcc/dccable_object.rb +37 -0
  57. data/lib/cinch/dcc/incoming.rb +1 -0
  58. data/lib/cinch/dcc/incoming/send.rb +147 -0
  59. data/lib/cinch/dcc/outgoing.rb +1 -0
  60. data/lib/cinch/dcc/outgoing/send.rb +122 -0
  61. data/lib/cinch/exceptions.rb +46 -0
  62. data/lib/cinch/formatting.rb +125 -0
  63. data/lib/cinch/handler.rb +118 -0
  64. data/lib/cinch/handler_list.rb +90 -0
  65. data/lib/cinch/helpers.rb +231 -0
  66. data/lib/cinch/irc.rb +924 -0
  67. data/lib/cinch/isupport.rb +98 -0
  68. data/lib/cinch/log_filter.rb +21 -0
  69. data/lib/cinch/logger.rb +168 -0
  70. data/lib/cinch/logger/formatted_logger.rb +97 -0
  71. data/lib/cinch/logger/zcbot_logger.rb +22 -0
  72. data/lib/cinch/logger_list.rb +85 -0
  73. data/lib/cinch/mask.rb +69 -0
  74. data/lib/cinch/message.rb +392 -0
  75. data/lib/cinch/message_queue.rb +107 -0
  76. data/lib/cinch/mode_parser.rb +76 -0
  77. data/lib/cinch/network.rb +104 -0
  78. data/lib/cinch/open_ended_queue.rb +26 -0
  79. data/lib/cinch/pattern.rb +65 -0
  80. data/lib/cinch/plugin.rb +515 -0
  81. data/lib/cinch/plugin_list.rb +38 -0
  82. data/lib/cinch/rubyext/float.rb +3 -0
  83. data/lib/cinch/rubyext/module.rb +26 -0
  84. data/lib/cinch/rubyext/string.rb +33 -0
  85. data/lib/cinch/sasl.rb +34 -0
  86. data/lib/cinch/sasl/dh_blowfish.rb +71 -0
  87. data/lib/cinch/sasl/diffie_hellman.rb +47 -0
  88. data/lib/cinch/sasl/mechanism.rb +6 -0
  89. data/lib/cinch/sasl/plain.rb +26 -0
  90. data/lib/cinch/syncable.rb +83 -0
  91. data/lib/cinch/target.rb +199 -0
  92. data/lib/cinch/timer.rb +145 -0
  93. data/lib/cinch/user.rb +488 -0
  94. data/lib/cinch/user_list.rb +87 -0
  95. data/lib/cinch/utilities/deprecation.rb +16 -0
  96. data/lib/cinch/utilities/encoding.rb +37 -0
  97. data/lib/cinch/utilities/kernel.rb +13 -0
  98. data/lib/cinch/version.rb +4 -0
  99. metadata +140 -0
@@ -0,0 +1,60 @@
1
+ # @title Common mistakes
2
+ # @markup kramdown
3
+
4
+ # I defined an initialize method in my plugin and now it doesn't work properly anymore
5
+
6
+ Cinch requires plugins to set certain states for them to work
7
+ properly. This is done by the initialize method of the Plugin module.
8
+ If you define your own initializer, make sure to accept an arbitrary
9
+ number of arguments (`*args`) and to call `super` as soon as possible.
10
+
11
+ ## Example
12
+
13
+ class MyPlugin
14
+ include Cinch::Plugin
15
+
16
+ def initialize(*args)
17
+ super
18
+ my own stuff here
19
+ end
20
+ end
21
+
22
+
23
+ # I am trying to use plugin options, but Ruby says it cannot find the `config` method
24
+
25
+ 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.
26
+
27
+ The following is not possible:
28
+
29
+ class MyPlugin
30
+ include Cinch::Plugin
31
+
32
+ match(config[:pattern])
33
+ def execute(m)
34
+ # ...
35
+ end
36
+ end
37
+
38
+ # My handlers won't run, even though the Regexp matches.
39
+
40
+ Cinch plugins have a default prefix (`/^!/`). This allows for flexible prefixes
41
+ across the whole bot. The default prefix can be changed in `Bot#configure`:
42
+
43
+ x = Cinch::Bot.new do
44
+ configure do |c|
45
+ # ...
46
+ c.plugins.prefix = /^%/
47
+ end
48
+ end
49
+
50
+ Alternatively, you can set the prefix for specific plugins only, by calling `set`:
51
+
52
+ class MyPlygin
53
+ include Cinch::Plugin
54
+
55
+ set :prefix, /^%/
56
+ end
57
+
58
+ You can also choose to not use a prefix for specific matchers:
59
+
60
+ match /hi/, use_prefix: false
@@ -0,0 +1,57 @@
1
+ # @title Common Tasks
2
+ # @markup kramdown
3
+
4
+ # Checking if a user is online
5
+
6
+ Cinch by itself tries to keep track of the online state of users.
7
+ Whenever it sees someone speak, change their nick or be in a channel the
8
+ bot is also in, it'll set the user to being online. And when a user
9
+ quits, gets killed or cannot be whoised/contacted, its state will be
10
+ set to offline.
11
+
12
+ A problem with that information is that it can quickly become out of
13
+ sync. Consider the following example:
14
+
15
+ The bot joins a channel, sees someone in the name list and thus marks
16
+ him as online. The bot then leaves the channel and at some later
17
+ point, the user disconnects. The bot won't know that and still track
18
+ the user as online.
19
+
20
+ If (near-)realtime information about this state is required, one can
21
+ use {Cinch::User#monitor} to automatically monitor the state.
22
+ {Cinch::User#monitor #monitor} uses either the _MONITOR_ feature of modern IRCds or, if
23
+ that's not available, periodically runs _WHOIS_ to update the
24
+ information.
25
+
26
+ Whenever a user's state changes, either the `:online` or the
27
+ `:offline` event will be fired, as can be seen in the following
28
+ example:
29
+
30
+ class SomePlugin
31
+ include Cinch::Plugin
32
+
33
+ listen_to :connect, method: :on_connect
34
+ listen_to :online, method: :on_online
35
+ listen_to :offline, method: :on_offline
36
+
37
+ def on_connect(m)
38
+ User("my_master").monitor
39
+ end
40
+
41
+ def on_online(m, user)
42
+ user.send "Hello master"
43
+ end
44
+
45
+ def on_offline(m, user)
46
+ @bot.loggers.info "I miss my master :("
47
+ end
48
+ end
49
+
50
+ # Sending messages to users and channels beside `m.user` and `m.channel`
51
+
52
+ Cinch provides {Cinch::Helpers helper methods} to get instances of Channel
53
+ and User objects that you can work with:
54
+
55
+ User('user').send("Hello!") # Sends a message to user 'user'
56
+ Channel('#channel').send("Hello!") # Sends a message to channel '#channel'
57
+
data/docs/encodings.md ADDED
@@ -0,0 +1,69 @@
1
+ # @title Encodings
2
+ # @markup kramdown
3
+
4
+ # Encodings
5
+
6
+ The IRC protocol doesn't define a specific encoding that should be
7
+ used, nor does it provide any information on which encodings _are_
8
+ being used.
9
+
10
+ At the same time, lots of different encodings have become popular on
11
+ IRC. This presents a big problem, because, if you're using a different
12
+ encoding than someone else on IRC, you'll receive their text as
13
+ garbage.
14
+
15
+ Cinch tries to work around this issue in two ways, while also keeping
16
+ the usual Ruby behaviour.
17
+
18
+ ## The `encoding` option
19
+ By setting {file:docs/bot_options.md#encoding the `encoding` option}, you
20
+ set your expectations on what encoding other users will use. Allowed
21
+ values are instances of Encoding, names of valid encodings (as
22
+ strings) and the special `:irc` encoding, which will be explained
23
+ further down.
24
+
25
+
26
+ ## Encoding.default_internal
27
+ If set, Cinch will automatically convert incoming messages to the
28
+ encoding defined by `Encoding.default_internal`, unless the special
29
+ encoding `:irc` is being used as the {file:docs/bot_options.md#encoding
30
+ `encoding option`}
31
+
32
+ ## The `:irc` encoding
33
+ As mentioned earlier, people couldn't decide on a single encoding to
34
+ use. As such, specifying a single encoding would most likely lead to
35
+ problems, especially if the bot is in more than one channel.
36
+
37
+ Luckily, even though people cannot decide on a single encoding,
38
+ western countries usually either use CP1252 (Windows Latin-1) or
39
+ UTF-8. Since text encoded in CP1252 fails validation as UTF-8, it is
40
+ easy to tell the two apart. Additionally it is possible to losslessly
41
+ re-encode CP1252 in UTF-8 and as such, a small subset of UTF-8 is also
42
+ representable in CP1252.
43
+
44
+ If incoming text is valid UTF-8, it will be interpreted as such. If it
45
+ fails validation, a CP1252 → UTF-8 conversion is performed. This
46
+ ensures that you will always deal with UTF-8 in your code, even if
47
+ other people use CP1252. Note, however, that we ignore
48
+ `Encoding.default_internal` in this case and always present you with
49
+ UTF-8.
50
+
51
+ If text you send contains only characters that fit inside the
52
+ CP1252 code page, the entire line will be sent that way.
53
+
54
+ If the text doesn't fit inside the CP1252 code page, (for example if
55
+ you type Eastern European characters, or Russian) it will be sent as
56
+ UTF-8. Only UTF-8 capable clients will be able to see these characters
57
+ correctly.
58
+
59
+ ## Invalid bytes and unsupported translations
60
+ If Cinch receives text in an encoding other than the one assumed, it
61
+ can happen that the message contains bytes that are not valid in the
62
+ assumed encoding. Instead of dropping the complete message, Cinch will
63
+ replace offending bytes with question marks.
64
+
65
+ Also, if you expect messages in e.g. UTF-8 but re-encode them in
66
+ CP1252 (by setting `Encoding.default_internal` to CP1252), it can
67
+ happen that some characters cannot be represented in CP1252. In such a
68
+ case, Cinch will too replace the offending characters with question
69
+ marks.
data/docs/events.md ADDED
@@ -0,0 +1,273 @@
1
+ # @title Events
2
+ # @markup kramdown
3
+
4
+ Cinch provides three kinds of events:
5
+
6
+ 1. Events mapping directly to IRC commands
7
+
8
+ For example `:topic`, which will be triggered when someone changes
9
+ the topic, or `:kick`, when someone gets kicked.
10
+
11
+ 2. Events mapping directly to IRC numeric codes
12
+
13
+ For example `:"401"` for `ERR_NOSUCHNICK`, which is triggered when
14
+ trying to operate on an unknown nickname, or `:"318"` for
15
+ `RPL_ENDOFWHOIS`, which is triggered after whois information have
16
+ been received.
17
+
18
+ 3. Events mapping to more abstract ideas
19
+
20
+ For example `:leaving` whenever a user parts, quits or gets
21
+ kicked/killed or `:message`, which is actually a synonym for
22
+ `:privmsg`, the underlying IRC command.
23
+
24
+ # Events of the first two kinds
25
+
26
+ All events of the first two kinds behave exactly the same: When they
27
+ get triggered, the handler will be passed a single object, a reference
28
+ to the {Cinch::Message Message object}.
29
+
30
+ Example:
31
+
32
+ on :topic do |m|
33
+ # m is the message object
34
+ end
35
+
36
+ We will not further describe all possible events of the first two
37
+ categories.
38
+
39
+ # Events of the third kind
40
+
41
+ Events of the third kind can each have different signatures, as they
42
+ get passed objects directly relating to their kind, for example the
43
+ leaving user in case of `:leaving`. This document will describe all
44
+ events of that kind, their signature and example usage.
45
+
46
+ **Note: Because *all* handlers receive a {Cinch::Message Message}
47
+ object as the first argument, we will only mention and describe
48
+ additional arguments.**
49
+
50
+ ## `:action`
51
+
52
+ The `:action` event is triggered when a user sends a CTCP ACTION to a
53
+ channel or the bot. CTCP ACTION is commonly refered to simply as
54
+ "actions" or "/me's", because that is the command used in most IRC
55
+ clients.
56
+
57
+ Example:
58
+
59
+ on :action, "kicks the bot" do |m|
60
+ m.reply "Ouch! Stop kicking me :(", true
61
+ end
62
+
63
+
64
+ ## `:away`
65
+
66
+ The `:away` event is triggered when a user goes away. This feature
67
+ only works on networks implementing the "away-notify" extension.
68
+
69
+ Example:
70
+
71
+ on :away do |m|
72
+ debug("User %s just went away: %s" % [m.user, m.message])
73
+ end
74
+
75
+ See also {file:docs/events.md#unaway the `:unaway` event}.
76
+
77
+
78
+ ## `:ban`
79
+
80
+ The `:ban` event is triggered when a user gets banned in a channel.
81
+
82
+ One additional argument, a {Cinch::Ban Ban object}, gets passed to
83
+ the handler.
84
+
85
+ Example:
86
+
87
+ on :ban do |m, ban|
88
+ debug("%s just banned %s" % [ban.by, ban.mask])
89
+ end
90
+
91
+ See also {file:docs/events.md#unban the `:unban` event}.
92
+
93
+
94
+ ## `:catchall`
95
+
96
+ `:catchall` is a special event that gets triggered for every incoming
97
+ IRC message/command, no matter what the type is.
98
+
99
+
100
+ ## `:channel`
101
+
102
+ The `:channel` event is triggered for channel messages (the usual
103
+ form of communication on IRC).
104
+
105
+ See also {file:docs/events.md#private the `:private` event}.
106
+
107
+
108
+ ## `:connect`
109
+
110
+ The `:connect` event is triggered after the bot successfully
111
+ connected to the IRC server.
112
+
113
+ One common use case for this event is setting up variables,
114
+ synchronising information etc.
115
+
116
+
117
+ ## `:ctcp`
118
+
119
+ The `:ctcp` event is triggered when receiving CTCP-related messages,
120
+ for example the VERSION request.
121
+
122
+
123
+ ## `:dcc_send`
124
+
125
+ `:dcc_send` gets triggered when a user tries to send a file to the
126
+ bot, using the DCC SEND protocol.
127
+
128
+ One additional argument, a {Cinch::DCC::Incoming::Send DCC::Send
129
+ object}, gets passed to the handler.
130
+
131
+ For example usage and a general explanation of DCC in Cinch check
132
+ {Cinch::DCC::Incoming::Send}.
133
+
134
+
135
+ ## `:dehalfop`, `:deop`, `:deowner`, `:devoice`
136
+
137
+ These events get triggered for the respective channel operations of
138
+ taking halfop, op, owner and voice from a user.
139
+
140
+ One additional argument, the user whose rights are being modifed, gets
141
+ passed to the handler.
142
+
143
+
144
+ ## `:error`
145
+
146
+ `:error` gets triggered for all numeric replies that signify errors
147
+ (`ERR_*`).
148
+
149
+
150
+ ## `:halfop`
151
+
152
+ This event gets triggered when a user in a channel gets half-opped.
153
+
154
+ One additional argument, the user being half-opped, gets passed to the
155
+ handler.
156
+
157
+
158
+ ## `:leaving`
159
+
160
+ `:leaving` is an event that is triggered whenever any of the following
161
+ are triggered as well: `:part`, `:quit`, `:kick`, `:kill`.
162
+
163
+ The event can thus be used for noticing when a user leaves a channel
164
+ or the network, no matter the reason.
165
+
166
+ One additional argument, the leaving user, gets passed to the handler.
167
+
168
+ Be careful not to confuse the additional argument with
169
+ {Cinch::Message#user}. For example in the case of a kick,
170
+ {Cinch::Message#user} will describe the user kicking someone, not the
171
+ one who is being kicked.
172
+
173
+ Example:
174
+
175
+ on :leaving do |m, user|
176
+ if m.channel?
177
+ debug("%s just left %s." % [user, m.channel])
178
+ else
179
+ debug("%s just left the network." % user)
180
+ end
181
+ end
182
+
183
+
184
+
185
+ ## `:mode_change`
186
+
187
+ This event gets triggered whenever modes in a channel or on the bot
188
+ directly change. Unlike events like `:op`, this event is more
189
+ low-level, as the argument the handler gets passed is an array
190
+ describing every change.
191
+
192
+
193
+ ## `:offline`
194
+
195
+ This event is triggered when a
196
+ {file:docs/common_tasks.md#checking-if-a-user-is-online monitored user}
197
+ goes offline.
198
+
199
+ One additional argument, the user going offline, gets passed to the
200
+ handler.
201
+
202
+
203
+ ## `:online`
204
+
205
+ This event is triggered when a
206
+ {file:docs/common_tasks.md#checking-if-a-user-is-online monitored user}
207
+ comes online.
208
+
209
+ One additional argument, the user coming online, gets passed to the
210
+ handler.
211
+
212
+
213
+ ## `:op`
214
+
215
+ This event gets triggered when a user in a channel gets opped.
216
+
217
+ One additional argument, the user being opped, gets passed to the
218
+ handler.
219
+
220
+
221
+ ## `:owner`
222
+
223
+
224
+ This event gets triggered when a user in a channel receives
225
+ owner-status.
226
+
227
+ One additional argument, the user receiving owner-status, gets passed
228
+ to the handler.
229
+
230
+
231
+ ## `:message`
232
+
233
+ The `:message` event is triggered for messages directed at either a
234
+ channel or directly at the bot. It's synonymous with `:privmsg`.
235
+
236
+
237
+ ## `:private`
238
+
239
+ The `:private` event is triggered for messages directly towarded at
240
+ the bot (think /query in traditional IRC clients).
241
+
242
+ See also {file:docs/events.md#channel the `:channel` event}.
243
+
244
+
245
+ ## `:unaway`
246
+
247
+ The `:unaway` event is triggered when a user no longer is away. This
248
+ feature only works on networks implementing the "away-notify"
249
+ extension.
250
+
251
+ Example:
252
+
253
+ on :unaway do |m|
254
+ debug("User %s no longer is away." % m.user)
255
+ end
256
+
257
+ See also {file:docs/events.md#away the `:away` event}.
258
+
259
+
260
+ ## `:unban`
261
+
262
+ The `:unban` event is triggered when a user gets unbanned in a
263
+ channel.
264
+
265
+ One additional argument, a {Cinch::Ban Ban object}, gets passed to the
266
+ handler.
267
+
268
+
269
+ ## `:voice`
270
+ This event gets triggered when a user in a channel gets voiced.
271
+
272
+ One additional argument, the user being voiced, gets passed to the
273
+ handler.