lita-poetry 0.1.0 → 0.2.0

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: 0ba908fe51218c4defcb94d5725dbb03fd613010
4
- data.tar.gz: f2050fa3f1c2d0187febf20329f1bc5e2b1e986f
3
+ metadata.gz: ba0c967cbd2a549b896a558df29a5242e697ad19
4
+ data.tar.gz: c988175dc89d058bf0f843060a5fbe6e311cf10c
5
5
  SHA512:
6
- metadata.gz: 503ded515d18be493e8b41b136c4661f5946f61798c552c899ad02b140dbda95eaedf68ea5b6f972a4aa1d36271941a7bf426b3b65b8ceaf8fbb30eda7b8e0cd
7
- data.tar.gz: 1e17bf9394dc71f16dcc5a723db47c3a3b6d181e3a8e2b6a95dfa95a31a6272139b145a19f2013c1b1d10a62395cce91644bb1450e53728ab318b80c0c38ac3e
6
+ metadata.gz: eec945eb943c48fa0f4cf928798e4bdf048158b6422874ffbfe965c76dfa1bbba8913bd71467013fd85f028f43635c98cd145c3feda4d32abd0b249c4aba535a
7
+ data.tar.gz: f2b0a93ce6eab4fe316b1d0b32fe1af17e9397e4b27c1f5de6882b2def4b6b6d99c2f25df0019a62412470c0e3fbb733f42f4fe24918c0f76527a2c675b7be31
data/README.md CHANGED
@@ -31,6 +31,17 @@ Lita.configure do |config|
31
31
  end
32
32
  ```
33
33
 
34
+ ##Usage
35
+ Three commands are available: ```haiku last```, ```haiku total```, and ```haiku get [integer]```
36
+ ```You > Litabot: haiku last
37
+ Litabot > haiku are easy; But some times they dont make sense; Refrigerator
38
+ You > Litabot: haiku total
39
+ Litabot > 5
40
+ You > Litabot: haiku get 3
41
+ Litabot > In the ponds cool depths; the happy frog plays in spring; his life a slow game
42
+ ```
43
+
44
+
34
45
  ## License
35
46
 
36
47
  [MIT](http://opensource.org/licenses/MIT)
@@ -11,6 +11,19 @@ module Lita
11
11
  config :strict_mode, types: [TrueClass, FalseClass], default: false
12
12
 
13
13
  route(/.+/, :process)
14
+
15
+ route %r{^haiku last}i, :get_last_haiku, help: {
16
+ "litabot: haiku last" => "Retreives last saved Haiku"
17
+ }
18
+
19
+ route %r{^haiku total}i, :get_total_haikus, help: {
20
+ "litabot: haiku total" => "Retreives total number of saved haikus"
21
+ }
22
+
23
+ route %r{^(haiku get) (\d)}i, :get_specific_haiku, help: {
24
+ "litabot: haiku get 5" => "Retreives the 5th saved haiku"
25
+ }
26
+
14
27
  on(:loaded, :populate)
15
28
 
16
29
 
@@ -20,7 +33,8 @@ module Lita
20
33
  self.class.lock.synchronize do
21
34
  three = {
22
35
  'id' => request.message.user.id,
23
- 'count' => process_sentence(request.message.body)
36
+ 'count' => process_sentence(request.message.body),
37
+ 'text' => request.message.body
24
38
  }
25
39
 
26
40
  redis.lpop('data')
@@ -28,7 +42,6 @@ module Lita
28
42
  redis.rpush('data', MultiJson.dump(three))
29
43
  end
30
44
 
31
-
32
45
  return if one.nil? || two.nil?
33
46
 
34
47
  one = MultiJson.load(one)
@@ -39,10 +52,15 @@ module Lita
39
52
  end
40
53
 
41
54
  if one['count'] == 5 && two['count'] == 7 && three['count'] == 5
55
+ save_last_haiku(one, two, three)
42
56
  request.reply('Garth, that was a haiku!')
43
57
  end
44
58
  end
45
59
 
60
+ def save_last_haiku(one, two, three)
61
+ redis.rpush('saved_haikus', one['text'] + "; " + two['text'] + "; " + three['text'])
62
+ end
63
+
46
64
  def process_sentence(sentence)
47
65
  sentence.gsub!("'", "")
48
66
  sentence.gsub!(",","")
@@ -53,25 +71,45 @@ module Lita
53
71
 
54
72
 
55
73
  def count_syllables(word)
56
-
57
74
  word.downcase!
58
75
  return 1 if word.length <= 3
59
76
  word.sub!(/(?:[^laeiouy]es|ed|[^laeiouy]e)$/, '')
60
77
  word.sub!(/^y/, '')
61
78
  word.scan(/[aeiouy]{1,2}/).size
62
-
63
79
  end
64
80
 
65
81
  def populate payload
66
-
67
82
  self.class.lock.synchronize do
68
83
  length = redis.llen('data')
69
-
70
84
  (3 - length).times do
71
85
  redis.rpush('data', MultiJson.dump({'id' => 0, 'count' => 0 }))
72
86
  end
73
87
  end
74
88
  end
89
+
90
+ def get_last_haiku(request)
91
+ number = redis.llen('saved_haikus')
92
+ if number == 0
93
+ request.reply('Rain falls softly now; it is a sad day when you; have no saved haikus')
94
+ else
95
+ request.reply(redis.lrange('saved_haikus', number - 1, 1).first)
96
+ end
97
+ end
98
+
99
+ def get_specific_haiku(request)
100
+ which, extra = request.matches.first.last.to_i, 0
101
+ if which == redis.llen('saved_haikus')
102
+ extra += 1
103
+ elsif which > redis.llen('saved_haikus')
104
+ return
105
+ end
106
+ request.reply(redis.lrange('saved_haikus', which - 1, 1 + extra).first)
107
+ end
108
+
109
+ def get_total_haikus(request)
110
+ request.reply("#{redis.llen('saved_haikus')} haikus total")
111
+ end
112
+
75
113
  end
76
114
  Lita.register_handler(Poetry)
77
115
  end
data/lita-poetry.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-poetry"
3
- spec.version = "0.1.0"
3
+ spec.version = "0.2.0"
4
4
  spec.authors = ["Chris Woodrich"]
5
5
  spec.email = ["cwoodrich@gmail.com"]
6
6
  spec.description = "A Haiku detector for Lita"
@@ -1,22 +1,24 @@
1
1
  require "spec_helper"
2
2
 
3
+
3
4
  describe Lita::Handlers::Poetry, lita_handler: true do
4
5
 
5
6
  it {is_expected.to route_event(:loaded).to(:populate)}
6
7
  it {is_expected.to route('a string').to(:process)}
8
+ it { is_expected.to route_command("haiku last").to(:get_last_haiku) }
9
+ it { is_expected.to route_command("haiku total").to(:get_total_haikus) }
10
+ it { is_expected.to route_command("haiku get 5").to(:get_specific_haiku) }
11
+
12
+
7
13
 
8
14
  before do
9
15
  registry.config.handlers.poetry.strict_mode = true;
10
16
  end
11
17
 
12
-
13
-
14
18
  describe '#process' do
15
19
  before {robot.trigger(:loaded)}
16
20
  it 'tells Garth or the poetic user that (s)he has written a Haiku' do
17
- send_message("dainty daffodil")
18
- send_message("your golden trumpet fanfares")
19
- send_message("the dawning of spring")
21
+ simple_haiku
20
22
  expect(replies.last).to eq('Garth, that was a haiku!')
21
23
  end
22
24
 
@@ -40,17 +42,7 @@ describe Lita::Handlers::Poetry, lita_handler: true do
40
42
  send_message("Haiku Hating Haiku Bros")
41
43
  send_message("Oh the irony.")
42
44
 
43
- send_message("To spread their evil")
44
- send_message("They hate haiku through Hiakus")
45
- send_message("Here is their worst deeds.")
46
-
47
- send_message("haiku are easy")
48
- send_message("But some times they dont make sense")
49
- send_message("Refrigerator")
50
-
51
- send_message("In the ponds cool depths")
52
- send_message("the happy frog plays in spring")
53
- send_message("his life, a slow game.")
45
+ three_good_ones
54
46
 
55
47
  send_message("Summer’s arid heat")
56
48
  send_message("the dry parched earth welcomes me")
@@ -96,11 +88,67 @@ describe Lita::Handlers::Poetry, lita_handler: true do
96
88
  send_message("Weighed nearly eight hundred tonnes")
97
89
  send_message("He loved his deer pie")
98
90
  expect(replies.last).to eq('Garth, that was a haiku!')
91
+ end
92
+ end
99
93
 
94
+ describe '#get_last_haiku' do
95
+ it "handles the situation where there are no saved haikus" do
96
+ send_command('haiku last')
97
+ expect(replies.last).to eq('Rain falls softly now; it is a sad day when you; have no saved haikus')
100
98
  end
101
99
 
100
+ it "retrieves the last saved haiku with semicolons between lines" do
101
+ simple_haiku
102
+ send_command('haiku last')
103
+ expect(replies.last).to eq("dainty daffodil" + "; " "your golden trumpet fanfares" + "; " + "the dawning of spring")
104
+ end
102
105
  end
103
106
 
107
+ describe '#get_total_haikus' do
108
+ it "returns the total number of saved haikus" do
109
+ 3.times { simple_haiku }
110
+ send_command('haiku total')
111
+ expect(replies.last).to eq("3 haikus total")
112
+ end
113
+ end
114
+
115
+ describe '#get_specific_haiku' do
116
+ it "gets a spefic haiku based on its index" do
117
+ three_good_ones
118
+ send_command('haiku get 2')
119
+ expect(replies.last).to eq("haiku are easy" + "; " + "But some times they dont make sense" + "; " "Refrigerator")
120
+
121
+ send_command('haiku get 3')
122
+ expect(replies.last).to eq("In the ponds cool depths" + "; " + "the happy frog plays in spring" + "; " "his life a slow game")
123
+ end
124
+
125
+ it "does nothing if the user selects a haiku that doesn not exist" do
126
+ three_good_ones
127
+ send_command('haiku get 9000')
128
+ expect(replies.size).to eq(3)
129
+ end
130
+ end
131
+
132
+ def three_good_ones
133
+ send_message("To spread their evil")
134
+ send_message("They hate haiku through Hiakus")
135
+ send_message("Here is their worst deeds.")
136
+
137
+ send_message("haiku are easy")
138
+ send_message("But some times they dont make sense")
139
+ send_message("Refrigerator")
140
+
141
+ send_message("In the ponds cool depths")
142
+ send_message("the happy frog plays in spring")
143
+ send_message("his life a slow game")
144
+ end
145
+
146
+ def simple_haiku
147
+ send_message("dainty daffodil")
148
+ send_message("your golden trumpet fanfares")
149
+ send_message("the dawning of spring")
150
+ end
104
151
 
105
152
 
106
153
  end
154
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-poetry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Woodrich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-12 00:00:00.000000000 Z
11
+ date: 2015-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita