ircinch 2.4.4 → 2.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.standard.yml +1 -1
  3. data/CHANGELOG.md +13 -0
  4. data/CODE_OF_CONDUCT.md +7 -81
  5. data/README.md +39 -30
  6. data/docs/bot_options.md +207 -314
  7. data/docs/changes.md +293 -282
  8. data/docs/common_mistakes.md +50 -41
  9. data/docs/common_tasks.md +63 -42
  10. data/docs/encodings.md +28 -55
  11. data/docs/events.md +123 -131
  12. data/docs/getting_started.md +97 -102
  13. data/docs/logging.md +62 -70
  14. data/docs/migrating.md +145 -131
  15. data/docs/plugins.md +109 -3
  16. data/docs/readme.md +17 -15
  17. data/examples/README.md +78 -0
  18. data/examples/basic/autovoice.rb +14 -18
  19. data/examples/basic/google.rb +9 -22
  20. data/examples/basic/hello.rb +4 -3
  21. data/examples/basic/join_part.rb +8 -23
  22. data/examples/basic/memo.rb +26 -24
  23. data/examples/basic/msg.rb +6 -6
  24. data/examples/basic/seen.rb +17 -24
  25. data/examples/basic/urban_dict.rb +6 -26
  26. data/examples/basic/url_shorten.rb +8 -26
  27. data/examples/plugins/autovoice.rb +17 -16
  28. data/examples/plugins/custom_prefix.rb +4 -3
  29. data/examples/plugins/dice_roll.rb +13 -20
  30. data/examples/plugins/google.rb +7 -21
  31. data/examples/plugins/hello.rb +4 -3
  32. data/examples/plugins/hooks.rb +5 -6
  33. data/examples/plugins/join_part.rb +8 -21
  34. data/examples/plugins/lambdas.rb +5 -6
  35. data/examples/plugins/last_nick.rb +7 -6
  36. data/examples/plugins/msg.rb +6 -6
  37. data/examples/plugins/multiple_matches.rb +10 -11
  38. data/examples/plugins/own_events.rb +14 -19
  39. data/examples/plugins/seen.rb +23 -23
  40. data/examples/plugins/timer.rb +5 -6
  41. data/examples/plugins/url_shorten.rb +15 -19
  42. data/examples/settings.rb +19 -0
  43. data/examples/tiny_url.rb +41 -0
  44. data/ircinch.gemspec +5 -6
  45. data/lib/cinch/bot.rb +2 -3
  46. data/lib/cinch/channel.rb +4 -4
  47. data/lib/cinch/irc.rb +2 -2
  48. data/lib/cinch/message_queue.rb +2 -2
  49. data/lib/cinch/plugin.rb +1 -1
  50. data/lib/cinch/version.rb +1 -1
  51. metadata +270 -249
  52. data/lib/cinch/rubyext/float.rb +0 -5
data/docs/events.md CHANGED
@@ -1,7 +1,7 @@
1
- # @title Events
2
- # @markup kramdown
1
+ # Events
3
2
 
4
- Cinch provides three kinds of events:
3
+ Register handlers with `on` on a bot or `listen_to` in a [plugin](plugins.md).
4
+ Each incoming IRC message can dispatch several events. IRCinch provides three kinds:
5
5
 
6
6
  1. Events mapping directly to IRC commands
7
7
 
@@ -10,152 +10,145 @@ Cinch provides three kinds of events:
10
10
 
11
11
  2. Events mapping directly to IRC numeric codes
12
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.
13
+ For example `:"401"` (`ERR_NOSUCHNICK`) and `:"318"` (`RPL_ENDOFWHOIS`).
14
+ Both `on` and `listen_to` also accept the numeric code as a string or integer.
15
+ See the [numeric constants](../lib/cinch/constants.rb).
17
16
 
18
17
  3. Events mapping to more abstract ideas
19
18
 
20
19
  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.
20
+ kicked or killed, and `:message` for incoming `PRIVMSG` commands.
23
21
 
24
- # Events of the first two kinds
22
+ ## Events of the first two kinds
25
23
 
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}.
24
+ The first handler argument is the [message object](../lib/cinch/message.rb).
25
+ With `on`, any extra arguments passed at registration come next, followed
26
+ by regular expression captures. Event-specific arguments follow the captures.
29
27
 
30
28
  Example:
31
29
 
32
- on :topic do |m|
33
- # m is the message object
34
- end
30
+ ```ruby
31
+ on :topic do |m|
32
+ info "Topic changed in #{m.channel}"
33
+ end
35
34
 
36
- We will not further describe all possible events of the first two
37
- categories.
35
+ on 401 do |m|
36
+ warn "Unknown nickname: #{m.params[1]}"
37
+ end
38
+ ```
38
39
 
39
- # Events of the third kind
40
+ ## Events of the third kind
40
41
 
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.
42
+ These events may add arguments, such as the user who left for `:leaving`.
43
+ For `:disconnect`, `:online`, and `:offline`, the first argument is `nil`.
45
44
 
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`
45
+ ### `:action`
51
46
 
52
47
  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.
48
+ channel or the bot, usually via `/me` in an IRC client. The `on` pattern
49
+ matches the action text, available as `m.action_message`.
56
50
 
57
51
  Example:
58
52
 
59
- on :action, "kicks the bot" do |m|
60
- m.reply "Ouch! Stop kicking me :(", true
61
- end
62
-
53
+ ```ruby
54
+ on :action, "kicks the bot" do |m|
55
+ m.reply "Ouch! Stop kicking me :(", true
56
+ end
57
+ ```
63
58
 
64
- ## `:away`
59
+ ### `:away`
65
60
 
66
61
  The `:away` event is triggered when a user goes away. This feature
67
62
  only works on networks implementing the "away-notify" extension.
68
63
 
69
64
  Example:
70
65
 
71
- on :away do |m|
72
- debug("User %s just went away: %s" % [m.user, m.message])
73
- end
66
+ ```ruby
67
+ on :away do |m|
68
+ debug("User %s just went away: %s" % [m.user, m.message])
69
+ end
70
+ ```
74
71
 
75
- See also {file:docs/events.md#unaway the `:unaway` event}.
72
+ See also [the `:unaway` event](#unaway).
76
73
 
77
-
78
- ## `:ban`
74
+ ### `:ban`
79
75
 
80
76
  The `:ban` event is triggered when a user gets banned in a channel.
81
77
 
82
- One additional argument, a {Cinch::Ban Ban object}, gets passed to
78
+ One additional argument, a [Ban object](../lib/cinch/ban.rb), gets passed to
83
79
  the handler.
84
80
 
85
81
  Example:
86
82
 
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}.
83
+ ```ruby
84
+ on :ban do |m, ban|
85
+ debug("%s just banned %s" % [ban.by, ban.mask])
86
+ end
87
+ ```
92
88
 
89
+ See also [the `:unban` event](#unban).
93
90
 
94
- ## `:catchall`
91
+ ### `:catchall`
95
92
 
96
93
  `:catchall` is a special event that gets triggered for every incoming
97
94
  IRC message/command, no matter what the type is.
98
95
 
96
+ ### `:channel`
99
97
 
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
-
98
+ The `:channel` event is triggered for `PRIVMSG` and `NOTICE` sent to a
99
+ channel, including messages addressed to a subset of users via `STATUSMSG`.
107
100
 
108
- ## `:connect`
101
+ See also [the `:private` event](#private).
109
102
 
110
- The `:connect` event is triggered after the bot successfully
111
- connected to the IRC server.
103
+ ### `:connect`
112
104
 
113
- One common use case for this event is setting up variables,
114
- synchronising information etc.
115
-
116
-
117
- ## `:ctcp`
105
+ The `:connect` event is dispatched during successful IRC registration,
106
+ before channel membership is guaranteed. It can be dispatched more than
107
+ once on a connection as the remaining registration numerics arrive. Use
108
+ `:join` and check `m.user == bot` for work that requires the bot to be in a
109
+ channel.
118
110
 
119
- The `:ctcp` event is triggered when receiving CTCP-related messages,
120
- for example the VERSION request.
111
+ ### `:ctcp`
121
112
 
113
+ The `:ctcp` event is triggered for CTCP payloads in `PRIVMSG` or `NOTICE`,
114
+ such as a `VERSION` request. Access the command and arguments through
115
+ `m.ctcp_command` and `m.ctcp_args`.
122
116
 
123
- ## `:dcc_send`
117
+ ### `:dcc_send`
124
118
 
125
119
  `:dcc_send` gets triggered when a user tries to send a file to the
126
120
  bot, using the DCC SEND protocol.
127
121
 
128
- One additional argument, a {Cinch::DCC::Incoming::Send DCC::Send
129
- object}, gets passed to the handler.
122
+ The second argument is a [`Cinch::DCC::Incoming::Send`](../lib/cinch/dcc/incoming/send.rb)
123
+ offer. See [DCC file transfers](common_tasks.md#dcc-file-transfers).
130
124
 
131
- For example usage and a general explanation of DCC in Cinch check
132
- {Cinch::DCC::Incoming::Send}.
125
+ ### `:disconnect`
133
126
 
127
+ Fires after the IRC socket closes at the end of the read loop. The message
128
+ argument is `nil`. An initial TCP connection failure does not emit this event.
134
129
 
135
- ## `:dehalfop`, `:deop`, `:deowner`, `:devoice`
130
+ ### `:dehalfop`, `:deop`, `:deowner`, `:devoice`
136
131
 
137
132
  These events get triggered for the respective channel operations of
138
133
  taking halfop, op, owner and voice from a user.
139
134
 
140
- One additional argument, the user whose rights are being modifed, gets
135
+ One additional argument, the user whose rights are being modified, gets
141
136
  passed to the handler.
142
137
 
138
+ ### `:error`
143
139
 
144
- ## `:error`
145
-
146
- `:error` gets triggered for all numeric replies that signify errors
147
- (`ERR_*`).
140
+ `:error` is dispatched for numeric replies in the `400`–`599` range.
141
+ `m.error` contains the numeric code as an integer. The IRC `ERROR` command
142
+ also dispatches `:error` through its command name.
148
143
 
149
-
150
- ## `:halfop`
144
+ ### `:halfop`
151
145
 
152
146
  This event gets triggered when a user in a channel gets half-opped.
153
147
 
154
148
  One additional argument, the user being half-opped, gets passed to the
155
149
  handler.
156
150
 
157
-
158
- ## `:leaving`
151
+ ### `:leaving`
159
152
 
160
153
  `:leaving` is an event that is triggered whenever any of the following
161
154
  are triggered as well: `:part`, `:quit`, `:kick`, `:kill`.
@@ -166,60 +159,54 @@ or the network, no matter the reason.
166
159
  One additional argument, the leaving user, gets passed to the handler.
167
160
 
168
161
  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
162
+ [`Cinch::Message#user`](../lib/cinch/message.rb). For example in the case of a kick,
163
+ [`Cinch::Message#user`](../lib/cinch/message.rb) will describe the user kicking someone, not the
171
164
  one who is being kicked.
