ircinch 2.4.5 → 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.
- checksums.yaml +4 -4
- data/.standard.yml +1 -1
- data/CHANGELOG.md +10 -0
- data/CODE_OF_CONDUCT.md +7 -81
- data/README.md +39 -30
- data/docs/bot_options.md +207 -314
- data/docs/changes.md +293 -282
- data/docs/common_mistakes.md +50 -41
- data/docs/common_tasks.md +63 -42
- data/docs/encodings.md +28 -55
- data/docs/events.md +123 -131
- data/docs/getting_started.md +97 -102
- data/docs/logging.md +62 -70
- data/docs/migrating.md +145 -131
- data/docs/plugins.md +109 -3
- data/docs/readme.md +17 -15
- data/examples/README.md +78 -0
- data/examples/basic/autovoice.rb +14 -18
- data/examples/basic/google.rb +9 -22
- data/examples/basic/hello.rb +4 -3
- data/examples/basic/join_part.rb +8 -23
- data/examples/basic/memo.rb +26 -24
- data/examples/basic/msg.rb +6 -6
- data/examples/basic/seen.rb +17 -24
- data/examples/basic/urban_dict.rb +6 -26
- data/examples/basic/url_shorten.rb +8 -26
- data/examples/plugins/autovoice.rb +17 -16
- data/examples/plugins/custom_prefix.rb +4 -3
- data/examples/plugins/dice_roll.rb +13 -20
- data/examples/plugins/google.rb +7 -21
- data/examples/plugins/hello.rb +4 -3
- data/examples/plugins/hooks.rb +5 -6
- data/examples/plugins/join_part.rb +8 -21
- data/examples/plugins/lambdas.rb +5 -6
- data/examples/plugins/last_nick.rb +7 -6
- data/examples/plugins/msg.rb +6 -6
- data/examples/plugins/multiple_matches.rb +10 -11
- data/examples/plugins/own_events.rb +14 -19
- data/examples/plugins/seen.rb +23 -23
- data/examples/plugins/timer.rb +5 -6
- data/examples/plugins/url_shorten.rb +15 -19
- data/examples/settings.rb +19 -0
- data/examples/tiny_url.rb +41 -0
- data/ircinch.gemspec +5 -6
- data/lib/cinch/bot.rb +2 -3
- data/lib/cinch/channel.rb +4 -4
- data/lib/cinch/message_queue.rb +2 -2
- data/lib/cinch/plugin.rb +1 -1
- data/lib/cinch/version.rb +1 -1
- metadata +270 -249
- data/lib/cinch/rubyext/float.rb +0 -5
data/docs/events.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
# @markup kramdown
|
|
1
|
+
# Events
|
|
3
2
|
|
|
4
|
-
|
|
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"`
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
22
|
-
`:privmsg`, the underlying IRC command.
|
|
20
|
+
kicked or killed, and `:message` for incoming `PRIVMSG` commands.
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
## Events of the first two kinds
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
```ruby
|
|
31
|
+
on :topic do |m|
|
|
32
|
+
info "Topic changed in #{m.channel}"
|
|
33
|
+
end
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
on 401 do |m|
|
|
36
|
+
warn "Unknown nickname: #{m.params[1]}"
|
|
37
|
+
end
|
|
38
|
+
```
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
## Events of the third kind
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
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
|
|
54
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
101
|
+
See also [the `:private` event](#private).
|
|
109
102
|
|
|
110
|
-
|
|
111
|
-
connected to the IRC server.
|
|
103
|
+
### `:connect`
|
|
112
104
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
129
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
`:error`
|
|
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
|
-
|
|
170
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
189
|
+
[monitored user](common_tasks.md#checking-if-a-user-is-online)
|
|
197
190
|
goes offline.
|
|
198
191
|
|
|
199
|
-
|
|
200
|
-
handler.
|
|
201
|
-
|
|
192
|
+
The handler receives `nil` followed by the monitored user.
|
|
202
193
|
|
|
203
|
-
|
|
194
|
+
### `:online`
|
|
204
195
|
|
|
205
196
|
This event is triggered when a
|
|
206
|
-
|
|
197
|
+
[monitored user](common_tasks.md#checking-if-a-user-is-online)
|
|
207
198
|
comes online.
|
|
208
199
|
|
|
209
|
-
|
|
210
|
-
handler.
|
|
211
|
-
|
|
200
|
+
The handler receives `nil` followed by the monitored user.
|
|
212
201
|
|
|
213
|
-
|
|
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
|
-
|
|
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
|
-
|
|
240
|
-
the bot (think /query in traditional IRC clients).
|
|
222
|
+
### `:private`
|
|
241
223
|
|
|
242
|
-
|
|
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
|
-
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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
|
|
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
|
|
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.
|