cinch-memo 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/lib/cinch-memo/base.rb +16 -7
- data/lib/cinch-memo/store/redis.rb +1 -1
- data/lib/cinch-memo/version.rb +1 -1
- data/test/base_test.rb +42 -15
- data/test/store/redis_test.rb +3 -3
- metadata +3 -3
data/README.md
CHANGED
@@ -33,6 +33,8 @@ Currently, only Redis is available as a backend store.
|
|
33
33
|
|
34
34
|
* !memo [nick] [message] - stores the message for the user
|
35
35
|
* !memo? - returns memo's for your nick
|
36
|
+
|
37
|
+
The bot will also auto message a user on join of the channel if there are messages for that user.
|
36
38
|
|
37
39
|
## Integration with Cinch ##
|
38
40
|
|
data/lib/cinch-memo/base.rb
CHANGED
@@ -4,7 +4,7 @@ module Cinch
|
|
4
4
|
class Base
|
5
5
|
include Cinch::Plugin
|
6
6
|
attr_accessor :backend
|
7
|
-
|
7
|
+
|
8
8
|
class << self
|
9
9
|
attr_accessor :store, :host, :port
|
10
10
|
|
@@ -15,17 +15,26 @@ module Cinch
|
|
15
15
|
|
16
16
|
def initialize(*args)
|
17
17
|
super
|
18
|
-
@backend =
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
@backend =
|
19
|
+
case self.class.store
|
20
|
+
when :redis then Cinch::Plugins::Memo::Redis.new(self.class.host, self.class.port)
|
21
|
+
else
|
22
|
+
self.class.store
|
23
|
+
end
|
24
24
|
end
|
25
25
|
|
26
26
|
match %r{memo (\S*) (.*)}, :method => :store_message
|
27
27
|
match %r{memo\?}, :method => :get_message
|
28
28
|
|
29
|
+
listen_to :join
|
30
|
+
|
31
|
+
def listen(m)
|
32
|
+
messages = @backend.retrieve(m.user.nick)
|
33
|
+
if messages || !messages.empty?
|
34
|
+
messages.each { |msg| User(m.user.nick).send(msg) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
29
38
|
# Stores message to designated user.
|
30
39
|
def store_message(m, nick, message)
|
31
40
|
if nick == @bot.nick
|
data/lib/cinch-memo/version.rb
CHANGED
data/test/base_test.rb
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path('../teststrap',__FILE__)
|
|
3
3
|
context "Base" do
|
4
4
|
dont_register!
|
5
5
|
setup { @bot = mock() }
|
6
|
-
|
6
|
+
|
7
7
|
helper :base do |store|
|
8
8
|
Cinch::Plugins::Memo::Base.configure do |c|
|
9
9
|
c.store = store
|
@@ -16,24 +16,24 @@ context "Base" do
|
|
16
16
|
setup { base(:redis) }
|
17
17
|
asserts(:store).equals :redis
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
context "#initialize" do
|
21
21
|
setup { base(:redis).new(@bot) }
|
22
22
|
asserts_topic.assigns :backend
|
23
23
|
end
|
24
|
-
|
25
|
-
context "#store_message" do
|
24
|
+
|
25
|
+
context "#store_message" do
|
26
26
|
setup do
|
27
27
|
@bot.expects(:nick).returns('bob')
|
28
28
|
@base = base(:redis).new(@bot)
|
29
29
|
@message = mock()
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
context "with bot nick" do
|
33
33
|
setup { @message.expects(:reply).with("You can't store a message for me.").returns(true) }
|
34
34
|
asserts("that it doesn't save message for bot") { @base.store_message(@message,'bob','hey') }
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
context "with non-bot nick" do
|
38
38
|
setup do
|
39
39
|
@replier = mock() ; @replier.expects(:nick).returns("chris")
|
@@ -44,18 +44,18 @@ context "Base" do
|
|
44
44
|
@base.backend = @backend
|
45
45
|
end
|
46
46
|
asserts("that it does save message") { @base.store_message(@message, 'john', 'hey') }
|
47
|
-
end
|
47
|
+
end
|
48
48
|
end
|
49
|
-
|
50
|
-
context "#deliver_message" do
|
49
|
+
|
50
|
+
context "#deliver_message" do
|
51
51
|
setup do
|
52
52
|
@replier = mock() ; @replier.expects(:nick).returns('chris')
|
53
53
|
@message = mock() ; @message.expects(:user).returns(@replier)
|
54
54
|
@backend = mock()
|
55
55
|
@base = base(:redis).new(@bot)
|
56
56
|
end
|
57
|
-
|
58
|
-
context "with message" do
|
57
|
+
|
58
|
+
context "with message" do
|
59
59
|
setup do
|
60
60
|
@backend.expects(:retrieve).with('chris').returns(["john: hey there!", "john: bye!"])
|
61
61
|
@base.backend = @backend
|
@@ -64,8 +64,8 @@ context "Base" do
|
|
64
64
|
end
|
65
65
|
asserts("that it returns message") { @base.get_message(@message) }
|
66
66
|
end
|
67
|
-
|
68
|
-
context "without message" do
|
67
|
+
|
68
|
+
context "without message" do
|
69
69
|
setup do
|
70
70
|
@backend.expects(:retrieve).with('chris').returns([])
|
71
71
|
@base.backend = @backend
|
@@ -74,5 +74,32 @@ context "Base" do
|
|
74
74
|
asserts("that it says there aren't messages") { @base.get_message(@message) }
|
75
75
|
end
|
76
76
|
end
|
77
|
-
|
78
|
-
|
77
|
+
|
78
|
+
context "#listen" do
|
79
|
+
setup do
|
80
|
+
@replier = mock() ; @replier.stubs(:nick).returns('chris')
|
81
|
+
@message = mock() ; @message.stubs(:user).returns(@replier)
|
82
|
+
@backend = mock()
|
83
|
+
@base = base(:redis).new(@bot)
|
84
|
+
end
|
85
|
+
context "with messages" do
|
86
|
+
setup do
|
87
|
+
@u = mock() ; @u.expects(:send).with('john')
|
88
|
+
@base.expects(:User).with('chris').returns(@u)
|
89
|
+
@backend.expects(:retrieve).with('chris').returns(['john'])
|
90
|
+
@base.backend = @backend
|
91
|
+
end
|
92
|
+
asserts("that it pings message") { @base.listen(@message) }
|
93
|
+
end
|
94
|
+
|
95
|
+
context "without messages" do
|
96
|
+
setup do
|
97
|
+
@backend.expects(:retrieve).with('chris').returns([])
|
98
|
+
@base.expects(:User).with('chris').never
|
99
|
+
@base.backend = @backend
|
100
|
+
end
|
101
|
+
asserts("that it doesn't ping them") { @base.listen(@message) }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
data/test/store/redis_test.rb
CHANGED
@@ -14,7 +14,7 @@ context "Redis" do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
context "#initialize" do
|
17
|
-
setup { ::Redis.expects(:new).with(:host => 'localhost', :port => '6709') }
|
17
|
+
setup { ::Redis.expects(:new).with(:host => 'localhost', :port => '6709', :thread_safe => true) }
|
18
18
|
setup { base.new(@bot) }
|
19
19
|
asserts_topic.assigns :backend
|
20
20
|
end
|
@@ -23,7 +23,7 @@ context "Redis" do
|
|
23
23
|
setup do
|
24
24
|
Timecop.freeze(Time.now)
|
25
25
|
backend = mock() ; backend.expects(:sadd).with('bob', ['chris','yo yo', Time.now].to_json).returns(true)
|
26
|
-
::Redis.expects(:new).with(:host => 'localhost', :port => '6709').returns(backend)
|
26
|
+
::Redis.expects(:new).with(:host => 'localhost', :port => '6709', :thread_safe=>true).returns(backend)
|
27
27
|
Cinch::Plugins::Memo::Redis.new('localhost','6709')
|
28
28
|
end
|
29
29
|
asserts("that it stores message") { topic.store('bob', 'chris','yo yo') }
|
@@ -34,7 +34,7 @@ context "Redis" do
|
|
34
34
|
Timecop.freeze(Time.now)
|
35
35
|
backend = mock() ; backend.expects(:smembers).with("bob").returns("\[\"a\",\"b\",\"c\"\]")
|
36
36
|
backend.expects(:del).with('bob').returns(true)
|
37
|
-
::Redis.expects(:new).with(:host => 'localhost', :port => '6709').returns(backend)
|
37
|
+
::Redis.expects(:new).with(:host => 'localhost', :port => '6709', :thread_safe=>true).returns(backend)
|
38
38
|
Cinch::Plugins::Memo::Redis.new('localhost','6709')
|
39
39
|
end
|
40
40
|
asserts("that it retrieves message") { topic.retrieve('bob') }
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
- 0
|
8
7
|
- 1
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Arthur Chiu
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-09 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|