172
165
 
173
166
  Example:
174
167
 
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
-
168
+ ```ruby
169
+ on :leaving do |m, user|
170
+ if m.channel?
171
+ debug("%s just left %s." % [user, m.channel])
172
+ else
173
+ debug("%s just left the network." % user)
174
+ end
175
+ end
176
+ ```
183
177
 
178
+ ### `:mode_change`
184
179
 
185
- ## `:mode_change`
180
+ Fires for channel `MODE` changes. The second argument is an array of
181
+ `[direction, mode, parameter]` triples. `direction` is `:add` or `:remove`,
182
+ `mode` is a one-letter string, and `parameter` is a string or `nil`.
183
+ Use `:mode` to observe raw `MODE` messages, including changes to the bot's
184
+ own user modes.
186
185
 
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`
186
+ ### `:offline`
194
187
 
195
188
  This event is triggered when a
196
- {file:docs/common_tasks.md#checking-if-a-user-is-online monitored user}
189
+ [monitored user](common_tasks.md#checking-if-a-user-is-online)
197
190
  goes offline.
198
191
 
199
- One additional argument, the user going offline, gets passed to the
200
- handler.
201
-
192
+ The handler receives `nil` followed by the monitored user.
202
193
 
203
- ## `:online`
194
+ ### `:online`
204
195
 
205
196
  This event is triggered when a
206
- {file:docs/common_tasks.md#checking-if-a-user-is-online monitored user}
197
+ [monitored user](common_tasks.md#checking-if-a-user-is-online)
207
198
  comes online.
208
199
 
209
- One additional argument, the user coming online, gets passed to the
210
- handler.
211
-
200
+ The handler receives `nil` followed by the monitored user.
212
201
 
213
- ## `:op`
202
+ ### `:op`
214
203
 
215
204
  This event gets triggered when a user in a channel gets opped.
216
205
 
217
206
  One additional argument, the user being opped, gets passed to the
218
207
  handler.
219
208
 
220
-
221
- ## `:owner`
222
-
209
+ ### `:owner`
223
210
 
224
211
  This event gets triggered when a user in a channel receives
225
212
  owner-status.
@@ -227,22 +214,19 @@ owner-status.
227
214
  One additional argument, the user receiving owner-status, gets passed
228
215
  to the handler.
229
216
 
217
+ ### `:message`
230
218
 
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`
219
+ The `:message` and `:privmsg` events both fire for an incoming `PRIVMSG` to
220
+ a channel or directly to the bot, including CTCP requests carried in `PRIVMSG`.
238
221
 
