cinch 2.0.0.pre.7 → 2.0.0
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.
- data/README.md +1 -1
- data/docs/bot_options.md +6 -8
- data/docs/changes.md +39 -40
- data/docs/encodings.md +2 -2
- data/docs/events.md +7 -7
- data/docs/getting_started.md +184 -0
- data/docs/logging.md +50 -1
- data/docs/migrating.md +3 -4
- data/docs/plugins.md +4 -0
- data/lib/cinch/bot.rb +6 -7
- data/lib/cinch/channel.rb +12 -0
- data/lib/cinch/configuration/bot.rb +3 -2
- data/lib/cinch/dcc/outgoing/send.rb +1 -1
- data/lib/cinch/helpers.rb +8 -1
- data/lib/cinch/plugin.rb +19 -14
- data/lib/cinch/storage.rb +2 -1
- data/lib/cinch/target.rb +8 -0
- data/lib/cinch/version.rb +1 -1
- metadata +7 -5
data/README.md
CHANGED
data/docs/bot_options.md
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
# @markup kramdown
|
3
3
|
|
4
4
|
# Options
|
5
|
-
Note: This page describes options of Cinch. It does not describe how
|
6
|
-
to set options specific to plugins.
|
7
5
|
|
8
6
|
## channels
|
9
7
|
Type
|
@@ -59,7 +57,7 @@ Description
|
|
59
57
|
|
60
58
|
|
61
59
|
### Notes
|
62
|
-
- {file:encodings.md More information on how Cinch handles encoding issues}
|
60
|
+
- {file:docs/encodings.md More information on how Cinch handles encoding issues}
|
63
61
|
|
64
62
|
## local_host
|
65
63
|
Type
|
@@ -114,7 +112,7 @@ Description
|
|
114
112
|
### Notes
|
115
113
|
- If your bot gets kicked for excess flood, try lowering the value of
|
116
114
|
`messages_per_second`.
|
117
|
-
- See also: {file:bot_options.md#serverqueuesize `server_queue_size`}
|
115
|
+
- See also: {file:docs/bot_options.md#serverqueuesize `server_queue_size`}
|
118
116
|
|
119
117
|
## message_split_end
|
120
118
|
Type
|
@@ -175,7 +173,7 @@ Default value
|
|
175
173
|
: `nil`
|
176
174
|
|
177
175
|
Description
|
178
|
-
: This option overrules {file:bot_options.md#nick `nick`} and allows Cinch
|
176
|
+
: This option overrules {file:docs/bot_options.md#nick `nick`} and allows Cinch
|
179
177
|
to try multiple nicks before adding underscores.
|
180
178
|
|
181
179
|
|
@@ -209,7 +207,7 @@ Description
|
|
209
207
|
|
210
208
|
### Notes
|
211
209
|
- The ping interval should be smaller than
|
212
|
-
{file:bot_options.md#timeoutsread `timeouts.read`} to prevent Cinch from
|
210
|
+
{file:docs/bot_options.md#timeoutsread `timeouts.read`} to prevent Cinch from
|
213
211
|
falsely declaring a connection dead.
|
214
212
|
|
215
213
|
|
@@ -348,7 +346,7 @@ Description
|
|
348
346
|
### Notes
|
349
347
|
- If your bot gets kicked for excess flood, try lowering the value of
|
350
348
|
`server_queue_size`.
|
351
|
-
- See also: {file:bot_options.md#messagespersecond `messages_per_second`}
|
349
|
+
- See also: {file:docs/bot_options.md#messagespersecond `messages_per_second`}
|
352
350
|
|
353
351
|
## ssl
|
354
352
|
|
@@ -382,7 +380,7 @@ Default value
|
|
382
380
|
|
383
381
|
Description
|
384
382
|
: The path to a directory with certificates. This has to be set
|
385
|
-
properly for {file:bot_options.md#sslverify `ssl.verify`} to work.
|
383
|
+
properly for {file:docs/bot_options.md#sslverify `ssl.verify`} to work.
|
386
384
|
|
387
385
|
|
388
386
|
### ssl.client_cert
|
data/docs/changes.md
CHANGED
@@ -94,7 +94,7 @@ needs to be aware of available features/quirks, check out
|
|
94
94
|
## Reworked logging facilities
|
95
95
|
|
96
96
|
The logging API has been drastically improved. Check the
|
97
|
-
{file:logging.md logging documentation} for more information.
|
97
|
+
{file:docs/logging.md logging documentation} for more information.
|
98
98
|
|
99
99
|
|
100
100
|
## Added match groups
|
@@ -225,7 +225,6 @@ moved from {Cinch} to {Cinch::Constants}
|
|
225
225
|
#### {Cinch::Plugin}
|
226
226
|
|
227
227
|
- {Cinch::Plugin#handlers}
|
228
|
-
- {Cinch::Plugin#storage}
|
229
228
|
- {Cinch::Plugin#timers}
|
230
229
|
- {Cinch::Plugin#unregister}
|
231
230
|
|
@@ -234,7 +233,7 @@ moved from {Cinch} to {Cinch::Constants}
|
|
234
233
|
- {Cinch::User#away}
|
235
234
|
- {Cinch::User#dcc_send} - See {Cinch::DCC::Outgoing::Send}
|
236
235
|
- {Cinch::User#match}
|
237
|
-
- {Cinch::User#monitor} - See {file:common_tasks.md#checking-if-a-user-is-online Checking if a user is online}
|
236
|
+
- {Cinch::User#monitor} - See {file:docs/common_tasks.md#checking-if-a-user-is-online Checking if a user is online}
|
238
237
|
- {Cinch::User#monitored}
|
239
238
|
- {Cinch::User#online?}
|
240
239
|
- {Cinch::User#unmonitor}
|
@@ -297,7 +296,7 @@ instead are made available via {Cinch::Plugin::ClassMethods#set a
|
|
297
296
|
`set` method} or alternatively plain attribute setters.
|
298
297
|
|
299
298
|
See
|
300
|
-
{file:migrating.md#plugin-options the migration guide} for more
|
299
|
+
{file:docs/migrating.md#plugin-options the migration guide} for more
|
301
300
|
information.
|
302
301
|
|
303
302
|
### Channel/Target/User implement Comparable
|
@@ -342,24 +341,24 @@ For more information on timers, see the {Cinch::Timer Timer documentation}.
|
|
342
341
|
|
343
342
|
## New options
|
344
343
|
|
345
|
-
- :{file:bot_options.md#dccownip dcc.own_ip}
|
346
|
-
- :{file:bot_options.md#modes modes}
|
347
|
-
- :{file:bot_options.md#maxreconnectdelay max_reconnect_delay}
|
348
|
-
- :{file:bot_options.md#localhost local_host}
|
349
|
-
- :{file:bot_options.md#delayjoins delay_joins}
|
350
|
-
- :{file:bot_options.md#saslusername sasl.username}
|
351
|
-
- :{file:bot_options.md#saslpassword sasl.password}
|
344
|
+
- :{file:docs/bot_options.md#dccownip dcc.own_ip}
|
345
|
+
- :{file:docs/bot_options.md#modes modes}
|
346
|
+
- :{file:docs/bot_options.md#maxreconnectdelay max_reconnect_delay}
|
347
|
+
- :{file:docs/bot_options.md#localhost local_host}
|
348
|
+
- :{file:docs/bot_options.md#delayjoins delay_joins}
|
349
|
+
- :{file:docs/bot_options.md#saslusername sasl.username}
|
350
|
+
- :{file:docs/bot_options.md#saslpassword sasl.password}
|
352
351
|
|
353
352
|
## New events
|
354
|
-
- :{file:events.md#action action}
|
355
|
-
- :{file:events.md#away away}
|
356
|
-
- :{file:events.md#unaway unaway}
|
357
|
-
- :{file:events.md#dccsend dcc_send}
|
358
|
-
- :{file:events.md#owner owner}
|
359
|
-
- :{file:events.md#dehalfop-deop-deowner-devoice deowner}
|
360
|
-
- :{file:events.md#leaving leaving}
|
361
|
-
- :{file:events.md#online online}
|
362
|
-
- :{file:events.md#offline offline}
|
353
|
+
- :{file:docs/events.md#action action}
|
354
|
+
- :{file:docs/events.md#away away}
|
355
|
+
- :{file:docs/events.md#unaway unaway}
|
356
|
+
- :{file:docs/events.md#dccsend dcc_send}
|
357
|
+
- :{file:docs/events.md#owner owner}
|
358
|
+
- :{file:docs/events.md#dehalfop-deop-deowner-devoice deowner}
|
359
|
+
- :{file:docs/events.md#leaving leaving}
|
360
|
+
- :{file:docs/events.md#online online}
|
361
|
+
- :{file:docs/events.md#offline offline}
|
363
362
|
|
364
363
|
|
365
364
|
# What has changed in 1.1?
|
@@ -371,16 +370,16 @@ x. **Deprecated methods**
|
|
371
370
|
|
372
371
|
## New events
|
373
372
|
|
374
|
-
- :{file:events.md#op op}
|
375
|
-
- :{file:events.md#dehalfop-deop-deowner-devoice deop}
|
376
|
-
- :{file:events.md#voice voice}
|
377
|
-
- :{file:events.md#dehalfop-deop-deowner-devoice devoice}
|
378
|
-
- :{file:events.md#halfop halfop}
|
379
|
-
- :{file:events.md#dehalfop-deop-deowner-devoice dehalfop}
|
380
|
-
- :{file:events.md#ban ban}
|
381
|
-
- :{file:events.md#unban unban}
|
382
|
-
- :{file:events.md#modechange mode_change}
|
383
|
-
- :{file:events.md#catchall catchall}
|
373
|
+
- :{file:docs/events.md#op op}
|
374
|
+
- :{file:docs/events.md#dehalfop-deop-deowner-devoice deop}
|
375
|
+
- :{file:docs/events.md#voice voice}
|
376
|
+
- :{file:docs/events.md#dehalfop-deop-deowner-devoice devoice}
|
377
|
+
- :{file:docs/events.md#halfop halfop}
|
378
|
+
- :{file:docs/events.md#dehalfop-deop-deowner-devoice dehalfop}
|
379
|
+
- :{file:docs/events.md#ban ban}
|
380
|
+
- :{file:docs/events.md#unban unban}
|
381
|
+
- :{file:docs/events.md#modechange mode_change}
|
382
|
+
- :{file:docs/events.md#catchall catchall}
|
384
383
|
|
385
384
|
Additionally, plugins are now able to send their own events by using
|
386
385
|
Cinch::Bot#dispatch.
|
@@ -401,16 +400,16 @@ Provides a nicer representation of {Cinch::Message} objects.
|
|
401
400
|
Provides an easier way of checking if a given user is in a channel
|
402
401
|
|
403
402
|
## New options
|
404
|
-
- {file:bot_options.md#pluginssuffix plugins.suffix}
|
405
|
-
- {file:bot_options.md#ssluse ssl.use}
|
406
|
-
- {file:bot_options.md#sslverify ssl.verify}
|
407
|
-
- {file:bot_options.md#sslcapath ssl.ca_path}
|
408
|
-
- {file:bot_options.md#sslclientcert ssl.client_cert}
|
409
|
-
- {file:bot_options.md#nicks nicks}
|
410
|
-
- {file:bot_options.md#timeoutsread timeouts.read}
|
411
|
-
- {file:bot_options.md#timeoutsconnect timeouts.connect}
|
412
|
-
- {file:bot_options.md#pinginterval ping_interval}
|
413
|
-
- {file:bot_options.md#reconnect reconnect}
|
403
|
+
- {file:docs/bot_options.md#pluginssuffix plugins.suffix}
|
404
|
+
- {file:docs/bot_options.md#ssluse ssl.use}
|
405
|
+
- {file:docs/bot_options.md#sslverify ssl.verify}
|
406
|
+
- {file:docs/bot_options.md#sslcapath ssl.ca_path}
|
407
|
+
- {file:docs/bot_options.md#sslclientcert ssl.client_cert}
|
408
|
+
- {file:docs/bot_options.md#nicks nicks}
|
409
|
+
- {file:docs/bot_options.md#timeoutsread timeouts.read}
|
410
|
+
- {file:docs/bot_options.md#timeoutsconnect timeouts.connect}
|
411
|
+
- {file:docs/bot_options.md#pinginterval ping_interval}
|
412
|
+
- {file:docs/bot_options.md#reconnect reconnect}
|
414
413
|
|
415
414
|
|
416
415
|
|
data/docs/encodings.md
CHANGED
@@ -16,7 +16,7 @@ Cinch tries to work around this issue in two ways, while also keeping
|
|
16
16
|
the usual Ruby behaviour.
|
17
17
|
|
18
18
|
## The `encoding` option
|
19
|
-
By setting {file:bot_options.md#encoding the `encoding` option}, you
|
19
|
+
By setting {file:docs/bot_options.md#encoding the `encoding` option}, you
|
20
20
|
set your expectations on what encoding other users will use. Allowed
|
21
21
|
values are instances of Encoding, names of valid encodings (as
|
22
22
|
strings) and the special `:irc` encoding, which will be explained
|
@@ -26,7 +26,7 @@ further down.
|
|
26
26
|
## Encoding.default_internal
|
27
27
|
If set, Cinch will automatically convert incoming messages to the
|
28
28
|
encoding defined by `Encoding.default_internal`, unless the special
|
29
|
-
encoding `:irc` is being used as the {file:bot_options.md#encoding
|
29
|
+
encoding `:irc` is being used as the {file:docs/bot_options.md#encoding
|
30
30
|
`encoding option`}
|
31
31
|
|
32
32
|
## The `:irc` encoding
|
data/docs/events.md
CHANGED
@@ -72,7 +72,7 @@ Example:
|
|
72
72
|
debug("User %s just went away: %s" % [m.user, m.message])
|
73
73
|
end
|
74
74
|
|
75
|
-
See also {file:events.md#unaway the `:unaway` event}.
|
75
|
+
See also {file:docs/events.md#unaway the `:unaway` event}.
|
76
76
|
|
77
77
|
|
78
78
|
## `:ban`
|
@@ -88,7 +88,7 @@ Example:
|
|
88
88
|
debug("%s just banned %s" % [ban.by, ban.mask])
|
89
89
|
end
|
90
90
|
|
91
|
-
See also {file:events.md#unban the `:unban` event}.
|
91
|
+
See also {file:docs/events.md#unban the `:unban` event}.
|
92
92
|
|
93
93
|
|
94
94
|
## `:catchall`
|
@@ -102,7 +102,7 @@ IRC message/command, no matter what the type is.
|
|
102
102
|
The `:channel` event is triggered for channel messages (the usual
|
103
103
|
form of communication on IRC).
|
104
104
|
|
105
|
-
See also {file:events.md#private the `:private` event}.
|
105
|
+
See also {file:docs/events.md#private the `:private` event}.
|
106
106
|
|
107
107
|
|
108
108
|
## `:connect`
|
@@ -193,7 +193,7 @@ describing every change.
|
|
193
193
|
## `:offline`
|
194
194
|
|
195
195
|
This event is triggered when a
|
196
|
-
{file:common_tasks.md#checking-if-a-user-is-online monitored user}
|
196
|
+
{file:docs/common_tasks.md#checking-if-a-user-is-online monitored user}
|
197
197
|
goes offline.
|
198
198
|
|
199
199
|
One additional argument, the user going offline, gets passed to the
|
@@ -203,7 +203,7 @@ handler.
|
|
203
203
|
## `:online`
|
204
204
|
|
205
205
|
This event is triggered when a
|
206
|
-
{file:common_tasks.md#checking-if-a-user-is-online monitored user}
|
206
|
+
{file:docs/common_tasks.md#checking-if-a-user-is-online monitored user}
|
207
207
|
comes online.
|
208
208
|
|
209
209
|
One additional argument, the user coming online, gets passed to the
|
@@ -239,7 +239,7 @@ channel or directly at the bot. It's synonymous with `:privmsg`.
|
|
239
239
|
The `:private` event is triggered for messages directly towarded at
|
240
240
|
the bot (think /query in traditional IRC clients).
|
241
241
|
|
242
|
-
See also {file:events.md#channel the `:channel` event}.
|
242
|
+
See also {file:docs/events.md#channel the `:channel` event}.
|
243
243
|
|
244
244
|
|
245
245
|
## `:unaway`
|
@@ -254,7 +254,7 @@ Example:
|
|
254
254
|
debug("User %s no longer is away." % m.user)
|
255
255
|
end
|
256
256
|
|
257
|
-
See also {file:events.md#away the `:away` event}.
|
257
|
+
See also {file:docs/events.md#away the `:away` event}.
|
258
258
|
|
259
259
|
|
260
260
|
## `:unban`
|
@@ -0,0 +1,184 @@
|
|
1
|
+
# @title Getting Started
|
2
|
+
# @markup kramdown
|
3
|
+
|
4
|
+
# Getting Started
|
5
|
+
|
6
|
+
This short guide will show you how to easily and quickly write your
|
7
|
+
own IRC bot with Cinch.
|
8
|
+
|
9
|
+
# What Cinch really is
|
10
|
+
|
11
|
+
First and foremost, it is important to understand that Cinch is more
|
12
|
+
of an API for IRC access than a full-blown bot framework like Autumn
|
13
|
+
or Rbot.
|
14
|
+
|
15
|
+
There will be no enforced directory structures, no magical places from
|
16
|
+
which plugins will be loaded and no obscure, "fancy" names. Plugins
|
17
|
+
will be plugins and not "leaves".
|
18
|
+
|
19
|
+
This, however, does not mean that Cinch requires you to be familiar
|
20
|
+
with the internals of the IRC protocol. Quite the opposite: A very
|
21
|
+
high-level abstraction is provided, allowing things such as
|
22
|
+
|
23
|
+
Channel("#cinch").users.each do |user, modes|
|
24
|
+
user.send "I am watching you!"
|
25
|
+
end
|
26
|
+
|
27
|
+
to work.
|
28
|
+
|
29
|
+
|
30
|
+
Furthermore, the API has been designed in a way that it sticks true to
|
31
|
+
the way Ruby looks and behaves. Plugins are normal classes that mix-in
|
32
|
+
a module, functions of the bot are implemented as normal methods and
|
33
|
+
so on.
|
34
|
+
|
35
|
+
# Hello, World
|
36
|
+
|
37
|
+
The following will describe one of the most basic IRC bots you can
|
38
|
+
write in Cinch: One that joins a specific channel and responds to
|
39
|
+
"hello" by saying "Hello, World".
|
40
|
+
|
41
|
+
|
42
|
+
require "cinch"
|
43
|
+
|
44
|
+
bot = Cinch::Bot.new do
|
45
|
+
configure do |c|
|
46
|
+
c.server = "irc.freenode.net"
|
47
|
+
c.channels = ["#cinch-bots"]
|
48
|
+
end
|
49
|
+
|
50
|
+
on :message, "hello" do |m|
|
51
|
+
m.reply "Hello, World"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
bot.start
|
56
|
+
|
57
|
+
|
58
|
+
Note that this is the entire file and all you need for the basic bot
|
59
|
+
to work. Save the above example to a file and run it with Ruby.
|
60
|
+
|
61
|
+
## In Detail
|
62
|
+
|
63
|
+
So, what are we actually doing in that short piece of code? First, we
|
64
|
+
create a new bot in line 3 and conigure it in lines 4–6 –
|
65
|
+
{Cinch::Bot#configure configure} simply yields the configuration
|
66
|
+
object, which allows you to configure various things. In this example,
|
67
|
+
we only set which server to connect to and which channel to join.
|
68
|
+
Another often-used option is the nickname of the bot
|
69
|
+
({file:docs/bot_options.md#nick c.nick}). For an overview of all
|
70
|
+
available options, see {file:docs/bot_options.md the list of options}.
|
71
|
+
|
72
|
+
Following, we define a basic message handler. In its simplest form,
|
73
|
+
{Cinch::Bot#on on} expects two arguments: The kind of message to react
|
74
|
+
to and the pattern to match. In this case, the kind is
|
75
|
+
{file:docs/events.md#message :message}, which means that the bot will
|
76
|
+
respond to both messages in channels as well as messages sent directly
|
77
|
+
to the bot. For a list of all kinds, called events, see
|
78
|
+
{file:docs/events.md the list of events}.
|
79
|
+
|
80
|
+
For the pattern we use a basic string, which means that the message
|
81
|
+
has to be exactly that string. It mustn't have anything before or
|
82
|
+
after the word "hello". Another way of using {Cinch::Bot#on on} is by using
|
83
|
+
regular expressions:
|
84
|
+
|
85
|
+
on :message, /^\d{4}$/ do |m|
|
86
|
+
# ...
|
87
|
+
end
|
88
|
+
|
89
|
+
will match all messages that consist of exactly four digits and
|
90
|
+
nothing else.
|
91
|
+
|
92
|
+
Whenever a message matches the handler we just defined, the block we
|
93
|
+
provided will be called, with the message object, and optionally
|
94
|
+
capture groups of the regular expression, passed to it.
|
95
|
+
|
96
|
+
The message object allows insight into the nature of the message, i.e.
|
97
|
+
who sent it, when was it sent etc, and also provides the
|
98
|
+
{Cinch::Message#reply reply} method, an easy way of responding to a
|
99
|
+
message. If the message was sent to a channel, {Cinch::Message#reply
|
100
|
+
reply} will respond to the channel, otherwise directly to the user.
|
101
|
+
|
102
|
+
We then use exactly that {Cinch::Message#reply reply} method to send back "Hello, World"
|
103
|
+
whenever someone says "hello".
|
104
|
+
|
105
|
+
That's it!
|
106
|
+
|
107
|
+
# on-handlers vs. plugins
|
108
|
+
|
109
|
+
Using `on` might be nice and handy for writing simple bots, but if you
|
110
|
+
want to write a more complex bot, providing lots of different features
|
111
|
+
to its users, then using plugins might be a better solution.
|
112
|
+
|
113
|
+
But what are plugins, exactly? Technically, plugins are implemented as
|
114
|
+
Ruby classes that mix-in a {Cinch::Plugin specific module} to get
|
115
|
+
access to various methods.
|
116
|
+
|
117
|
+
To have an example to work with, we'll convert our "Hello, World" bot
|
118
|
+
to using the plugin API:
|
119
|
+
|
120
|
+
require "cinch"
|
121
|
+
|
122
|
+
class HelloWorld
|
123
|
+
include Cinch::Plugin
|
124
|
+
|
125
|
+
match "hello"
|
126
|
+
def execute(m)
|
127
|
+
m.reply "Hello, World"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
bot = Cinch::Bot.new do
|
132
|
+
configure do |c|
|
133
|
+
c.server = "irc.freenode.net"
|
134
|
+
c.channels = ["#cinch-bots"]
|
135
|
+
c.plugins.plugins = [HelloWorld]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
bot.start
|
140
|
+
|
141
|
+
The first thing to notice is that we wrote a new class called
|
142
|
+
`HelloWorld`, and that we use {Cinch::Plugin::ClassMethods#match
|
143
|
+
match} instead of `on` to define our handler. Furthermore, we didn't
|
144
|
+
specify a message type nor did we provide any blocks.
|
145
|
+
|
146
|
+
But let's back up and proceed in smaller steps to see how plugins are built.
|
147
|
+
|
148
|
+
First thing after defining a new class is to include {Cinch::Plugin} –
|
149
|
+
This module will provide methods like
|
150
|
+
{Cinch::Plugin::ClassMethods#match match} and also allows Cinch to
|
151
|
+
control the class in specific ways required for plugins to work.
|
152
|
+
|
153
|
+
Then we use aforementioned `match`, instead of `on`, to specify what
|
154
|
+
messages we want to react to. We didn't have to specify the message
|
155
|
+
type because plugins default to {file:docs/events.md#message :message}.
|
156
|
+
|
157
|
+
We then define a method called `execute`, which is pretty much the
|
158
|
+
same as blocks are to on-handlers. And from here on, everything is the
|
159
|
+
same.
|
160
|
+
|
161
|
+
The only thing left to do is to tell Cinch to use our plugin, by
|
162
|
+
adding it to {file:docs/bot_options.md#pluginsplugins c.plugins.plugins}.
|
163
|
+
|
164
|
+
One important thing remains to note: Plugins have a
|
165
|
+
{file:docs/bot_options.md#pluginsprefix prefix}, a string (or pattern)
|
166
|
+
that gets appended to all patterns you define, and by default this
|
167
|
+
prefix is `/^!/`. This means that in order to invoke our HelloWorld
|
168
|
+
plugin, a user has to say "!hello" instead of "hello". This prefix can
|
169
|
+
be configured on a per-plugin or global basis, but that's not in the
|
170
|
+
scope of this document.
|
171
|
+
|
172
|
+
# Final Words
|
173
|
+
|
174
|
+
This short guide only explains the basics of using Cinch, so that you
|
175
|
+
can get started as quickly as possible. For more advanced topics, you
|
176
|
+
will want to read the specific documents:
|
177
|
+
|
178
|
+
- {file:docs/plugins.md Plugins}
|
179
|
+
- {file:docs/bot_options.md A list of all available bot options}
|
180
|
+
- {file:docs/events.md A list of all available events}
|
181
|
+
- {file:docs/encodings.md Dealing with encodings}
|
182
|
+
- {file:docs/logging.md Logging in Cinch}
|
183
|
+
- {file:docs/common_tasks.md A cookbook for common tasks}
|
184
|
+
- {file:docs/common_mistakes.md A list of common mistakes and how to avoid them}
|
data/docs/logging.md
CHANGED
@@ -1,6 +1,55 @@
|
|
1
1
|
# @title Logging
|
2
2
|
# @markup kramdown
|
3
3
|
|
4
|
-
|
4
|
+
# Using the logger
|
5
|
+
|
6
|
+
Plugins can use the logging facility for logging their own messages,
|
7
|
+
either by using the logging related helper methods (#debug, #info, and
|
8
|
+
so on) or by directly interfacing with {Cinch::LoggerList}, which is
|
9
|
+
available via `@bot.loggers`.
|
10
|
+
|
11
|
+
Example:
|
12
|
+
|
13
|
+
class MyPlugin
|
14
|
+
include Cinch::Plugin
|
15
|
+
|
16
|
+
match "foo"
|
17
|
+
def execute(m)
|
18
|
+
debug "Starting handler..."
|
19
|
+
info "Some more important information"
|
20
|
+
debug "Done."
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Logger levels
|
25
|
+
|
26
|
+
Cinch uses a priority-based logging system, using the types `:debug`,
|
27
|
+
`:log`, `:info`, `:warn`, `:error` and `:fatal`, each of them
|
28
|
+
displaying less information than the previous.
|
29
|
+
|
30
|
+
By default, the logging level to display is set to `:debug`, which
|
31
|
+
will include all possible kinds of log events, including the rather
|
32
|
+
verbose debug output caused by plugins.
|
33
|
+
|
34
|
+
`:log` will hide debug output but still contain the raw IRC log and
|
35
|
+
from there on, the levels are rather self-explanatory.
|
36
|
+
|
37
|
+
## Changing the level
|
38
|
+
|
39
|
+
The level can be changed for single loggers or all loggers at once, by either using {Cinch::Logger#level=} or {Cinch::LoggerList#level=} respectively.
|
40
|
+
|
41
|
+
Example:
|
42
|
+
|
43
|
+
bot = Cinch::Bot.new { }
|
44
|
+
bot.loggers << Cinch::Loggers::FormattedLogger.new(File.open("/tmp/log.log", "a"))
|
45
|
+
bot.loggers.level = :debug
|
46
|
+
bot.loggers.first.level = :info
|
47
|
+
|
48
|
+
This will set all loggers to the `:debug` level (which actually is the
|
49
|
+
default already) and the first logger (which is the default STDOUT
|
50
|
+
logger) to `:info`.
|
5
51
|
|
6
52
|
# Writing your own logger
|
53
|
+
|
54
|
+
This section will follow soon. For now just look at the code of
|
55
|
+
already implemented loggers.
|
data/docs/migrating.md
CHANGED
@@ -18,7 +18,6 @@ shouldn't and usually mustn't overwrite:
|
|
18
18
|
- `#bot`
|
19
19
|
- `#config`
|
20
20
|
- `#handlers`
|
21
|
-
- `#storage`
|
22
21
|
- `#synchronize`
|
23
22
|
- `#timers`
|
24
23
|
- `#unregister`
|
@@ -193,7 +192,7 @@ that. Alterntively you can also use the logging-related helper methods
|
|
193
192
|
provided by {Cinch::Helpers}.
|
194
193
|
|
195
194
|
For more information on the logging architecture as well as examples
|
196
|
-
on how to use it, check the {file:logging.md Logging readme}.
|
195
|
+
on how to use it, check the {file:docs/logging.md Logging readme}.
|
197
196
|
|
198
197
|
## Prefix/suffix + string semantics
|
199
198
|
|
@@ -239,12 +238,12 @@ or
|
|
239
238
|
The second version is especially interesting to tools like
|
240
239
|
{https://github.com/netfeed/cinchize Cinchize}, which load the
|
241
240
|
configuration from a YAML file. For more information see
|
242
|
-
{file:bot_options.md Bot options}.
|
241
|
+
{file:docs/bot_options.md Bot options}.
|
243
242
|
|
244
243
|
|
245
244
|
## Various removed methods
|
246
245
|
|
247
|
-
See {file:changes.md#removedrenamed-methods What's changed}
|
246
|
+
See {file:docs/changes.md#removedrenamed-methods What's changed}
|
248
247
|
|
249
248
|
|
250
249
|
## `on`-handlers now only accepts one pattern
|
data/docs/plugins.md
ADDED
data/lib/cinch/bot.rb
CHANGED
@@ -47,7 +47,7 @@ require "cinch/configuration/bot"
|
|
47
47
|
require "cinch/configuration/plugins"
|
48
48
|
require "cinch/configuration/ssl"
|
49
49
|
require "cinch/configuration/timeouts"
|
50
|
-
require "cinch/configuration/storage"
|
50
|
+
# require "cinch/configuration/storage"
|
51
51
|
require "cinch/configuration/dcc"
|
52
52
|
require "cinch/configuration/sasl"
|
53
53
|
|
@@ -171,7 +171,7 @@ module Cinch
|
|
171
171
|
# Registers a handler.
|
172
172
|
#
|
173
173
|
# @param [String, Symbol, Integer] event the event to match. For a
|
174
|
-
# list of available events, check the {file:events.md Events
|
174
|
+
# list of available events, check the {file:docs/events.md Events
|
175
175
|
# documentation}.
|
176
176
|
#
|
177
177
|
# @param [Regexp, Pattern, String] regexp every message of the
|
@@ -290,12 +290,11 @@ module Cinch
|
|
290
290
|
end while @config.reconnect and not @quitting
|
291
291
|
end
|
292
292
|
|
293
|
-
# TODO document this
|
294
293
|
def stop
|
295
|
-
@plugins.each do |plugin|
|
296
|
-
|
297
|
-
|
298
|
-
end
|
294
|
+
# @plugins.each do |plugin|
|
295
|
+
# plugin.storage.save
|
296
|
+
# plugin.storage.unload
|
297
|
+
# end
|
299
298
|
end
|
300
299
|
|
301
300
|
# @endgroup
|
data/lib/cinch/channel.rb
CHANGED
@@ -380,6 +380,18 @@ module Cinch
|
|
380
380
|
@users.clear
|
381
381
|
end
|
382
382
|
|
383
|
+
def msg(text, notice = false)
|
384
|
+
text = text.to_s
|
385
|
+
if @modes["c"]
|
386
|
+
# Remove all formatting and colors if the channel doesn't
|
387
|
+
# allow colors.
|
388
|
+
text.gsub!(/[\x02\x1F\x16\x0F]|\x03\d{2}(,\d{2})?/, "")
|
389
|
+
end
|
390
|
+
super(text, notice)
|
391
|
+
end
|
392
|
+
alias_method :send, :msg
|
393
|
+
alias_method :privmsg, :msg
|
394
|
+
|
383
395
|
# @return [Fixnum]
|
384
396
|
def hash
|
385
397
|
@name.hash
|
@@ -8,7 +8,7 @@ module Cinch
|
|
8
8
|
:realname, :user, :messages_per_second, :server_queue_size,
|
9
9
|
:strictness, :message_split_start, :message_split_end,
|
10
10
|
:max_messages, :plugins, :channels, :encoding, :reconnect, :max_reconnect_delay,
|
11
|
-
:local_host, :timeouts, :ping_interval, :
|
11
|
+
:local_host, :timeouts, :ping_interval, :dcc, :shared, :sasl]
|
12
12
|
|
13
13
|
# (see Configuration.default_config)
|
14
14
|
def self.default_config
|
@@ -37,9 +37,10 @@ module Cinch
|
|
37
37
|
:timeouts => Configuration::Timeouts.new,
|
38
38
|
:ping_interval => 120,
|
39
39
|
:delay_joins => 0,
|
40
|
-
:storage => Configuration::Storage.new,
|
40
|
+
# :storage => Configuration::Storage.new,
|
41
41
|
:dcc => Configuration::DCC.new,
|
42
42
|
:sasl => Configuration::SASL.new,
|
43
|
+
:shared => {},
|
43
44
|
}
|
44
45
|
end
|
45
46
|
end
|
@@ -27,7 +27,7 @@ module Cinch
|
|
27
27
|
# but sending files will probably be the most common case.
|
28
28
|
#
|
29
29
|
# If you're behind a NAT it is necessary to explicitly set the
|
30
|
-
# external IP using the {file:bot_options.md#dccownip dcc.own_ip
|
30
|
+
# external IP using the {file:docs/bot_options.md#dccownip dcc.own_ip
|
31
31
|
# option}.
|
32
32
|
#
|
33
33
|
# @example Sending a file to a user
|
data/lib/cinch/helpers.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# TODO @since for all methods
|
2
1
|
module Cinch
|
3
2
|
# The Helpers module contains a number of methods whose purpose is
|
4
3
|
# to make writing plugins easier by hiding parts of the API. The
|
@@ -19,6 +18,7 @@ module Cinch
|
|
19
18
|
# on :message, /^message (.+)$/ do |m, target|
|
20
19
|
# Target(target).send "hi!"
|
21
20
|
# end
|
21
|
+
# @since 2.0.0
|
22
22
|
def Target(target)
|
23
23
|
return target if target.is_a?(Target)
|
24
24
|
Target.new(target, bot)
|
@@ -32,6 +32,7 @@ module Cinch
|
|
32
32
|
# on :message, /^please join (#.+)$/ do |m, target|
|
33
33
|
# Channel(target).join
|
34
34
|
# end
|
35
|
+
# @since 1.0.0
|
35
36
|
def Channel(channel)
|
36
37
|
return channel if channel.is_a?(Channel)
|
37
38
|
bot.channel_list.find_ensured(channel)
|
@@ -46,6 +47,7 @@ module Cinch
|
|
46
47
|
# user = User(target)
|
47
48
|
# m.reply "%s is named %s and connects from %s" % [user.nick, user.name, user.host]
|
48
49
|
# end
|
50
|
+
# @since 1.0.0
|
49
51
|
def User(user)
|
50
52
|
return user if user.is_a?(User)
|
51
53
|
if user == bot.nick
|
@@ -121,6 +123,11 @@ module Cinch
|
|
121
123
|
|
122
124
|
# (see Logger#log)
|
123
125
|
def log(messages, event = :debug, level = event)
|
126
|
+
if self.is_a?(Cinch::Plugin)
|
127
|
+
messages = Array(messages).map {|m|
|
128
|
+
"[#{self.class}] " + m
|
129
|
+
}
|
130
|
+
end
|
124
131
|
@bot.loggers.log(messages, event, level)
|
125
132
|
end
|
126
133
|
|
data/lib/cinch/plugin.rb
CHANGED
@@ -10,7 +10,7 @@ module Cinch
|
|
10
10
|
#
|
11
11
|
# Most of the instance methods are for use by the Cinch framework
|
12
12
|
# and part of the private API, but some will also be used by plugin
|
13
|
-
# authors, mainly {#config}, {#synchronize}
|
13
|
+
# authors, mainly {#config}, {#synchronize} and {#bot}.
|
14
14
|
module Plugin
|
15
15
|
include Helpers
|
16
16
|
|
@@ -172,10 +172,15 @@ module Cinch
|
|
172
172
|
# @option options [Boolean] :use_suffix (true) If true, the
|
173
173
|
# plugin suffix will automatically be appended to the
|
174
174
|
# pattern.
|
175
|
+
# @option options [String, Regexp, Proc] prefix (nil) A prefix
|
176
|
+
# overwriting the per-plugin prefix.
|
177
|
+
# @option options [String, Regexp, Proc] suffix (nil) A suffix
|
178
|
+
# overwriting the per-plugin suffix.
|
179
|
+
# @option options [Symbol, Fixnum] react_on (:message) The
|
180
|
+
# {file:docs/events.md event} to react on.
|
175
181
|
# @option options [Symbol] :group (nil) The group the match belongs to.
|
176
182
|
# @return [Matcher]
|
177
183
|
# @todo Document match/listener grouping
|
178
|
-
# @todo document new options
|
179
184
|
def match(pattern, options = {})
|
180
185
|
options = {:use_prefix => true, :use_suffix => true, :method => :execute, :group => nil, :prefix => nil, :suffix => nil, :react_on => nil}.merge(options)
|
181
186
|
if options[:react_on]
|
@@ -191,15 +196,7 @@ module Cinch
|
|
191
196
|
# @overload listen_to(*types, options = {})
|
192
197
|
# @param [String, Symbol, Integer] *types Events to listen to. Available
|
193
198
|
# events are all IRC commands in lowercase as symbols, all numeric
|
194
|
-
# replies
|
195
|
-
#
|
196
|
-
# - :channel (a channel message)
|
197
|
-
# - :private (a private message)
|
198
|
-
# - :message (both channel and private messages)
|
199
|
-
# - :error (IRC errors)
|
200
|
-
# - :ctcp (ctcp requests)
|
201
|
-
# - :action (actions, aka /me)
|
202
|
-
#
|
199
|
+
# replies and all events listed in the {file:docs/events.md list of events}.
|
203
200
|
# @param [Hash] options
|
204
201
|
# @option options [Symbol] :method (:listen) The method to
|
205
202
|
# execute
|
@@ -292,7 +289,11 @@ module Cinch
|
|
292
289
|
def call_hooks(type, event, instance, args)
|
293
290
|
stop = __hooks(type, event).find { |hook|
|
294
291
|
# stop after the first hook that returns false
|
295
|
-
|
292
|
+
if hook.method.respond_to?(:call)
|
293
|
+
instance.instance_exec(*args, &hook.method) == false
|
294
|
+
else
|
295
|
+
instance.__send__(hook.method, *args) == false
|
296
|
+
end
|
296
297
|
}
|
297
298
|
|
298
299
|
!stop
|
@@ -432,14 +433,14 @@ module Cinch
|
|
432
433
|
attr_reader :timers
|
433
434
|
|
434
435
|
# @return [Storage] The per-plugin persistent storage
|
435
|
-
attr_reader :storage
|
436
|
+
# attr_reader :storage
|
436
437
|
|
437
438
|
# @api private
|
438
439
|
def initialize(bot)
|
439
440
|
@bot = bot
|
440
441
|
@handlers = []
|
441
442
|
@timers = []
|
442
|
-
@storage = bot.config.storage.backend.new(@bot.config.storage, self)
|
443
|
+
# @storage = bot.config.storage.backend.new(@bot.config.storage, self)
|
443
444
|
__register
|
444
445
|
end
|
445
446
|
|
@@ -468,6 +469,10 @@ module Cinch
|
|
468
469
|
@bot.config.plugins.options[self.class] || {}
|
469
470
|
end
|
470
471
|
|
472
|
+
def shared
|
473
|
+
@bot.config.shared
|
474
|
+
end
|
475
|
+
|
471
476
|
# @api private
|
472
477
|
def self.included(by)
|
473
478
|
by.extend ClassMethods
|
data/lib/cinch/storage.rb
CHANGED
data/lib/cinch/target.rb
CHANGED
@@ -121,6 +121,14 @@ module Cinch
|
|
121
121
|
send "\001#{message}\001"
|
122
122
|
end
|
123
123
|
|
124
|
+
def concretize
|
125
|
+
if @bot.isupport["CHANTYPES"].include?(@name[0])
|
126
|
+
@bot.channel_list.find_ensured(@name)
|
127
|
+
else
|
128
|
+
@bot.user_list.find_ensured(@name)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
124
132
|
# @return [Boolean]
|
125
133
|
def eql?(other)
|
126
134
|
self == other
|
data/lib/cinch/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Dominik Honnef
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-24 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A simple, friendly DSL for creating IRC bots
|
15
15
|
email:
|
@@ -21,10 +21,12 @@ files:
|
|
21
21
|
- LICENSE
|
22
22
|
- README.md
|
23
23
|
- docs/changes.md
|
24
|
+
- docs/getting_started.md
|
24
25
|
- docs/readme.md
|
25
26
|
- docs/bot_options.md
|
26
27
|
- docs/common_mistakes.md
|
27
28
|
- docs/events.md
|
29
|
+
- docs/plugins.md
|
28
30
|
- docs/encodings.md
|
29
31
|
- docs/logging.md
|
30
32
|
- docs/common_tasks.md
|
@@ -133,9 +135,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
136
|
none: false
|
135
137
|
requirements:
|
136
|
-
- - ! '
|
138
|
+
- - ! '>='
|
137
139
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
140
|
+
version: '0'
|
139
141
|
requirements: []
|
140
142
|
rubyforge_project:
|
141
143
|
rubygems_version: 1.8.15
|