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.
- checksums.yaml +4 -4
- data/.standard.yml +1 -1
- data/CHANGELOG.md +13 -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/irc.rb +2 -2
- 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/migrating.md
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
# @title Migration Guide
|
|
2
|
-
# @markup kramdown
|
|
3
|
-
|
|
4
1
|
# Migration Guide
|
|
5
2
|
|
|
6
|
-
This
|
|
7
|
-
|
|
3
|
+
This guide records the API changes between the original Cinch 1.x and 2.x
|
|
4
|
+
releases. For a new IRCinch project, start with [Getting Started](getting_started.md)
|
|
5
|
+
and use `require "ircinch"`.
|
|
8
6
|
|
|
9
7
|
## Migrating from 1.x to 2.x
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
### Plugins
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
#### New methods
|
|
14
12
|
|
|
15
13
|
Plugins have the following (new) instance and class methods, which you
|
|
16
14
|
shouldn't and usually mustn't overwrite:
|
|
@@ -49,8 +47,7 @@ shouldn't and usually mustn't overwrite:
|
|
|
49
47
|
|
|
50
48
|
Note: The list does also include methods from prior versions.
|
|
51
49
|
|
|
52
|
-
|
|
53
|
-
### Plugin options
|
|
50
|
+
#### Plugin options
|
|
54
51
|
|
|
55
52
|
Previously, plugins used a DSL-like way of setting options like the
|
|
56
53
|
plugin prefix. This contradicts with the general idea of plugins being
|
|
@@ -60,117 +57,126 @@ smell.
|
|
|
60
57
|
Instead of having methods like `#prefix` double as both attribute
|
|
61
58
|
getter and setter, options can now be set in two different ways: Using
|
|
62
59
|
ordinary attribute setters or using the
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
60
|
+
[`#set`](../lib/cinch/plugin.rb) method.
|
|
61
|
+
|
|
62
|
+
##### Cinch 1.x
|
|
63
|
+
|
|
64
|
+
```ruby
|
|
65
|
+
class MyPlugin
|
|
66
|
+
include Cinch::Plugin
|
|
67
|
+
|
|
68
|
+
prefix /^!/
|
|
69
|
+
help "some help message"
|
|
70
|
+
match /foo/
|
|
71
|
+
def execute(m)
|
|
72
|
+
# ...
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
##### Cinch 2.x, attribute setters
|
|
78
|
+
|
|
79
|
+
```ruby
|
|
80
|
+
class MyPlugin
|
|
81
|
+
include Cinch::Plugin
|
|
82
|
+
|
|
83
|
+
self.prefix = /^!/
|
|
84
|
+
self.help = "some help message"
|
|
85
|
+
match /foo/
|
|
86
|
+
def execute(m)
|
|
87
|
+
# ...
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
##### Cinch 2.x, `#set` method
|
|
93
|
+
|
|
94
|
+
```ruby
|
|
95
|
+
class MyPlugin
|
|
96
|
+
include Cinch::Plugin
|
|
97
|
+
|
|
98
|
+
set :prefix, /^!/
|
|
99
|
+
set :help, "some help message"
|
|
100
|
+
match /foo/
|
|
101
|
+
def execute(m)
|
|
102
|
+
# ...
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
##### Cinch 2.x, `#set` method, alternative syntax
|
|
108
|
+
|
|
109
|
+
```ruby
|
|
110
|
+
class MyPlugin
|
|
111
|
+
include Cinch::Plugin
|
|
112
|
+
|
|
113
|
+
set prefix: /^!/,
|
|
114
|
+
help: "some help message"
|
|
115
|
+
match /foo/
|
|
116
|
+
def execute(m)
|
|
117
|
+
# ...
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### No more automatic matcher with the plugin's name
|
|
119
123
|
|
|
120
124
|
Cinch does not add a default matcher with the plugin's name anymore.
|
|
121
125
|
If you've been relying on the following to work
|
|
122
126
|
|
|
123
|
-
|
|
124
|
-
|
|
127
|
+
```ruby
|
|
128
|
+
class Footastic
|
|
129
|
+
include Cinch::Plugin
|
|
125
130
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
def execute(m)
|
|
132
|
+
# this will triger on "!footastic"
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
```
|
|
130
136
|
|
|
131
137
|
you will have to rewrite it using an explicit matcher:
|
|
132
138
|
|
|
133
|
-
|
|
134
|
-
|
|
139
|
+
```ruby
|
|
140
|
+
class Footastic
|
|
141
|
+
include Cinch::Plugin
|
|
135
142
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
match "footastic"
|
|
144
|
+
def execute(m)
|
|
145
|
+
# ...
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
```
|
|
141
149
|
|
|
142
|
-
|
|
150
|
+
#### No more default `#execute` and `#listen` methods
|
|
143
151
|
|
|
144
152
|
Plugins do not come with default `#execute` and `#listen` methods
|
|
145
153
|
anymore, which means that specifying a matcher or listener without
|
|
146
154
|
providing the required methods will always result in an exception.
|
|
147
155
|
|
|
148
|
-
|
|
156
|
+
#### Programmatically registering plugins
|
|
149
157
|
|
|
150
158
|
If you're using the API to register plugins on your own, you will have
|
|
151
|
-
to use the new
|
|
159
|
+
to use the new [`Cinch::PluginList`](../lib/cinch/plugin_list.rb) class and its methods, instead of
|
|
152
160
|
using `Cinch::Bot#register_plugin` or `Cinch::Bot#register_plugins`,
|
|
153
161
|
which have been removed.
|
|
154
162
|
|
|
155
|
-
The PluginList instance is available via
|
|
163
|
+
The PluginList instance is available via [`Cinch::Bot#plugins`](../lib/cinch/bot.rb).
|
|
156
164
|
|
|
157
|
-
|
|
165
|
+
### Logging
|
|
158
166
|
|
|
159
167
|
Logging in Cinch 2.x has been greatly improved. Instead of only
|
|
160
168
|
supporting one logger and having all logging-relevant methods in
|
|
161
|
-
|
|
169
|
+
[`Cinch::Bot`](../lib/cinch/bot.rb), we've introduced the [`Cinch::LoggerList`](../lib/cinch/logger_list.rb) class, which
|
|
162
170
|
manages an infinite number of loggers. Included with Cinch are the
|
|
163
|
-
|
|
164
|
-
1.x, and a new
|
|
171
|
+
[formatted logger](../lib/cinch/logger/formatted_logger.rb), known from Cinch
|
|
172
|
+
1.x, and a new [Zcbot logger](../lib/cinch/logger/zcbot_logger.rb), a logger
|
|
165
173
|
emulating the log output of Zcbot, a format which can be parsed by
|
|
166
|
-
|
|
174
|
+
[pisg](https://pisg.sourceforge.net/).
|
|
167
175
|
|
|
168
|
-
|
|
176
|
+
#### Log levels
|
|
169
177
|
|
|
170
178
|
The old `@config.verbose` option has been replaced with a finely
|
|
171
|
-
tunable log level system. Each logger has
|
|
172
|
-
level}, but it is also possible to {Cinch::LoggerList#level= set the
|
|
173
|
-
level for all loggers at once}.
|
|
179
|
+
tunable log level system. Each logger has [its own level](../lib/cinch/logger.rb), but it is also possible to [set the level for all loggers at once](../lib/cinch/logger_list.rb).
|
|
174
180
|
|
|
175
181
|
The available levels, in ascending order of verbosity, are:
|
|
176
182
|
|
|
@@ -181,20 +187,20 @@ The available levels, in ascending order of verbosity, are:
|
|
|
181
187
|
- log
|
|
182
188
|
- debug
|
|
183
189
|
|
|
184
|
-
|
|
190
|
+
#### Methods
|
|
185
191
|
|
|
186
192
|
All logging related methods (`Cinch::Bot#debug` et al) have been
|
|
187
193
|
removed from the Bot class and instead moved to the loggers and the
|
|
188
|
-
|
|
189
|
-
plugins or handlers, you should use
|
|
190
|
-
|
|
194
|
+
[LoggerList](../lib/cinch/logger_list.rb). If you want to log messages from your
|
|
195
|
+
plugins or handlers, you should use [`Cinch::Bot#loggers`](../lib/cinch/bot.rb) to access the
|
|
196
|
+
[LoggerList](../lib/cinch/logger_list.rb) and then call the right methods on
|
|
191
197
|
that. Alterntively you can also use the logging-related helper methods
|
|
192
|
-
provided by
|
|
198
|
+
provided by [`Cinch::Helpers`](../lib/cinch/helpers.rb).
|
|
193
199
|
|
|
194
200
|
For more information on the logging architecture as well as examples
|
|
195
|
-
on how to use it, check the
|
|
201
|
+
on how to use it, check the [Logging readme](logging.md).
|
|
196
202
|
|
|
197
|
-
|
|
203
|
+
### Prefix/suffix + string semantics
|
|
198
204
|
|
|
199
205
|
Behaviour of string prefixes and suffixes has been adapted to match
|
|
200
206
|
that of matchers.
|
|
@@ -202,66 +208,74 @@ that of matchers.
|
|
|
202
208
|
That means that if the prefix or suffix are strings, the ^ or $ anchor
|
|
203
209
|
will be prepended/appened.
|
|
204
210
|
|
|
205
|
-
|
|
211
|
+
### Hooks and their return value
|
|
206
212
|
|
|
207
213
|
Hooks now behave as filters. If a hook returns `false`, the message
|
|
208
214
|
will not further be processed in a particular plugin.
|
|
209
215
|
|
|
210
|
-
|
|
216
|
+
### Constants
|
|
211
217
|
|
|
212
218
|
All constants for numeric replies (e.g. `RPL_INFO`) have been moved from
|
|
213
|
-
|
|
214
|
-
|
|
219
|
+
[`Cinch`](../lib/cinch/ban.rb) to [`Cinch::Constants`](../lib/cinch/constants.rb). Thus `Cinch::RPL_INFO` becomes
|
|
220
|
+
[`Cinch::Constants::RPL_INFO`](../lib/cinch/constants.rb), same for all other numeric constants.
|
|
215
221
|
|
|
216
|
-
|
|
222
|
+
### Bot configuration
|
|
217
223
|
|
|
218
|
-
Bot configuration now uses
|
|
224
|
+
Bot configuration now uses [special classes](../lib/cinch/configuration.rb)
|
|
219
225
|
instead of OpenStructs. Thus, assignments like
|
|
220
226
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
227
|
+
```ruby
|
|
228
|
+
configure do |c|
|
|
229
|
+
c.timeouts = OpenStruct.new({:read => 240, :connect => 10})
|
|
230
|
+
end
|
|
231
|
+
```
|
|
224
232
|
|
|
225
233
|
are not possible anymore and have to be written as either
|
|
226
234
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
235
|
+
```ruby
|
|
236
|
+
configure do |c|
|
|
237
|
+
c.timeouts.read = 240
|
|
238
|
+
c.timeouts.connect = 10
|
|
239
|
+
end
|
|
240
|
+
```
|
|
231
241
|
|
|
232
242
|
or
|
|
233
243
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
244
|
+
```ruby
|
|
245
|
+
configure do |c|
|
|
246
|
+
c.timeouts.load({:read => 240, :connect => 10})
|
|
247
|
+
end
|
|
248
|
+
```
|
|
237
249
|
|
|
238
250
|
The second version is especially interesting to tools like
|
|
239
|
-
|
|
251
|
+
[Cinchize](https://github.com/netfeed/cinchize), which load the
|
|
240
252
|
configuration from a YAML file. For more information see
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
## Various removed methods
|
|
253
|
+
[Bot options](bot_options.md).
|
|
245
254
|
|
|
246
|
-
|
|
255
|
+
### Various removed methods
|
|
247
256
|
|
|
257
|
+
See [What's changed](changes.md#removedrenamed-methods)
|
|
248
258
|
|
|
249
|
-
|
|
259
|
+
### `on`-handlers now only accepts one pattern
|
|
250
260
|
|
|
251
|
-
In previous versions,
|
|
261
|
+
In previous versions, [`Cinch::Bot#on`](../lib/cinch/bot.rb) accepted a variable amount of patterns
|
|
252
262
|
to match against. This feature was rarely used and has hence been
|
|
253
263
|
removed. If you've been using constructs like
|
|
254
264
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
265
|
+
```ruby
|
|
266
|
+
on :message, [/this/, /that/] do |m|
|
|
267
|
+
# ...
|
|
268
|
+
end
|
|
269
|
+
```
|
|
258
270
|
|
|
259
271
|
you will have to rewrite them as follows:
|
|
260
272
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
273
|
+
```ruby
|
|
274
|
+
b = lambda { |m|
|
|
275
|
+
# ...
|
|
276
|
+
}
|
|
264
277
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
278
|
+
[/this/, /that/].each do |pattern|
|
|
279
|
+
on :message, pattern, &b
|
|
280
|
+
end
|
|
281
|
+
```
|
data/docs/plugins.md
CHANGED
|
@@ -1,4 +1,110 @@
|
|
|
1
|
-
#
|
|
2
|
-
# @markup kramdown
|
|
1
|
+
# Plugins
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
A plugin is a Ruby class that includes `Cinch::Plugin`. IRCinch creates an
|
|
4
|
+
instance for each bot that registers the plugin. Add the class to
|
|
5
|
+
[`c.plugins.plugins`](bot_options.md#pluginsplugins) before `bot.start`.
|
|
6
|
+
See the [complete Hello, World bot](getting_started.md#on-handlers-vs-plugins).
|
|
7
|
+
|
|
8
|
+
## Matching messages
|
|
9
|
+
|
|
10
|
+
`match` reacts to `:message` by default and calls `execute(message, *captures)`.
|
|
11
|
+
Pass `method:` to select a different method and `react_on:` to select a
|
|
12
|
+
specific [event](events.md). A string matches the entire message after
|
|
13
|
+
including the prefix and suffix. A regular expression keeps its own anchors,
|
|
14
|
+
with the prefix and suffix applied around it.
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
class Echo
|
|
18
|
+
include Cinch::Plugin
|
|
19
|
+
|
|
20
|
+
match /\Aecho (.+)\z/, use_prefix: false, method: :echo
|
|
21
|
+
|
|
22
|
+
def echo(message, text)
|
|
23
|
+
message.safe_reply(text)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Plugin matchers inherit the bot prefix (`/^!/` by default) and suffix
|
|
29
|
+
(`nil` by default). Override either with `set :prefix, ...` or
|
|
30
|
+
`set :suffix, ...`, or pass `prefix:` and `suffix:` on an individual
|
|
31
|
+
matcher. Set `use_prefix: false` or `use_suffix: false` to omit either.
|
|
32
|
+
A `Proc` used as a pattern, prefix, or suffix receives the message and
|
|
33
|
+
returns the value to match. `strip_colors: true` requests matching against
|
|
34
|
+
text with IRC formatting removed. A `group:` limits a match group to
|
|
35
|
+
its first matching handler for a dispatch.
|
|
36
|
+
|
|
37
|
+
## Listening to events
|
|
38
|
+
|
|
39
|
+
Use `listen_to` to react to events without filtering by text. It accepts one
|
|
40
|
+
or more event names and calls `listen` unless `method:` selects another method.
|
|
41
|
+
Arguments depend on the [event](events.md).
|
|
42
|
+
|
|
43
|
+
```ruby
|
|
44
|
+
listen_to :join, :part, method: :track_membership
|
|
45
|
+
|
|
46
|
+
def track_membership(message)
|
|
47
|
+
info "#{message.command}: #{message.user} in #{message.channel}"
|
|
48
|
+
end
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
For CTCP commands, `ctcp "VERSION"` registers `ctcp_version(message)`.
|
|
52
|
+
Use `message.ctcp_reply(text)` to send a reply.
|
|
53
|
+
|
|
54
|
+
## Configuration
|
|
55
|
+
|
|
56
|
+
Set options on the bot and read them through the plugin instance's `config`
|
|
57
|
+
hash. `required_options` lists keys that must be present before the plugin's
|
|
58
|
+
handlers are registered. Validate the values separately if needed.
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
class Greeting
|
|
62
|
+
include Cinch::Plugin
|
|
63
|
+
|
|
64
|
+
set :required_options, [:text]
|
|
65
|
+
match "hello"
|
|
66
|
+
|
|
67
|
+
def execute(message)
|
|
68
|
+
message.reply(config.fetch(:text))
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
bot = Cinch::Bot.new do
|
|
73
|
+
configure do |c|
|
|
74
|
+
c.plugins.plugins = [Greeting]
|
|
75
|
+
c.plugins.options[Greeting] = {text: "Hello!"}
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
If the plugin defines `initialize(bot)`, call `super` to register its
|
|
81
|
+
handlers. See [common mistakes](common_mistakes.md).
|
|
82
|
+
|
|
83
|
+
Use `set :help, "Description of the command"` to add a help response.
|
|
84
|
+
With the default prefix, a plugin called `Greeting` responds to `!help greeting`.
|
|
85
|
+
|
|
86
|
+
## Hooks and timers
|
|
87
|
+
|
|
88
|
+
Use `hook :pre` or `hook :post` to run a method before or after a handler
|
|
89
|
+
in its thread. `method:` names the hook method. `for:` limits it to
|
|
90
|
+
`:match`, `:listen_to`, or `:ctcp`, and `group:` limits it to a matcher
|
|
91
|
+
group. The hook receives the message. Returning `false` from a pre-hook
|
|
92
|
+
skips that handler. Returning `false` from a post-hook stops later post-hooks.
|
|
93
|
+
|
|
94
|
+
Declare a repeating task with `timer 30, method: :tick`. The method takes
|
|
95
|
+
no arguments. The timer starts on `:connect` and stops on `:disconnect` by
|
|
96
|
+
default. Use `shots:` to limit the number of invocations. `threaded: false`
|
|
97
|
+
runs each invocation on the timer thread before waiting for the next interval.
|
|
98
|
+
|
|
99
|
+
For a timer started from a handler, call `Timer(5, shots: 1, start_automatically: false) { ... }`.
|
|
100
|
+
The helper starts it immediately and returns a timer object you can stop.
|
|
101
|
+
|
|
102
|
+
## Shared state
|
|
103
|
+
|
|
104
|
+
Separate invocations of a plugin handler can run concurrently on the same
|
|
105
|
+
plugin instance. Use `synchronize(:name) { ... }` when reading and writing
|
|
106
|
+
state that handlers share. Plugins attached to the same bot can also use
|
|
107
|
+
[`shared`](bot_options.md#shared) and a common synchronization name.
|
|
108
|
+
|
|
109
|
+
See the [`Cinch::Plugin` API source](../lib/cinch/plugin.rb) and
|
|
110
|
+
[`Cinch::Timer` API source](../lib/cinch/timer.rb).
|
data/docs/readme.md
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
#
|
|
2
|
-
# @markup kramdown
|
|
1
|
+
# IRCinch Documentation
|
|
3
2
|
|
|
3
|
+
- [Getting Started](getting_started.md)
|
|
4
|
+
- [Plugins](plugins.md)
|
|
5
|
+
- [Bot Options](bot_options.md)
|
|
6
|
+
- [Events](events.md)
|
|
7
|
+
- [Common Tasks](common_tasks.md)
|
|
8
|
+
- [Common Mistakes](common_mistakes.md)
|
|
9
|
+
- [Encodings](encodings.md)
|
|
10
|
+
- [Logging](logging.md)
|
|
4
11
|
|
|
5
|
-
|
|
6
|
-
- {file:docs/migrating.md Migration guides}
|
|
12
|
+
## Messaging and Transfers
|
|
7
13
|
|
|
8
|
-
|
|
14
|
+
- [DCC File Transfers](common_tasks.md#dcc-file-transfers)
|
|
15
|
+
- [SASL Authentication](bot_options.md#sasl)
|
|
16
|
+
- [Formatting Messages](common_tasks.md#formatting-messages)
|
|
9
17
|
|
|
10
|
-
|
|
18
|
+
## Release History
|
|
11
19
|
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
- {Cinch::DCC DCC}
|
|
16
|
-
- {file:docs/encodings.md Encodings}
|
|
17
|
-
- {file:docs/logging.md Logging}
|
|
18
|
-
- {Cinch::SASL SASL}
|
|
19
|
-
- {Cinch::Formatting Formatting messages}
|
|
20
|
-
- {file:docs/events.md Events}
|
|
20
|
+
- [IRCinch Changelog](../CHANGELOG.md)
|
|
21
|
+
- [Historical Cinch Changelog](changes.md)
|
|
22
|
+
- [Cinch Migration Guide](migrating.md)
|
data/examples/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# IRCinch Examples
|
|
2
|
+
|
|
3
|
+
The scripts in `basic/` use `bot.on` handlers. The scripts in `plugins/` register
|
|
4
|
+
classes that include `Cinch::Plugin`. Run one script at a time in a channel
|
|
5
|
+
where you have permission to test.
|
|
6
|
+
|
|
7
|
+
From the repository root, run `bundle install`, then start an example:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
IRC_SERVER=localhost IRC_CHANNEL='#my-test-channel' IRC_NICK=mybot \
|
|
11
|
+
bundle exec ruby -Ilib examples/basic/hello.rb
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Join the same channel with an IRC client and send `hello`. The plugin version
|
|
15
|
+
responds to `!hello`. Ctrl-C stops either bot. With the gem installed directly,
|
|
16
|
+
you can also run `ruby examples/basic/hello.rb` and use the installed gem.
|
|
17
|
+
|
|
18
|
+
The examples default to `localhost`, port `6667`, and `#ircinch-bots`.
|
|
19
|
+
Set `IRC_SERVER`, `IRC_PORT`, `IRC_CHANNEL`, and `IRC_NICK` for your test
|
|
20
|
+
server. Set `IRC_TLS=1` to enable TLS and certificate-chain verification,
|
|
21
|
+
with port `6697` as the default. See [TLS behavior](../docs/bot_options.md#sslverify).
|
|
22
|
+
|
|
23
|
+
## Commands and Events
|
|
24
|
+
|
|
25
|
+
- [Hello (basic)](basic/hello.rb) and [plugin](plugins/hello.rb). Send `hello`
|
|
26
|
+
to the basic bot or `!hello` to the plugin to get a greeting.
|
|
27
|
+
- [Autovoice (basic)](basic/autovoice.rb) and [plugin](plugins/autovoice.rb).
|
|
28
|
+
Give the bot operator mode (`+o`), send `!autovoice on` as a channel
|
|
29
|
+
operator, then have another user join. `!autovoice off` disables it in
|
|
30
|
+
that channel.
|
|
31
|
+
- [Google (basic)](basic/google.rb) and [plugin](plugins/google.rb).
|
|
32
|
+
Send `!google ruby irc` to get a search link.
|
|
33
|
+
- [Join and part (basic)](basic/join_part.rb) and [plugin](plugins/join_part.rb).
|
|
34
|
+
Send `!join #another-channel`, then `!part #another-channel`. In a channel,
|
|
35
|
+
`!part` uses that channel.
|
|
36
|
+
- [Memo](basic/memo.rb). Send `!memo alice Hello`, then have Alice send a
|
|
37
|
+
message the bot can see. The bot delivers the memo by private message.
|
|
38
|
+
- [Message relay (basic)](basic/msg.rb) and [plugin](plugins/msg.rb).
|
|
39
|
+
Send `!msg alice Hello` to have the bot send Alice a private message.
|
|
40
|
+
- [Seen (basic)](basic/seen.rb) and [plugin](plugins/seen.rb). Have Alice say
|
|
41
|
+
something in the channel, then send `!seen alice` to recall her latest
|
|
42
|
+
public message in that channel.
|
|
43
|
+
- [Urban Dictionary](basic/urban_dict.rb). Send `!urban example` to get a
|
|
44
|
+
definition link.
|
|
45
|
+
- [URL shortener (basic)](basic/url_shorten.rb) and [plugin](plugins/url_shorten.rb).
|
|
46
|
+
Send `!shorten https://example.com` to get a TinyURL link.
|
|
47
|
+
- [Custom prefix](plugins/custom_prefix.rb). Send `~somecommand` to try a
|
|
48
|
+
plugin-specific command prefix.
|
|
49
|
+
- [Dice roll](plugins/dice_roll.rb). Send `!roll 2d6+1` to roll two six-sided
|
|
50
|
+
dice and add one to each die. `!roll 2#3d6` rolls six dice and totals them.
|
|
51
|
+
A command can roll up to 100 dice with at most 10,000 sides each.
|
|
52
|
+
- [Hooks](plugins/hooks.rb). Send `!rand` to run pre- and post-hooks around
|
|
53
|
+
the command handler in the same thread.
|
|
54
|
+
- [Dynamic prefix](plugins/lambdas.rb). Send `mybot: hello`, using the bot's
|
|
55
|
+
current nickname. An authorized sender can send `mybot: rename` to append
|
|
56
|
+
`_` to the bot's nick.
|
|
57
|
+
- [Last nick](plugins/last_nick.rb). Change nick while sharing the bot's
|
|
58
|
+
channel to get a private message with your previous nick.
|
|
59
|
+
- [Multiple matches](plugins/multiple_matches.rb). Send `!command1 one`,
|
|
60
|
+
`!command2 two`, or `command3 three` to route to different methods.
|
|
61
|
+
- [Custom events](plugins/own_events.rb). Wait for a periodic random number
|
|
62
|
+
after the bot joins. One plugin publishes the event and the other replies.
|
|
63
|
+
- [Timer](plugins/timer.rb). Wait for the message the bot sends every five
|
|
64
|
+
seconds after joining.
|
|
65
|
+
|
|
66
|
+
## Extra Setup
|
|
67
|
+
|
|
68
|
+
- **Join, part, relay, and rename.** Set `IRC_ADMIN_PREFIX` to your exact
|
|
69
|
+
IRC sender prefix, with no leading colon, such as `alice!ident@trusted.example`.
|
|
70
|
+
The examples compare against the prefix supplied by the server. Use a test
|
|
71
|
+
network where that prefix identifies only your client. An unset value disables
|
|
72
|
+
those commands.
|
|
73
|
+
- **URL shortener.** Set `TINYURL_TOKEN` to a TinyURL API token with permission
|
|
74
|
+
to create links. Each `!shorten` request sends the URL to TinyURL and uses the
|
|
75
|
+
token's quota. [TinyURL API token setup](https://tinyurl.com/blog/how-create-modify-api-token/)
|
|
76
|
+
- **Memo and seen.** State stays in memory until the bot exits. Memos are
|
|
77
|
+
addressed to nicknames, which IRC users can change or reuse. Use non-sensitive
|
|
78
|
+
sample text.
|
data/examples/basic/autovoice.rb
CHANGED
|
@@ -1,31 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
|
|
7
|
-
# Disable with !autovoice off
|
|
8
|
-
#
|
|
9
|
-
# It starts out disabled.
|
|
3
|
+
require_relative "../settings"
|
|
4
|
+
|
|
5
|
+
# Give the bot +o in the channel. A channel operator can toggle autovoice.
|
|
6
|
+
enabled_channels = {}
|
|
10
7
|
|
|
11
8
|
bot = Cinch::Bot.new do
|
|
12
9
|
configure do |c|
|
|
13
|
-
c
|
|
14
|
-
c.server = "irc.libera.chat"
|
|
15
|
-
c.verbose = true
|
|
16
|
-
c.channels = ["#ircinch-bots"]
|
|
10
|
+
ExampleSettings.configure(c, "irc_voice")
|
|
17
11
|
end
|
|
18
12
|
|
|
19
13
|
on :join do |m|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
channel = m.channel
|
|
15
|
+
enabled = synchronize(:autovoice) { enabled_channels[channel] }
|
|
16
|
+
channel.voice(m.user) if enabled && m.user != bot && channel.opped?(bot)
|
|
23
17
|
end
|
|
24
18
|
|
|
25
|
-
on :
|
|
26
|
-
|
|
19
|
+
on :message, /\A!autovoice (on|off)\z/ do |m, option|
|
|
20
|
+
next unless m.user && m.channel&.opped?(m.user)
|
|
27
21
|
|
|
28
|
-
|
|
22
|
+
enabled = option == "on"
|
|
23
|
+
synchronize(:autovoice) { enabled_channels[m.channel] = enabled }
|
|
24
|
+
m.reply "Autovoice is now #{enabled ? "enabled" : "disabled"}."
|
|
29
25
|
end
|
|
30
26
|
end
|
|
31
27
|
|