239
- The `:private` event is triggered for messages directly towarded at
240
- the bot (think /query in traditional IRC clients).
222
+ ### `:private`
241
223
 
242
- See also {file:docs/events.md#channel the `:channel` event}.
224
+ The `:private` event is triggered for `PRIVMSG` and `NOTICE` directed to
225
+ the bot outside a channel.
243
226
 
227
+ See also [the `:channel` event](#channel).
244
228
 
245
- ## `:unaway`
229
+ ### `:unaway`
246
230
 
247
231
  The `:unaway` event is triggered when a user no longer is away. This
248
232
  feature only works on networks implementing the "away-notify"
@@ -250,24 +234,32 @@ extension.
250
234
 
251
235
  Example:
252
236
 
253
- on :unaway do |m|
254
- debug("User %s no longer is away." % m.user)
255
- end
237
+ ```ruby
238
+ on :unaway do |m|
239
+ debug("User %s no longer is away." % m.user)
240
+ end
241
+ ```
256
242
 
257
- See also {file:docs/events.md#away the `:away` event}.
243
+ See also [the `:away` event](#away).
258
244
 
259
-
260
- ## `:unban`
245
+ ### `:unban`
261
246
 
262
247
  The `:unban` event is triggered when a user gets unbanned in a
263
248
  channel.
264
249
 
265
- One additional argument, a {Cinch::Ban Ban object}, gets passed to the
250
+ One additional argument, a [Ban object](../lib/cinch/ban.rb), gets passed to the
266
251
  handler.
267
252
 
253
+ ### `:voice`
268
254
 
269
- ## `:voice`
270
255
  This event gets triggered when a user in a channel gets voiced.
271
256
 
272
257
  One additional argument, the user being voiced, gets passed to the
273
258
  handler.
259
+
260
+ ## Custom events
261
+
262
+ Call `bot.handlers.dispatch(:event_name, message, *args)` to notify handlers
263
+ registered for your own event. Pass `nil` when there is no originating IRC
264
+ message and use a [listener](plugins.md#listening-to-events) to receive it.
265
+ The public dispatcher returns the threads started for the handlers.