lita-lunch 0.1.2 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09440fc049f26143edaffbf0e422d13801620d04
4
- data.tar.gz: 21e56d4f1be93ed43a5519828d471ec667fea44c
3
+ metadata.gz: 755cce4899f9b00ba7eab7bda7a0728fde4a483d
4
+ data.tar.gz: 3e633a2dbbea3000b0d8edf3aacf33cc5d3e398a
5
5
  SHA512:
6
- metadata.gz: 2c9450480d92e7111e0f9f25ed90d6ca4b4354368c13923d9baf0ec1c5a20322f56db69817691047ebcb0a7f5146f73fd42f9a4f3d9acd4d343b9f0a72488eb4
7
- data.tar.gz: 8940dc9003c4c6a1eb89a29a4fdd7f607417fab303ce3c1464c1c48d97c5917fad3666a126c2e9f573590c59e242c2dd3433259dc54c528e666092fb6501d5d5
6
+ metadata.gz: abbbf314b32e5974c6b70ceb95415c0ec3a303ab1c1474b17317bf044a9459002ed2146a70249d18e25582aa0dc0a1dc2378786caf1d980497e078da921cfb7e
7
+ data.tar.gz: 8736ff2b04212544f823ea3820d8767b3534878057002dbe6d272ffbc4bf208acccba6e03a5be14ba3232126504506d86c58765175b6337e0eacf3efc3ad9c3c
data/README.md CHANGED
@@ -5,6 +5,8 @@
5
5
 
6
6
  A lita handler to help you pick where to go for lunch.
7
7
 
8
+ Populate Lita with a list of of your favourite lunch places, so next next time someone asks "where should I go for lunch?" you get a useful suggestion.
9
+
8
10
  ## Installation
9
11
 
10
12
  Add lita-lunch to your Lita instance's Gemfile:
@@ -22,25 +24,38 @@ There is no additional configuration.
22
24
  First you will to add some of your favorite lunch places:
23
25
 
24
26
  ```
25
- lita lunch add the taco hut
26
- lita lunch add Korean BBQ
27
+ You: lita lunch add the taco hut
28
+ Lita: taco hut has been added
29
+
30
+ You: lita lunch add Korean BBQ
31
+ Lita: Korean BBQ has been added
32
+
33
+ You: lita lunch add :hamburger:
34
+ Lita: :hamburger: has been added
27
35
  ```
28
36
 
29
37
  Then you can get a lunch suggestion:
30
38
 
31
39
  ```
32
- where should I go for lunch?
33
- lita lunch suggestion
40
+ You: where should I go for lunch?
41
+ Lita: How about the taco hut?
42
+
43
+ You: lita lunch suggestion
44
+ Lita: How about :hamburger:?
34
45
  ```
35
46
 
36
47
  You can list all stored places:
37
48
 
38
49
  ```
39
- lita lunch places
50
+ You: lita lunch places
51
+ Lita: taco hut
52
+ Korean BBQ
53
+ :hamburger:
40
54
  ```
41
55
 
42
56
  And remove unwanted places:
43
57
 
44
58
  ```
45
- lita lunch remove the taco hut
59
+ You: lita lunch remove the taco hut
60
+ Lita: taco hut has been removed
46
61
  ```
@@ -10,28 +10,27 @@ module Lita
10
10
  route(/where should (we|i|they) go for lunch/i, :suggest, command: false)
11
11
 
12
12
  def suggest(response)
13
- index = Random.rand(redis.llen(REDIS_KEY).nonzero? || 1)
14
- random = redis.lindex(REDIS_KEY, index) || t('.fallback')
13
+ random = redis.srandmember(REDIS_KEY) || t('.fallback')
15
14
  response.reply t('.suggest', place: random)
16
15
  end
17
16
 
18
17
  def list_suggestions(response)
19
- values = redis.lrange(REDIS_KEY, 0, -1)
20
- response.reply values.size > 0 ? values.join("\n") : t('.empty')
18
+ values = redis.smembers(REDIS_KEY)
19
+ response.reply values.size > 0 ? values.sort.join("\n") : t('.empty')
21
20
  end
22
21
 
23
22
  def add_suggestion(response)
24
23
  place = response.matches[0][0].strip
25
24
  return if place.empty?
26
- redis.rpush(REDIS_KEY, place)
27
- response.reply t('.added', place: place)
25
+ result = redis.sadd(REDIS_KEY, place)
26
+ response.reply result ? t('.added', place: place) : t('.duplicate', place: place)
28
27
  end
29
28
 
30
29
  def remove_suggestion(response)
31
30
  place = response.matches[0][0].strip
32
31
  return if place.empty?
33
- result = redis.lrem(REDIS_KEY, 0, place)
34
- response.reply result.nonzero? ? t('.removed', place: place) : t('.unfound')
32
+ result = redis.srem(REDIS_KEY, place)
33
+ response.reply result ? t('.removed', place: place) : t('.unfound')
35
34
  end
36
35
 
37
36
  def reset!
data/lita-lunch.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-lunch"
3
- spec.version = "0.1.2"
3
+ spec.version = "0.2.0"
4
4
  spec.authors = ["neilang"]
5
5
  spec.email = ["neilang@gmail.com"]
6
6
  spec.description = "A lita handler to help you pick where to go for lunch"
data/locales/en.yml CHANGED
@@ -6,5 +6,6 @@ en:
6
6
  suggest: "How about %{place}?"
7
7
  empty: "None added yet"
8
8
  added: "%{place} has been added"
9
+ duplicate: "I already know about %{place}"
9
10
  removed: "%{place} has been removed"
10
11
  unfound: "You will need to be more specific"
@@ -46,10 +46,18 @@ describe Lita::Handlers::Lunch, lita_handler: true do
46
46
  end
47
47
 
48
48
  it 'lists all the known places' do
49
- send_command('lunch place add foo')
50
49
  send_command('lunch place add bar')
50
+ send_command('lunch place add foo')
51
51
  send_command('lunch places')
52
- expect(replies.last).to eq "foo\nbar"
52
+ expect(replies.last).to eq "bar\nfoo"
53
+ end
54
+
55
+ it 'sorts the places it knows' do
56
+ send_command('lunch place add Zoo')
57
+ send_command('lunch place add Avec')
58
+ send_command('lunch place add Longs')
59
+ send_command('lunch places')
60
+ expect(replies.last).to eq "Avec\nLongs\nZoo"
53
61
  end
54
62
  end
55
63
 
@@ -67,6 +75,12 @@ describe Lita::Handlers::Lunch, lita_handler: true do
67
75
  send_command('lunch place add ')
68
76
  expect(replies.last).to eq nil
69
77
  end
78
+
79
+ it 'will not add a duplicate place' do
80
+ send_command('lunch place add BurgerCzar')
81
+ send_command('lunch place add BurgerCzar')
82
+ expect(replies.last).to eq 'I already know about BurgerCzar'
83
+ end
70
84
  end
71
85
 
72
86
  describe 'removing a place' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-lunch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - neilang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-13 00:00:00.000000000 Z
11
+ date: 2015-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita