lita-coffee 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64b6fd18a9681ae1c31cb6fdb0f752a566205c18
4
- data.tar.gz: 951b84eec9c661714d019e08b78ee19c2cabe202
3
+ metadata.gz: 4b49345f070b8d118bf1d960e0f07dcd7a56dffc
4
+ data.tar.gz: 7ff14d8b53dbeb2cee7200933edcd8e164e96c2e
5
5
  SHA512:
6
- metadata.gz: e218834fae3471c72221e1b59982c865edb6a888610e1ad14cf70e31aad5a8822a4afcc91e5ed5dc8ea47c3a13718b0318993e7169eb2eabac4e788c75b67a3d
7
- data.tar.gz: 12c67a729d5126d23e985885554568ed1e51ef54e873fce086ba1b38d8992dc41fa50cbc29038ee8cbce20e3295d33113e72839e0452b94cdf20c8a6228f48e4
6
+ metadata.gz: 48816a6a46e4569e3b64a2e3393c9be8daa0855bcb5db2260b248be329e0ecb215c24f4337ec549caa47537953793b54933e34b3575fd7344ad78ae1779ca113
7
+ data.tar.gz: b897fd6aa5f26089d1a0d57636ffe8163f33f9f509f7a2e3282856fc0b92f13a294de8e0b12acbe7aa4c91233a309aebbe617abf8c34ef533cce0f9ee2747dcc
@@ -19,18 +19,18 @@ module Lita
19
19
  end
20
20
 
21
21
  route(
22
- /^\(coffee\)(\s+\-[bcdgist]?|\s+\+)?(.*)/i,
22
+ /^\(?coffee\)?(\s+\-[bcdgist]?|\s+\+)?(.*)/i,
23
23
  :coffee,
24
24
  help: {
25
- '(coffee)' => "List the (coffee) orders for your group",
26
- '(coffee) -i' => "Display your (coffee) profile",
27
- '(coffee) -s Colombian Filter' => "Set your (coffee) preference",
28
- '(coffee) -g Cool Kids' => "Change your (coffee) group",
29
- '(coffee) +' => "Order a (coffee)",
30
- '(coffee) -c' => "Cancel your (coffee) order",
31
- '(coffee) -b You owe me one!' => "Buy (coffee) for your group, clear the orders and send a message",
32
- '(coffee) -t' => "Display (coffee) system settings",
33
- '(coffee) -d' => "Delete you from the (coffee) system",
25
+ 'coffee' => "List the orders for your group",
26
+ 'coffee -i' => "Display your profile",
27
+ 'coffee -s Colombian Filter' => "Set your coffee preference",
28
+ 'coffee -g Cool Kids' => "Change your group",
29
+ 'coffee +' => "Order a coffee",
30
+ 'coffee -c' => "Cancel your order",
31
+ 'coffee -b You owe me one!' => "Buy coffee for your group, clear the orders and send a message to each coffee drinker",
32
+ 'coffee -t' => "Display system settings",
33
+ 'coffee -d' => "Delete you from the coffee system",
34
34
  }
35
35
  )
36
36
 
@@ -50,71 +50,71 @@ module Lita
50
50
  group = get_group(my_user)
51
51
 
52
52
  # Setup new users
53
- response.reply("Welcome to (coffee)! You have been setup in the #{@@DEFAULT_GROUP} group with an order of #{@@DEFAULT_COFFEE}. Type help (coffee) for help.") if initialize_user_redis(my_user) == :new_user
53
+ response.reply("Welcome to coffee! You have been added to the #{@@DEFAULT_GROUP} group with an order of #{@@DEFAULT_COFFEE}. Type help coffee for help.") if initialize_user_redis(my_user) == :new_user
54
54
 
55
55
  # Retrieve my preference
56
56
  if get_settings
57
57
  settings = get_settings(my_user)
58
- response.reply("Your current (coffee) is #{settings['coffee']}. You are in the #{settings['group']} group.")
58
+ response.reply("Your current coffee is #{settings['coffee']}. You are in the #{settings['group']} group.")
59
59
  # Set my coffee
60
60
  elsif set_coffee
61
61
  result = set_coffee(my_user,preference)
62
62
  if result == "OK"
63
- response.reply("(coffee) set to #{preference}")
63
+ response.reply("Coffee set to #{preference}")
64
64
  else
65
- response.reply("(sadpanda) Failed to set your (coffee) for some reason: #{result.inspect}")
65
+ response.reply("(sadpanda) Failed to set your coffee for some reason: #{result.inspect}")
66
66
  end
67
67
  # Delete me altogether
68
68
  elsif delete_me
69
69
  result = delete_user(my_user)
70
70
  if result == 1
