lita-cricket 0.0.2 → 0.0.3
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/lib/lita/handlers/cricket.rb +31 -39
- data/spec/lita/handlers/cricket_spec.rb +4 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c638ba5ba8f85f6a7ec494d3dd863571b068cf5d
|
4
|
+
data.tar.gz: 47f8400449b02dedc21fb73b1423a1b314bd620d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a3e9bbdeb8b625047cd39704a7c020258895af0a095cccad3eac88c4249fa7e741f7f99d5dd3c5fcb6607833180575290639379f9c3decca6b62ad7e59a4518
|
7
|
+
data.tar.gz: bca90ad637245dd4c17a5c262f47708eb774acc7b661419d7cd0890bd5d4ea0eacb7b556518c5933105a891d1fcd3c550551babcbef44941a5d9d0e4230c0479
|
@@ -2,7 +2,7 @@ module Lita
|
|
2
2
|
module Handlers
|
3
3
|
class Cricket < Handler
|
4
4
|
# Version
|
5
|
-
VERSION = '0.0.
|
5
|
+
VERSION = '0.0.3'
|
6
6
|
|
7
7
|
# Dependencies
|
8
8
|
require 'json'
|
@@ -80,22 +80,22 @@ module Lita
|
|
80
80
|
)
|
81
81
|
|
82
82
|
def refresh_user(response)
|
83
|
-
my_favourites =
|
83
|
+
my_favourites = get_my_subscriptions(response,'favourite')
|
84
84
|
if my_favourites.empty?
|
85
|
-
|
85
|
+
set_my_subscriptions(response,['Australia'].to_json,'favourite')
|
86
86
|
response.reply('I can give you live cricket updates! Type `help cricket` for more information.')
|
87
87
|
elsif
|
88
88
|
matches = get_list_of_live_matches
|
89
89
|
matches.each do |m|
|
90
90
|
unless ([ m['t1'], m['t2']] & my_favourites).empty?
|
91
|
-
|
91
|
+
subscribe_to(response,m['id'],'match')
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
def scores(response)
|
98
|
-
subs = get_my_subscriptions(response)
|
98
|
+
subs = get_my_subscriptions(response,'match')
|
99
99
|
subs.each do |match|
|
100
100
|
get_match_score(response,match)
|
101
101
|
end
|
@@ -108,16 +108,16 @@ module Lita
|
|
108
108
|
|
109
109
|
def subscribe(response)
|
110
110
|
match = response.matches[0][0].to_i
|
111
|
-
|
111
|
+
subscribe_to(response,match,'match')
|
112
112
|
end
|
113
113
|
|
114
114
|
def unsubscribe(response)
|
115
115
|
match = response.matches[0][0].to_i
|
116
|
-
subs = get_my_subscriptions(response)
|
116
|
+
subs = get_my_subscriptions(response,'match')
|
117
117
|
if subs.delete(match) == nil
|
118
118
|
response.reply("You weren't subscribed to match #{match}!")
|
119
119
|
else
|
120
|
-
resp = set_my_subscriptions(response,subs)
|
120
|
+
resp = set_my_subscriptions(response,subs,'match')
|
121
121
|
response.reply("Unsubscribed you to match #{match}: #{resp}")
|
122
122
|
end
|
123
123
|
end
|
@@ -135,45 +135,27 @@ module Lita
|
|
135
135
|
|
136
136
|
def favourite(response)
|
137
137
|
match = response.matches[0][0]
|
138
|
-
|
139
|
-
favs << match
|
140
|
-
favs.uniq!
|
141
|
-
resp = set_my_favourites(response,favs)
|
142
|
-
response.reply("Added #{match} to your favourites: #{resp}")
|
138
|
+
subscribe_to(response,match,'favourite')
|
143
139
|
end
|
144
140
|
|
145
141
|
def unfavourite(response)
|
146
142
|
match = response.matches[0][0]
|
147
|
-
|
148
|
-
if favs.delete(match) == nil
|
149
|
-
response.reply("#{match} wasn't in your favourite list!")
|
150
|
-
else
|
151
|
-
resp = set_my_favourites(response,favs)
|
152
|
-
response.reply("Removed #{match} from your favourites: #{resp}")
|
153
|
-
end
|
143
|
+
unsubscribe_to(response,match,'favourite')
|
154
144
|
end
|
155
145
|
|
156
146
|
def info(response)
|
157
|
-
subs = get_my_subscriptions(response)
|
158
|
-
favs =
|
147
|
+
subs = get_my_subscriptions(response,'match')
|
148
|
+
favs = get_my_subscriptions(response,'favourite')
|
159
149
|
response.reply("Subscriptions: #{subs.join(' | ')}")
|
160
150
|
response.reply("Favourites: #{favs.join(' | ')}")
|
161
151
|
end
|
162
152
|
|
163
|
-
def get_my_subscriptions(response)
|
164
|
-
JSON.parse(redis.get("#{response.user.id}
|
165
|
-
end
|
166
|
-
|
167
|
-
def set_my_subscriptions(response,subs)
|
168
|
-
redis.set("#{response.user.id}-subscriptions",subs)
|
169
|
-
end
|
170
|
-
|
171
|
-
def get_my_favourites(response)
|
172
|
-
JSON.parse(redis.get("#{response.user.id}-favourites")) rescue []
|
153
|
+
def get_my_subscriptions(response,type)
|
154
|
+
JSON.parse(redis.get("#{response.user.id}-#{type}")) rescue []
|
173
155
|
end
|
174
156
|
|
175
|
-
def
|
176
|
-
redis.set("#{response.user.id}
|
157
|
+
def set_my_subscriptions(response,subs,type)
|
158
|
+
redis.set("#{response.user.id}-#{type}",subs)
|
177
159
|
end
|
178
160
|
|
179
161
|
def get_list_of_live_matches
|
@@ -189,12 +171,22 @@ module Lita
|
|
189
171
|
end
|
190
172
|
end
|
191
173
|
|
192
|
-
def
|
193
|
-
subs = get_my_subscriptions(response)
|
194
|
-
if (subs
|
174
|
+
def subscribe_to(response,id,type)
|
175
|
+
subs = get_my_subscriptions(response,type)
|
176
|
+
if (subs & [id]).empty?
|
195
177
|
subs << id
|
196
|
-
resp = set_my_subscriptions(response,subs)
|
197
|
-
response.reply("Subscribed you to
|
178
|
+
resp = set_my_subscriptions(response,subs,type)
|
179
|
+
response.reply("Subscribed you to #{type} #{id}: #{resp}")
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def unsubscribe_to(response,id,type)
|
184
|
+
subs = get_my_subscriptions(response,type)
|
185
|
+
if subs.delete(id) == nil
|
186
|
+
response.reply("#{id} wasn't in your #{type} list!")
|
187
|
+
else
|
188
|
+
resp = set_my_subscriptions(response,subs,type)
|
189
|
+
response.reply("Unsubscribed you from #{type} #{id}: #{resp}")
|
198
190
|
end
|
199
191
|
end
|
200
192
|
|
@@ -46,13 +46,15 @@ describe Lita::Handlers::Cricket, lita_handler: true do
|
|
46
46
|
|
47
47
|
it 'adds or removes a favourite team and also updates your favourite teams if you mention cricket' do
|
48
48
|
send_message('cricket -f Cromer Cricket Club')
|
49
|
-
expect(replies.last).to eq('
|
49
|
+
expect(replies.last).to eq('Subscribed you to favourite Cromer Cricket Club: OK')
|
50
50
|
send_message('cricket is grouse')
|
51
51
|
# it is tricky to test this last feature
|
52
52
|
send_message('cricket -r Cromer Cricket Club')
|
53
|
-
expect(replies.last).to eq('
|
53
|
+
expect(replies.last).to eq('Unsubscribed you from favourite Cromer Cricket Club: OK')
|
54
54
|
send_message('cricket -r Dee Why Cricket Club')
|
55
55
|
expect(replies.last).to eq('Dee Why Cricket Club wasn\'t in your favourite list!')
|
56
|
+
send_message('cricket -f Derbyshire')
|
57
|
+
send_message('cricket')
|
56
58
|
end
|
57
59
|
|
58
60
|
it 'lists your favourite teams and subscribed matches' do
|