lita-onewheel-beer-wework 0.0.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/lita/handlers/onewheel_beer_wework.rb +37 -24
- data/lita-onewheel-beer-wework.gemspec +1 -1
- data/spec/lita/handlers/onewheel_beer_wework_spec.rb +10 -4
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbb5d83948e34954e3362634fb4eb164def1738c
|
4
|
+
data.tar.gz: 8a54bd817965a9392ba78a9cce1631ff42c78834
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 103d1a396161050c51ac0c3aecc38e2cdc62b97ffc1fdf4d1dc6d3e18167187715661e8551098d3a64d9d87101b99561bf2d08146d139e891d803df4a4d4aab6
|
7
|
+
data.tar.gz: 39292bdb13b8c5bbeb392ac7f44601a4bd855cc363ab5580d249fc26880014e2dfe91effaa8c63838f09a5cda48028dcaa19f33e44d9235fb80c5f30e1b70f9f
|
data/.gitignore
CHANGED
@@ -1,48 +1,65 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module Lita
|
2
4
|
module Handlers
|
3
5
|
class OnewheelBeerWework < Handler
|
4
|
-
REDIS_KEY = 'onewheel-
|
6
|
+
REDIS_KEY = 'onewheel-beer-wework'
|
7
|
+
LOCATIONS = %w(1fs 1fn 2fs 2fn 3fn)
|
5
8
|
|
6
9
|
route /^wework\s+([\w\/+_-]+)\s+(.*)$/i,
|
7
|
-
:
|
10
|
+
:command_add_beer,
|
8
11
|
command: true,
|
9
12
|
help: {'!wework 2fS Beer' => 'Add a beer to 2fS'}
|
10
13
|
route /^wework$/i,
|
11
|
-
:
|
14
|
+
:command_list_beers,
|
12
15
|
command: true,
|
13
16
|
help: {'!wework ' => 'list all beers'}
|
14
17
|
route /^wework\s+(\w+)$/i,
|
15
|
-
:
|
18
|
+
:command_fetch_beer,
|
16
19
|
command: true,
|
17
20
|
help: {'!wework 2fS ' => 'fetch the beer for 2fS'}
|
18
21
|
|
19
|
-
def
|
22
|
+
def command_add_beer(response)
|
20
23
|
key = response.matches[0][0].downcase
|
21
|
-
unless
|
24
|
+
unless LOCATIONS.include? key
|
22
25
|
Lita.logger.info "#{key} was not found in the floors array."
|
23
26
|
return
|
24
27
|
end
|
25
|
-
|
26
|
-
|
28
|
+
beer_name = response.matches[0][1]
|
29
|
+
key = key[0..1] + key[-1].downcase
|
30
|
+
value = {
|
31
|
+
name: beer_name,
|
32
|
+
user: response.user.name,
|
33
|
+
time: Time.now
|
34
|
+
}.to_json
|
27
35
|
redis.hset(REDIS_KEY, key, value)
|
28
|
-
response.reply "Logged #{
|
36
|
+
response.reply "Logged #{beer_name} at #{key}!"
|
29
37
|
end
|
30
38
|
|
31
|
-
def
|
39
|
+
def command_fetch_beer(response)
|
32
40
|
key = response.matches[0][0]
|
33
41
|
|
34
|
-
|
35
|
-
|
42
|
+
values = get_values_that_start_with_key(key)
|
43
|
+
values.each do |keg|
|
44
|
+
floor_id, keg_name = get_floor_and_keg_name(keg)
|
45
|
+
response.reply "#{floor_id}: #{keg_name}"
|
46
|
+
end
|
36
47
|
end
|
37
48
|
|
38
|
-
def
|
39
|
-
|
49
|
+
def get_floor_and_keg_name(keg)
|
50
|
+
floor_id = keg.keys[0]
|
51
|
+
keg_meta = JSON.parse(keg[floor_id])
|
52
|
+
return floor_id, keg_meta['name']
|
53
|
+
end
|
40
54
|
|
41
|
-
|
42
|
-
|
43
|
-
|
55
|
+
def command_list_beers(response)
|
56
|
+
test = redis.hgetall(REDIS_KEY)
|
57
|
+
LOCATIONS.each do |floor|
|
58
|
+
if (data = redis.hget(REDIS_KEY, floor))
|
59
|
+
floor, keg_name = get_floor_and_keg_name(floor => data)
|
60
|
+
response.reply "#{floor}: #{keg_name}"
|
61
|
+
end
|
44
62
|
end
|
45
|
-
response.reply replies.join ", "
|
46
63
|
end
|
47
64
|
|
48
65
|
def get_values_that_start_with_key(key)
|
@@ -50,14 +67,10 @@ module Lita
|
|
50
67
|
all = redis.hgetall(REDIS_KEY)
|
51
68
|
all.each do |all_key, all_val|
|
52
69
|
if all_key =~ /^#{key}/i
|
53
|
-
values.push
|
70
|
+
values.push all_key => all_val
|
54
71
|
end
|
55
72
|
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
def format_key_val_response(all_key, all_val)
|
60
|
-
"#{all_key}: #{all_val}"
|
73
|
+
values
|
61
74
|
end
|
62
75
|
end
|
63
76
|
|
@@ -6,19 +6,25 @@ describe Lita::Handlers::OnewheelBeerWework, lita_handler: true do
|
|
6
6
|
|
7
7
|
it 'sets a beer' do
|
8
8
|
send_command 'wework 2fs Breakfast Stout'
|
9
|
-
expect(replies.last).to eq('Logged Breakfast Stout at
|
9
|
+
expect(replies.last).to eq('Logged Breakfast Stout at 2fs!')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'doesn\'t set a beer' do
|
13
|
+
send_command 'wework 9fF Breakfast Stout'
|
14
|
+
expect(replies.last).to eq(nil)
|
10
15
|
end
|
11
16
|
|
12
17
|
it 'gets a beer' do
|
13
18
|
send_command 'wework 2fs Breakfast Stout'
|
14
19
|
send_command 'wework 2fs'
|
15
|
-
expect(replies.last).to eq('
|
20
|
+
expect(replies.last).to eq('2fs: Breakfast Stout')
|
16
21
|
end
|
17
22
|
|
18
|
-
it 'lists
|
23
|
+
it 'lists beers' do
|
19
24
|
send_command 'wework 2fs one'
|
20
25
|
send_command 'wework 2fN two'
|
21
26
|
send_command 'wework'
|
22
|
-
expect(replies
|
27
|
+
expect(replies[2]).to eq('2fs: one')
|
28
|
+
expect(replies.last).to eq('2fn: two')
|
23
29
|
end
|
24
30
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-onewheel-beer-wework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kreps
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|