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/common_mistakes.md
CHANGED
|
@@ -1,60 +1,69 @@
|
|
|
1
|
-
#
|
|
2
|
-
# @markup kramdown
|
|
1
|
+
# Common Mistakes
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## I defined an initialize method in my plugin and now it doesn't work properly anymore
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
number of arguments (`*args`) and to call `super` as soon as possible.
|
|
5
|
+
IRCinch passes the bot to the plugin initializer. Call `super` with that
|
|
6
|
+
argument so `Cinch::Plugin` can initialize the instance and register its
|
|
7
|
+
handlers.
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
### Example
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
```ruby
|
|
12
|
+
class MyPlugin
|
|
13
|
+
include Cinch::Plugin
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
def initialize(bot)
|
|
16
|
+
super
|
|
17
|
+
@seen = {}
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
```
|
|
21
21
|
|
|
22
|
+
## I am trying to use plugin options, but Ruby says it cannot find the `config` method
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
`config` belongs to the plugin instance. Class-level declarations run before
|
|
25
|
+
the class is registered with a bot, so `match(config[:pattern])` raises.
|
|
26
|
+
Define a static matcher and check the configured value in the handler, as
|
|
27
|
+
shown in [plugin configuration](plugins.md#configuration).
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
## My handlers won't run, even though the regular expression matches
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
IRCinch plugins have a default prefix (`/^!/`). This allows for flexible prefixes
|
|
32
|
+
across the whole bot. The default prefix can be changed in `Bot#configure`:
|
|
28
33
|
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
```ruby
|
|
35
|
+
bot = Cinch::Bot.new do
|
|
36
|
+
configure do |c|
|
|
37
|
+
# ...
|
|
38
|
+
c.plugins.prefix = /^%/
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
```
|
|
31
42
|
|
|
32
|
-
|
|
33
|
-
def execute(m)
|
|
34
|
-
# ...
|
|
35
|
-
end
|
|
36
|
-
end
|
|
43
|
+
Alternatively, you can set the prefix for specific plugins only, by calling `set`:
|
|
37
44
|
|
|
38
|
-
|
|
45
|
+
```ruby
|
|
46
|
+
class MyPlugin
|
|
47
|
+
include Cinch::Plugin
|
|
39
48
|
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
set :prefix, /^%/
|
|
50
|
+
end
|
|
51
|
+
```
|
|
42
52
|
|
|
43
|
-
|
|
44
|
-
configure do |c|
|
|
45
|
-
# ...
|
|
46
|
-
c.plugins.prefix = /^%/
|
|
47
|
-
end
|
|
48
|
-
end
|
|
53
|
+
You can also choose to not use a prefix for specific matchers:
|
|
49
54
|
|
|
50
|
-
|
|
55
|
+
```ruby
|
|
56
|
+
match /hi/, use_prefix: false
|
|
57
|
+
```
|
|
51
58
|
|
|
52
|
-
|
|
53
|
-
include Cinch::Plugin
|
|
59
|
+
## My bot hasn't joined a channel when `:connect` runs
|
|
54
60
|
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
`:connect` signals IRC registration. The channel joins happen afterward.
|
|
62
|
+
Listen for `:join` and check `m.user == bot` before relying on membership.
|
|
63
|
+
See [`:connect`](events.md#connect) and [`delay_joins`](bot_options.md#delay_joins).
|
|
57
64
|
|
|
58
|
-
|
|
65
|
+
## Setting `c.default_logger_level` didn't change my log output
|
|
59
66
|
|
|
60
|
-
|
|
67
|
+
The default logger already exists when the configuration block runs. Set
|
|
68
|
+
`bot.loggers.first.level = :info` before `bot.start` to change its level.
|
|
69
|
+
See [Logging](logging.md#changing-the-level).
|
data/docs/common_tasks.md
CHANGED
|
@@ -1,57 +1,78 @@
|
|
|
1
|
-
#
|
|
2
|
-
# @markup kramdown
|
|
1
|
+
# Common Tasks
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Checking if a user is online
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
set to offline.
|
|
5
|
+
IRCinch tracks presence from messages it receives. That state can get stale
|
|
6
|
+
when the bot stops sharing channels with a user. Call
|
|
7
|
+
[`User(nick).monitor`](../lib/cinch/user.rb) to use the server's `MONITOR`
|
|
8
|
+
support or poll with `WHOIS` every 30 seconds. Call `unmonitor` to stop.
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
The `:online` and `:offline` handlers receive `nil` and then the user.
|
|
11
|
+
Set up monitoring once per connection, since server subscriptions are
|
|
12
|
+
connection-specific. This example guards against repeated `:connect`
|
|
13
|
+
events on the same connection.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
the user as online.
|
|
15
|
+
```ruby
|
|
16
|
+
class Presence
|
|
17
|
+
include Cinch::Plugin
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
that's not available, periodically runs _WHOIS_ to update the
|
|
24
|
-
information.
|
|
19
|
+
listen_to :connect, method: :on_connect
|
|
20
|
+
listen_to :online, method: :on_online
|
|
21
|
+
listen_to :offline, method: :on_offline
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
def on_connect(_message)
|
|
24
|
+
synchronize(:presence_monitor) do
|
|
25
|
+
return if @monitored_connection.equal?(bot.irc)
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
User("example_user").monitor
|
|
28
|
+
@monitored_connection = bot.irc
|
|
29
|
+
end
|
|
30
|
+
end
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
def on_online(_message, user)
|
|
33
|
+
info "#{user} is online"
|
|
34
|
+
end
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
def on_offline(_message, user)
|
|
37
|
+
info "#{user} is offline"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
```
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
user.send "Hello master"
|
|
43
|
-
end
|
|
42
|
+
## Sending messages to users and channels beside `m.user` and `m.channel`
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
Use the [`User`, `Channel`, and `Target` helpers](../lib/cinch/helpers.rb)
|
|
45
|
+
inside a plugin or `on` handler to look up another recipient.
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
User("example_user").send("Hello!")
|
|
49
|
+
Channel("#example").send("Hello, channel!")
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Use `m.reply` to answer the current conversation. If the message came from a
|
|
53
|
+
channel, `m.reply(text, true)` prefixes the sender's nickname. A reply to a
|
|
54
|
+
`STATUSMSG` uses the same channel audience. Use `safe_reply` or `safe_send`
|
|
55
|
+
for text from users or feeds to strip nonprinting characters.
|
|
56
|
+
|
|
57
|
+
## Formatting messages
|
|
49
58
|
|
|
50
|
-
|
|
59
|
+
Use `Format` with a style or color followed by the text. For example,
|
|
60
|
+
`m.reply(Format(:bold, "Ready"))` sends bold text to clients that support IRC
|
|
61
|
+
formatting. Use `Unformat(text)` to remove IRC formatting codes or
|
|
62
|
+
`Sanitize(text)` to remove nonprintable characters. See the
|
|
63
|
+
[formatting options](../lib/cinch/formatting.rb) and [helper methods](../lib/cinch/helpers.rb).
|
|
51
64
|
|
|
52
|
-
|
|
53
|
-
and User objects that you can work with:
|
|
65
|
+
## DCC file transfers
|
|
54
66
|
|
|
55
|
-
|
|
56
|
-
|
|
67
|
+
DCC sends the offer over IRC and transfers file data directly between clients.
|
|
68
|
+
Open an outgoing file in binary mode and pass it to
|
|
69
|
+
[`User(nick).dcc_send(io)`](../lib/cinch/user.rb) from a handler. The call blocks
|
|
70
|
+
while waiting for the recipient and transferring the data. The advertised
|
|
71
|
+
address can be configured with [`dcc.own_ip`](bot_options.md#dccown_ip).
|
|
57
72
|
|
|
73
|
+
For incoming offers, listen to [`:dcc_send`](events.md#dcc_send). The offer
|
|
74
|
+
exposes `user`, `filename`, `size`, `ip`, and `port`. Calling `accept(output)`
|
|
75
|
+
connects to the offered address and writes to an object that supports `<<`.
|
|
76
|
+
Review the sender and destination before accepting an offer. Choose the local
|
|
77
|
+
output path yourself and enforce your own transfer limits. See the
|
|
78
|
+
[incoming transfer API](../lib/cinch/dcc/incoming/send.rb).
|
data/docs/encodings.md
CHANGED
|
@@ -1,69 +1,42 @@
|
|
|
1
|
-
# @title Encodings
|
|
2
|
-
# @markup kramdown
|
|
3
|
-
|
|
4
1
|
# Encodings
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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.
|
|
3
|
+
IRC messages carry bytes without an encoding label. Configure
|
|
4
|
+
[`c.encoding`](bot_options.md#encoding) to control how IRCinch decodes
|
|
5
|
+
incoming bytes and encodes outgoing text.
|
|
17
6
|
|
|
18
7
|
## 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
8
|
|
|
9
|
+
Use an encoding name such as `"UTF-8"`, a Ruby `Encoding` object such as
|
|
10
|
+
`Encoding::UTF_8`, or the special value `:irc` (the default).
|
|
25
11
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
encoding
|
|
29
|
-
|
|
30
|
-
|
|
12
|
+
```ruby
|
|
13
|
+
bot.configure do |c|
|
|
14
|
+
c.encoding = Encoding::UTF_8
|
|
15
|
+
end
|
|
16
|
+
```
|
|
31
17
|
|
|
32
|
-
|
|
33
|
-
|
|
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.
|
|
18
|
+
An explicit encoding applies in both directions. For example, use `"Windows-1252"`
|
|
19
|
+
for a network that expects that encoding on the wire.
|
|
36
20
|
|
|
37
|
-
|
|
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.
|
|
21
|
+
## Encoding.default_internal
|
|
43
22
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
`Encoding.default_internal` in this case and always present you with
|
|
49
|
-
UTF-8.
|
|
23
|
+
For explicit encodings, IRCinch passes incoming strings through Ruby's
|
|
24
|
+
`String#encode!`, which converts to `Encoding.default_internal` when it is
|
|
25
|
+
set. This Ruby setting is process-wide. `:irc` always returns incoming text
|
|
26
|
+
as UTF-8, regardless of `Encoding.default_internal`.
|
|
50
27
|
|
|
51
|
-
|
|
52
|
-
CP1252 code page, the entire line will be sent that way.
|
|
28
|
+
## The `:irc` encoding
|
|
53
29
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
correctly.
|
|
30
|
+
- **Incoming** Keep valid UTF-8. If the byte sequence is invalid UTF-8,
|
|
31
|
+
decode the whole line as Windows-1252 (CP1252) and convert it to UTF-8.
|
|
32
|
+
- **Outgoing** Encode as UTF-8, including text that could fit in CP1252.
|
|
58
33
|
|
|
59
34
|
## 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
35
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
36
|
+
IRCinch asks Ruby to replace invalid bytes or characters that cannot be
|
|
37
|
+
converted when it transcodes. The replacement depends on the destination
|
|
38
|
+
encoding. For an explicit incoming encoding, IRCinch discards characters
|
|
39
|
+
that are still invalid after the conversion step.
|
|
40
|
+
|
|
41
|
+
See the [encoding implementation](../lib/cinch/utilities/encoding.rb) and
|
|
42
|
+
[encoding tests](../test/lib/cinch/utilities/encoding.rb).
|