71
- response.reply("You have been deleted from (coffee)")
71
+ response.reply("You have been deleted from coffee")
72
72
  else
73
- response.reply("(sadpanda) Failed to delete you from (coffee) for some reason: #{result.inspect}")
73
+ response.reply("(sadpanda) Failed to delete you from coffee for some reason: #{result.inspect}")
74
74
  end
75
75
  # Change my coffee group
76
76
  elsif change_group
77
77
  result = set_coffee_group(my_user,preference)
78
78
  if result == "OK"
79
- response.reply("(coffee) group set to #{preference}")
79
+ response.reply("Group set to #{preference}")
80
80
  else
81
- response.reply("(sadpanda) Failed to set your (coffee) group for some reason: #{result.inspect}")
81
+ response.reply("(sadpanda) Failed to set your coffee group for some reason: #{result.inspect}")
82
82
  end
83
83
  # Order a coffee
84
84
  elsif order
85
85
  result = order_coffee(my_user)
86
86
  if result == "OK"
87
- response.reply("Ordered you a (coffee)")
87
+ response.reply("Ordered you a coffee")
88
88
  else
89
- response.reply("(sadpanda) Failed to order your (coffee) for some reason: #{result.inspect}")
89
+ response.reply("(sadpanda) Failed to order your coffee for some reason: #{result.inspect}")
90
90
  end
91
91
  # Cancel a coffee
92
92
  elsif cancel
93
93
  result = cancel_coffee(my_user)
94
94
  if result == "OK"
95
- response.reply("Cancelled your (coffee)")
95
+ response.reply("Cancelled your coffee")
96
96
  else
97
- response.reply("(sadpanda) Failed to cancel your (coffee) for some reason: #{result.inspect}")
97
+ response.reply("(sadpanda) Failed to cancel your coffee for some reason: #{result.inspect}")
98
98
  end
99
99
  # Buy the coffees and clear the orders
100
100
  elsif buy_coffee
101
- response.reply("Thanks for ordering the (coffee) for #{group}!\n--")
101
+ response.reply("Thanks for ordering the coffee for #{group}!\n--")
102
102
  get_orders(group).each do |order|
103
103
  response.reply("#{order}: #{get_coffee(order)}")
104
104
  send_coffee_message(order,my_user,preference) unless order == my_user
105
105
  end
106
106
  result = clear_orders(group)
107
107
  if result == "OK"
108
- response.reply("Cleared all (coffee) orders for #{group}")
108
+ response.reply("Cleared all orders for #{group}")
109
109
  else
110
- response.reply("(sadpanda) Failed to clear the (coffee) orders for some reason: #{result.inspect}")
110
+ response.reply("(sadpanda) Failed to clear the orders for some reason: #{result.inspect}")
111
111
  end
112
112
  # tests
113
113
  elsif system_settings
114
114
  response.reply("Default coffee: #{@@DEFAULT_COFFEE}, Default group: #{@@DEFAULT_GROUP}")
115
115
  # List the orders
116
116
  else
117
- response.reply("Current (coffee) orders for #{group}:-\n--")
117
+ response.reply("Current orders for #{group}:-\n--")
118
118
  get_orders(group).each do |order|
119
119
  response.reply("#{order}: #{get_coffee(order)}")
120
120
  end
@@ -192,7 +192,7 @@ module Lita
192
192
  def send_coffee_message(user,purchaser,message)
193
193
  myuser = Lita::User.find_by_name(user)
194
194
  msg = Lita::Message.new(robot,'',Lita::Source.new(user: myuser))
195
- msg.reply("#{purchaser} has bought you a (coffee)!")
195
+ msg.reply("#{purchaser} has bought you a coffee!")
196
196
  msg.reply(message) # what happens if message is nil?
197
197
  rescue => e
198
198
  Lita.logger.error("Coffee#send_coffee_message raised #{e.class}: #{e.message}\n#{e.backtrace}")
data/lita-coffee.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-coffee'
3
- spec.version = '0.0.1'
3
+ spec.version = '0.0.2'
4
4
  spec.authors = ['Stuart Auld']
5
5
  spec.email = ['sja@marsupialmusic.net']
6
6
  spec.description = %q{Lita integration to manage office coffee orders}
@@ -1,71 +1,90 @@
1
1
  require "spec_helper"
2
- #TODO: write this stuff
3
2
 
4
3
  describe Lita::Handlers::Coffee, lita_handler: true do
5
4
 
6
- it { is_expected.to route('(coffee).to(:coffee)')}
5
+ it { is_expected.to route('(coffee)').to(:coffee) }
6
+ it { is_expected.to route('coffee').to(:coffee) }
7
7
 
8
8
  describe '#coffee' do
9
9
  before{robot.trigger(:loaded)}
10
10
 
11
11
  it 'sets up a user if they do not exist already' do
12
- send_message("(coffee)")
13
- expect(replies.first).to start_with("Welcome to (coffee)!") #TODO: test for defaults here?
12
+ send_message("coffee")
13
+ expect(replies.first).to start_with("Welcome to coffee!")
14
14
  end
15
15
 
16
16
  it 'lists the current coffee orders if no options received' do
17
- send_message("(coffee)")
18
- expect(replies.last).to start_with("Current (coffee) orders")
17
+ send_message("coffee")
18
+ expect(replies.last).to start_with("Current orders")
19
19
  end
20
20
 
21
21
  it 'orders me a coffee if I ask it!' do
22
- send_message("(coffee) +")
23
- expect(replies.last).to eq("Ordered you a (coffee)") #TODO: test that it has been added to the queue?
22
+ send_message("coffee +")
23
+ expect(replies.last).to eq("Ordered you a coffee")
24
+ send_message("coffee")
25
+ expect(replies.last).to start_with("Test User:")
24
26
  end
25
27
 
26
28
  it 'displays my profile settings' do
27
- send_message("(coffee) -i")
28
- expect(replies.last).to start_with("Your current (coffee) is")
29
+ send_message("coffee -i")
30
+ expect(replies.last).to start_with("Your current coffee is")
29
31
  end
30
32
 
31
33
  it 'sets my coffee preference' do
32
- send_message("(coffee) -s decaf soy cappuccino")
33
- expect(replies.last).to eq("(coffee) set to decaf soy cappuccino")
34
- send_message("(coffee) -i")
35
- expect(replies.last).to start_with("Your current (coffee) is decaf soy cappuccino")
34
+ send_message("coffee -s decaf soy cappuccino")
35
+ expect(replies.last).to eq("Coffee set to decaf soy cappuccino")
36
+ send_message("coffee -i")
37
+ expect(replies.last).to start_with("Your current coffee is decaf soy cappuccino")
36
38
  end
37
39
 
38
40
  it 'changes my coffee group' do
39
- send_message("(coffee) -g testing team")
40
- expect(replies.last).to eq("(coffee) group set to testing team")
41
- send_message("(coffee) -i")
41
+ send_message("coffee -g testing team")
42
+ expect(replies.last).to eq("Group set to testing team")
43
+ send_message("coffee -i")
42
44
  expect(replies.last).to end_with("You are in the testing team group.")
43
45
  end
44
46
 
45
47
  it 'cancels my order' do
46
- send_message("(coffee) -c")
47
- expect(replies.last).to eq("Cancelled your (coffee)") #TODO: check that my name has been removed from the queue
48
+ send_message("coffee +")
49
+ order_a_coffee('stu')
50
+ order_a_coffee('joel')
51
+ expect(coffees_in_the_queue).to eq(3)
52
+ send_message("coffee -c")
53
+ expect(replies.last).to eq("Cancelled your coffee") #TODO: check that my name has been removed from the queue
54
+ expect(coffees_in_the_queue).to eq(2)
48
55
  end
49
56
 
50
57
  it 'deletes me from the system' do
51
- send_message("(coffee) -d")
52
- expect(replies.last).to eq("You have been deleted from (coffee)")
58
+ send_message("coffee -d")
59
+ expect(replies.last).to eq("You have been deleted from coffee")
53
60
  end
54
61
 
55
62
  it 'displays default settings' do
56
- send_message("(coffee) -t")
63
+ send_message("coffee -t")
57
64
  expect(replies.last).to start_with("Default coffee:")
58
65
  end
59
66
 
60
67
  it 'buys the coffees and clears the queue' do
61
- send_message("(coffee) +")
62
- send_message("(coffee) -b")
63
- expect(replies.last).to start_with("Cleared all (coffee) orders")
64
- send_message("(coffee)")
68
+ order_a_coffee('stu')
69
+ order_a_coffee('joel')
70
+ send_message("coffee -b")
71
+ expect(replies.last).to start_with("Cleared all orders")
72
+ send_message("coffee")
65
73
  expect(replies.last).to end_with("--")
74
+ expect(replies.select{|x| x == "Test User has bought you a coffee!"}.count).to eq(2)
66
75
  end
67
76
 
68
-
77
+ def order_a_coffee(user)
78
+ user = Lita::User.create(1,name: user)
79
+ send_message('coffee +', as: user)
80
+ end
81
+
82
+ def coffees_in_the_queue
83
+ send_message('coffee')
84
+ replies.reverse.slice(0,replies.reverse.index{|x| ( x =~ /^Current orders/ ) == 0}).count
85
+ end
86
+
87
+
69
88
 
70
89
 
71
90
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-coffee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Auld
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-20 00:00:00.000000000 Z
11
+ date: 2015-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita