cinch 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +25 -44
- data/examples/basic/autovoice.rb +1 -1
- data/examples/basic/join_part.rb +0 -4
- data/examples/plugins/autovoice.rb +2 -5
- data/examples/plugins/google.rb +1 -2
- data/examples/plugins/hooks.rb +36 -0
- data/examples/plugins/lambdas.rb +35 -0
- data/examples/plugins/last_nick.rb +24 -0
- data/examples/plugins/multiple_matches.rb +1 -10
- data/examples/plugins/own_events.rb +37 -0
- data/examples/plugins/timer.rb +22 -0
- data/examples/plugins/url_shorten.rb +1 -1
- data/lib/cinch.rb +50 -1
- data/lib/cinch/ban.rb +5 -2
- data/lib/cinch/bot.rb +360 -193
- data/lib/cinch/cache_manager.rb +15 -0
- data/lib/cinch/callback.rb +6 -0
- data/lib/cinch/channel.rb +150 -96
- data/lib/cinch/channel_manager.rb +26 -0
- data/lib/cinch/constants.rb +6 -4
- data/lib/cinch/exceptions.rb +9 -0
- data/lib/cinch/irc.rb +197 -82
- data/lib/cinch/logger/formatted_logger.rb +8 -8
- data/lib/cinch/logger/zcbot_logger.rb +37 -0
- data/lib/cinch/mask.rb +17 -3
- data/lib/cinch/message.rb +14 -7
- data/lib/cinch/message_queue.rb +8 -4
- data/lib/cinch/mode_parser.rb +56 -0
- data/lib/cinch/pattern.rb +45 -0
- data/lib/cinch/plugin.rb +129 -34
- data/lib/cinch/rubyext/string.rb +4 -4
- data/lib/cinch/syncable.rb +8 -0
- data/lib/cinch/user.rb +68 -13
- data/lib/cinch/user_manager.rb +60 -0
- metadata +17 -35
- data/Rakefile +0 -66
- data/lib/cinch/PLANNED +0 -4
- data/spec/bot_spec.rb +0 -5
- data/spec/channel_spec.rb +0 -5
- data/spec/cinch_spec.rb +0 -5
- data/spec/irc_spec.rb +0 -5
- data/spec/message_spec.rb +0 -5
- data/spec/plugin_spec.rb +0 -5
- data/spec/spec.opts +0 -2
- data/spec/spec_helper.rb +0 -8
- data/spec/user_spec.rb +0 -5
data/lib/cinch/rubyext/string.rb
CHANGED
@@ -2,9 +2,9 @@ class String
|
|
2
2
|
def irc_downcase(mapping)
|
3
3
|
case mapping
|
4
4
|
when :rfc1459
|
5
|
-
self.tr("A-Z[]
|
5
|
+
self.tr("A-Z[]\\\\^", "a-z{}|~")
|
6
6
|
when :"strict-rfc1459"
|
7
|
-
self.tr("A-Z[]
|
7
|
+
self.tr("A-Z[]\\\\", "a-z{}|")
|
8
8
|
else
|
9
9
|
# when :ascii or unknown/nil
|
10
10
|
self.tr("A-Z", "a-z")
|
@@ -16,9 +16,9 @@ class String
|
|
16
16
|
when :ascii
|
17
17
|
self.tr("a-z", "A-Z")
|
18
18
|
when :rfc1459
|
19
|
-
self.tr("a-z{}|~", "A-Z[]
|
19
|
+
self.tr("a-z{}|~", "A-Z[]\\\\^")
|
20
20
|
when :strict-rfc1459
|
21
|
-
self.tr("a-z{}|", "A-Z[]
|
21
|
+
self.tr("a-z{}|", "A-Z[]\\\\")
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
data/lib/cinch/syncable.rb
CHANGED
@@ -3,6 +3,7 @@ module Cinch
|
|
3
3
|
# Blocks until the object is synced.
|
4
4
|
#
|
5
5
|
# @return [void]
|
6
|
+
# @api private
|
6
7
|
def wait_until_synced(attr)
|
7
8
|
attr = attr.to_sym
|
8
9
|
while true
|
@@ -22,14 +23,21 @@ module Cinch
|
|
22
23
|
@synced_attributes << attribute
|
23
24
|
end
|
24
25
|
|
26
|
+
# @return [Boolean]
|
27
|
+
# @api private
|
25
28
|
def synced?(attribute)
|
26
29
|
@synced_attributes.include?(attribute)
|
27
30
|
end
|
28
31
|
|
32
|
+
# @return [void]
|
33
|
+
# @api private
|
29
34
|
def unsync(attribute)
|
30
35
|
@synced_attributes.delete(attribute)
|
31
36
|
end
|
32
37
|
|
38
|
+
# @return [void]
|
39
|
+
# @api private
|
40
|
+
# @since 1.0.1
|
33
41
|
def unsync_all
|
34
42
|
@synced_attributes.clear
|
35
43
|
end
|
data/lib/cinch/user.rb
CHANGED
@@ -3,7 +3,7 @@ module Cinch
|
|
3
3
|
class User
|
4
4
|
include Syncable
|
5
5
|
|
6
|
-
@users = {}
|
6
|
+
@users = {} # this will be removed with version 2.0.0
|
7
7
|
class << self
|
8
8
|
|
9
9
|
# @overload find_ensured(nick, bot)
|
@@ -21,35 +21,54 @@ module Cinch
|
|
21
21
|
# @param [Bot] bot An instance of bot
|
22
22
|
#
|
23
23
|
# @return [User]
|
24
|
+
# @deprecated See {Bot#user_manager} and {UserManager#find_ensured} instead
|
25
|
+
# @note This method does not work properly if running more than one bot
|
26
|
+
# @note This method will be removed in Cinch 2.0.0
|
24
27
|
def find_ensured(*args)
|
25
|
-
|
28
|
+
$stderr.puts "Deprecation warning: Beginning with version 1.1.0, User.find_ensured should not be used anymore."
|
29
|
+
puts caller
|
30
|
+
|
26
31
|
case args.size
|
27
32
|
when 2
|
28
33
|
nick = args.first
|
29
|
-
bargs = [args.first]
|
30
34
|
bot = args.last
|
35
|
+
bargs = [nick]
|
31
36
|
when 4
|
32
37
|
nick = args[1]
|
33
|
-
bot
|
38
|
+
bot = args.pop
|
34
39
|
bargs = args
|
35
40
|
else
|
36
41
|
raise ArgumentError
|
37
42
|
end
|
38
|
-
downcased_nick = nick.irc_downcase(bot.irc.isupport["CASEMAPPING"])
|
39
|
-
@users[downcased_nick]
|
40
|
-
|
43
|
+
downcased_nick = nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"])
|
44
|
+
@users[downcased_nick] = args.last.user_manager.find_ensured(*args[0..-2])
|
45
|
+
# note: the complete case statement and the assignment to
|
46
|
+
# @users is only for keeping compatibility with older
|
47
|
+
# versions, which still use User.find and User.all.
|
41
48
|
end
|
42
49
|
|
43
50
|
# Finds a user.
|
44
51
|
#
|
45
52
|
# @param [String] nick nick of a user
|
46
53
|
# @return [User, nil]
|
54
|
+
# @deprecated See {Bot#user_manager} and {UserManager#find} instead
|
55
|
+
# @note This method does not work properly if running more than one bot
|
56
|
+
# @note This method will be removed in Cinch 2.0.0
|
47
57
|
def find(nick)
|
48
|
-
|
58
|
+
$stderr.puts "Deprecation warning: Beginning with version 1.1.0, User.find should not be used anymore."
|
59
|
+
puts caller
|
60
|
+
|
61
|
+
@users[downcased_nick]
|
49
62
|
end
|
50
63
|
|
51
64
|
# @return [Array<User>] Returns all users
|
65
|
+
# @deprecated See {Bot#user_manager} and {CacheManager#each} instead
|
66
|
+
# @note This method does not work properly if running more than one bot
|
67
|
+
# @note This method will be removed in Cinch 2.0.0
|
52
68
|
def all
|
69
|
+
$stderr.puts "Deprecation warning: Beginning with version 1.1.0, User.all should not be used anymore."
|
70
|
+
puts caller
|
71
|
+
|
53
72
|
@users.values
|
54
73
|
end
|
55
74
|
end
|
@@ -57,12 +76,16 @@ module Cinch
|
|
57
76
|
|
58
77
|
# @return [String]
|
59
78
|
attr_reader :nick
|
79
|
+
# @return [String]
|
80
|
+
attr_reader :last_nick
|
60
81
|
# @return [Bot]
|
61
82
|
attr_reader :bot
|
62
83
|
# @return [Boolean]
|
63
84
|
attr_reader :synced
|
64
85
|
# @return [Boolean]
|
65
86
|
attr_reader :in_whois
|
87
|
+
# @api private
|
88
|
+
attr_writer :in_whois
|
66
89
|
|
67
90
|
# @return [String]
|
68
91
|
attr_reader :user
|
@@ -115,12 +138,12 @@ module Cinch
|
|
115
138
|
# By default, you can use methods like User#user, User#host and
|
116
139
|
# alike – If you however fear that another thread might change
|
117
140
|
# data while you're using it and if this means a critical issue to
|
118
|
-
# your code, you can store the result of this method
|
119
|
-
# that instead.
|
141
|
+
# your code, you can store a clone of the result of this method
|
142
|
+
# and work with that instead.
|
120
143
|
#
|
121
144
|
# @example
|
122
|
-
# on :channel do
|
123
|
-
# data = user.data
|
145
|
+
# on :channel do |m|
|
146
|
+
# data = m.user.data.dup
|
124
147
|
# do_something_with(data.user)
|
125
148
|
# do_something_with(data.host)
|
126
149
|
# end
|
@@ -165,7 +188,7 @@ module Cinch
|
|
165
188
|
#
|
166
189
|
# @return [Boolean] true if the user is identified
|
167
190
|
def authed?
|
168
|
-
|
191
|
+
!attr(:authname).nil?
|
169
192
|
end
|
170
193
|
|
171
194
|
# @see Syncable#attr
|
@@ -196,6 +219,7 @@ module Cinch
|
|
196
219
|
# an unknown user
|
197
220
|
# @return [void]
|
198
221
|
# @api private
|
222
|
+
# @since 1.0.1
|
199
223
|
def end_of_whois(values, not_found = false)
|
200
224
|
@in_whois = false
|
201
225
|
if not_found
|
@@ -236,12 +260,17 @@ module Cinch
|
|
236
260
|
@synced = true
|
237
261
|
end
|
238
262
|
|
263
|
+
# @return [void]
|
264
|
+
# @since 1.0.1
|
239
265
|
# @api private
|
266
|
+
# @see Syncable#unsync_all
|
240
267
|
def unsync_all
|
241
268
|
@synced = false
|
242
269
|
super
|
243
270
|
end
|
244
271
|
|
272
|
+
# @group Sending messages
|
273
|
+
|
245
274
|
# Send a message to the user.
|
246
275
|
#
|
247
276
|
# @param [String] message the message
|
@@ -252,6 +281,24 @@ module Cinch
|
|
252
281
|
alias_method :privmsg, :send
|
253
282
|
alias_method :msg, :send
|
254
283
|
|
284
|
+
# Send a notice to the user.
|
285
|
+
#
|
286
|
+
# @param [String] message the message
|
287
|
+
# @return [void]
|
288
|
+
def notice(message)
|
289
|
+
@bot.notice(@nick, message)
|
290
|
+
end
|
291
|
+
|
292
|
+
# Like {#safe_send} but for notices.
|
293
|
+
#
|
294
|
+
# @param (see #safe_send)
|
295
|
+
# @return (see #safe_send)
|
296
|
+
# @see #safe_send
|
297
|
+
# @todo (see #safe_send)
|
298
|
+
def safe_notice(message)
|
299
|
+
@bot.safe_notice(@nick, message)
|
300
|
+
end
|
301
|
+
|
255
302
|
# Send a message to the user, but remove any non-printable
|
256
303
|
# characters. The purpose of this method is to send text from
|
257
304
|
# untrusted sources, like other users or feeds.
|
@@ -303,6 +350,8 @@ module Cinch
|
|
303
350
|
@bot.safe_action(@name, message)
|
304
351
|
end
|
305
352
|
|
353
|
+
# @endgroup
|
354
|
+
|
306
355
|
# @return [String]
|
307
356
|
def to_s
|
308
357
|
@nick
|
@@ -343,6 +392,12 @@ module Cinch
|
|
343
392
|
Mask.new(s)
|
344
393
|
end
|
345
394
|
|
395
|
+
# @api private
|
396
|
+
def update_nick(new_nick)
|
397
|
+
@last_nick, @nick = @nick, new_nick
|
398
|
+
@bot.user_manager.update_nick(self)
|
399
|
+
end
|
400
|
+
|
346
401
|
# Provides synced access to user attributes.
|
347
402
|
def method_missing(m, *args)
|
348
403
|
if m.to_s =~ /^(.+)_unsynced$/
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "cinch/cache_manager"
|
2
|
+
|
3
|
+
module Cinch
|
4
|
+
class UserManager < CacheManager
|
5
|
+
# Finds or creates a user.
|
6
|
+
# @overload find_ensured(nick)
|
7
|
+
# Finds or creates a user based on his nick.
|
8
|
+
#
|
9
|
+
# @param [String] nick The user's nickname
|
10
|
+
# @return [User]
|
11
|
+
# @overload find_ensured(user, nick, host)
|
12
|
+
# Finds or creates a user based on his nick but already
|
13
|
+
# setting user and host.
|
14
|
+
#
|
15
|
+
# @param [String] user The username
|
16
|
+
# @param [String] nick The nickname
|
17
|
+
# @param [String] host The user's hostname
|
18
|
+
# @return [User]
|
19
|
+
# @return [User]
|
20
|
+
# @see Bot#User
|
21
|
+
def find_ensured(*args)
|
22
|
+
case args.size
|
23
|
+
when 1
|
24
|
+
nick = args.first
|
25
|
+
bargs = [nick]
|
26
|
+
when 3
|
27
|
+
nick = args[1]
|
28
|
+
bargs = args
|
29
|
+
else
|
30
|
+
raise ArgumentError
|
31
|
+
end
|
32
|
+
downcased_nick = nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"])
|
33
|
+
@mutex.synchronize do
|
34
|
+
@cache[downcased_nick] ||= User.new(*bargs, @bot)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Finds a user.
|
39
|
+
#
|
40
|
+
# @param [String] nick nick of a user
|
41
|
+
# @return [User, nil]
|
42
|
+
def find(nick)
|
43
|
+
downcased_nick = nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"])
|
44
|
+
@cache[downcased_nick]
|
45
|
+
end
|
46
|
+
|
47
|
+
# @api private
|
48
|
+
def update_nick(user)
|
49
|
+
@mutex.synchronize do
|
50
|
+
@cache[user.nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"])] = user
|
51
|
+
@cache.delete user.last_nick.irc_downcase(@bot.irc.isupport["CASEMAPPING"])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# @api private
|
56
|
+
def delete(user)
|
57
|
+
@cache.delete_if {|n, u| u == user }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 19
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 1
|
7
|
+
- 1
|
8
8
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.2
|
9
|
+
version: 1.1.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Lee Jarvis
|
@@ -16,25 +15,10 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date:
|
18
|
+
date: 2011-01-16 00:00:00 +01:00
|
20
19
|
default_executable:
|
21
|
-
dependencies:
|
22
|
-
|
23
|
-
name: rspec
|
24
|
-
prerelease: false
|
25
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
|
-
requirements:
|
28
|
-
- - "="
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
hash: 27
|
31
|
-
segments:
|
32
|
-
- 1
|
33
|
-
- 3
|
34
|
-
- 0
|
35
|
-
version: 1.3.0
|
36
|
-
type: :development
|
37
|
-
version_requirements: *id001
|
20
|
+
dependencies: []
|
21
|
+
|
38
22
|
description: A simple, friendly DSL for creating IRC bots
|
39
23
|
email:
|
40
24
|
- lee@jarvis.co
|
@@ -47,19 +31,11 @@ extra_rdoc_files: []
|
|
47
31
|
|
48
32
|
files:
|
49
33
|
- LICENSE
|
50
|
-
- Rakefile
|
51
34
|
- README.md
|
52
|
-
- spec/user_spec.rb
|
53
|
-
- spec/plugin_spec.rb
|
54
|
-
- spec/spec_helper.rb
|
55
|
-
- spec/bot_spec.rb
|
56
|
-
- spec/spec.opts
|
57
|
-
- spec/channel_spec.rb
|
58
|
-
- spec/message_spec.rb
|
59
|
-
- spec/cinch_spec.rb
|
60
|
-
- spec/irc_spec.rb
|
61
35
|
- lib/cinch/irc.rb
|
36
|
+
- lib/cinch/channel_manager.rb
|
62
37
|
- lib/cinch/mask.rb
|
38
|
+
- lib/cinch/cache_manager.rb
|
63
39
|
- lib/cinch/exceptions.rb
|
64
40
|
- lib/cinch/rubyext/module.rb
|
65
41
|
- lib/cinch/rubyext/queue.rb
|
@@ -71,24 +47,32 @@ files:
|
|
71
47
|
- lib/cinch/user.rb
|
72
48
|
- lib/cinch/constants.rb
|
73
49
|
- lib/cinch/callback.rb
|
74
|
-
- lib/cinch/PLANNED
|
75
50
|
- lib/cinch/syncable.rb
|
51
|
+
- lib/cinch/pattern.rb
|
76
52
|
- lib/cinch/message_queue.rb
|
53
|
+
- lib/cinch/mode_parser.rb
|
77
54
|
- lib/cinch/helpers.rb
|
78
55
|
- lib/cinch/ban.rb
|
79
56
|
- lib/cinch/plugin.rb
|
57
|
+
- lib/cinch/user_manager.rb
|
80
58
|
- lib/cinch/isupport.rb
|
81
59
|
- lib/cinch/logger/logger.rb
|
82
60
|
- lib/cinch/logger/formatted_logger.rb
|
61
|
+
- lib/cinch/logger/zcbot_logger.rb
|
83
62
|
- lib/cinch/logger/null_logger.rb
|
84
63
|
- lib/cinch.rb
|
85
64
|
- examples/plugins/urban_dict.rb
|
86
65
|
- examples/plugins/multiple_matches.rb
|
87
66
|
- examples/plugins/autovoice.rb
|
88
67
|
- examples/plugins/hello.rb
|
68
|
+
- examples/plugins/lambdas.rb
|
69
|
+
- examples/plugins/last_nick.rb
|
70
|
+
- examples/plugins/hooks.rb
|
71
|
+
- examples/plugins/timer.rb
|
89
72
|
- examples/plugins/url_shorten.rb
|
90
73
|
- examples/plugins/seen.rb
|
91
74
|
- examples/plugins/join_part.rb
|
75
|
+
- examples/plugins/own_events.rb
|
92
76
|
- examples/plugins/google.rb
|
93
77
|
- examples/plugins/memo.rb
|
94
78
|
- examples/plugins/msg.rb
|
@@ -103,7 +87,7 @@ files:
|
|
103
87
|
- examples/basic/memo.rb
|
104
88
|
- examples/basic/msg.rb
|
105
89
|
has_rdoc: true
|
106
|
-
homepage: http://
|
90
|
+
homepage: http://rubydoc.info/github/cinchrb/cinch
|
107
91
|
licenses: []
|
108
92
|
|
109
93
|
post_install_message:
|
@@ -116,7 +100,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
100
|
requirements:
|
117
101
|
- - ">="
|
118
102
|
- !ruby/object:Gem::Version
|
119
|
-
hash: 49
|
120
103
|
segments:
|
121
104
|
- 1
|
122
105
|
- 9
|
@@ -127,7 +110,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
110
|
requirements:
|
128
111
|
- - ">="
|
129
112
|
- !ruby/object:Gem::Version
|
130
|
-
hash: 3
|
131
113
|
segments:
|
132
114
|
- 0
|
133
115
|
version: "0"
|
data/Rakefile
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
require 'rake/clean'
|
4
|
-
|
5
|
-
$LOAD_PATH.unshift('lib') unless $LOAD_PATH.include?('lib')
|
6
|
-
require 'cinch'
|
7
|
-
|
8
|
-
CLEAN.include ["doc"]
|
9
|
-
|
10
|
-
require 'spec/rake/spectask'
|
11
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
12
|
-
spec.libs << 'lib' << 'spec'
|
13
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
14
|
-
end
|
15
|
-
|
16
|
-
require 'yard'
|
17
|
-
YARD::Rake::YardocTask.new do |t|
|
18
|
-
t.files = ['lib/**/*.rb', 'README.md']
|
19
|
-
t.options = [
|
20
|
-
'-m', 'markdown',
|
21
|
-
'--hide-void-return',
|
22
|
-
'--quiet',
|
23
|
-
'--title', "Cinch #{Cinch::VERSION} Documentation",
|
24
|
-
'--main', 'README.md',
|
25
|
-
]
|
26
|
-
end
|
27
|
-
|
28
|
-
namespace :gem do
|
29
|
-
desc "Build gem"
|
30
|
-
task :build => ["rake:clean"] do
|
31
|
-
sh("gem build cinch.gemspec")
|
32
|
-
end
|
33
|
-
|
34
|
-
desc "Uninstall gem (not root)"
|
35
|
-
task :uninstall do
|
36
|
-
sh("gem uninstall cinch -v #{Cinch::VERSION}")
|
37
|
-
end
|
38
|
-
|
39
|
-
desc "Release to rubygems"
|
40
|
-
task :release => [:build] do
|
41
|
-
sh("gem push ./cinch-#{Cinch::VERSION}.gem")
|
42
|
-
end
|
43
|
-
|
44
|
-
desc "Install gem (not root)"
|
45
|
-
task :install => :build do
|
46
|
-
sh("gem install ./cinch-#{Cinch::VERSION} --local")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
namespace :doc do
|
51
|
-
desc "Upload documentation"
|
52
|
-
task :push => [:yard] do
|
53
|
-
# XXX rename once merge is complete
|
54
|
-
sh("scp -r doc injekt:injekt.net/doc/cinch-merge")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
task :version do
|
59
|
-
puts "Cinch version #{Cinch::VERSION}"
|
60
|
-
end
|
61
|
-
|
62
|
-
desc "Install gem (not root)"
|
63
|
-
task :install => "gem:install"
|
64
|
-
|
65
|
-
task :default => :spec
|
66
|
-
|