lita-onewheel-snowcrash 0.0.0 → 1.0.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a843e12d5988db8f669474e9472c046551e1c76f
|
4
|
+
data.tar.gz: df8d276c7f63dd53136f5fea406f236b2823bb84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b90cc30865e5d92ee5d8ecc497da8c4296efac515b19305c36bfcda8385139675fd7edce01ec12704949a110be4a45dc17edad28d91e38ab2b7110541393396
|
7
|
+
data.tar.gz: 79dbfc7669e78f15f8700d6ce18f416cf902f16c4014c800d45cfd0e8cb0b3616346fb97e768ef40b796bb9c213c8f6687ce29aca3bb5ae6cf71adeb324fb5c7
|
@@ -4,26 +4,50 @@ module Lita
|
|
4
4
|
module Handlers
|
5
5
|
class OnewheelSnowcrash < Handler
|
6
6
|
route /^snowcrash$/i,
|
7
|
-
:
|
7
|
+
:generate_random_sentence,
|
8
8
|
command: true
|
9
9
|
route /^snowcrash (\d+)$/i,
|
10
10
|
:generate_by_number,
|
11
11
|
command: true
|
12
|
+
route /^snowcrashwords$/i,
|
13
|
+
:generate_random_words,
|
14
|
+
command: true
|
15
|
+
route /^snowcrashwords (\d+)$/i,
|
16
|
+
:generate_words_by_number,
|
17
|
+
command: true
|
12
18
|
|
13
|
-
def
|
14
|
-
response.reply
|
19
|
+
def generate_random_sentence(response)
|
20
|
+
response.reply return_sentence_chain(1)
|
15
21
|
end
|
16
22
|
|
17
23
|
def generate_by_number(response)
|
18
|
-
response.reply
|
24
|
+
response.reply return_sentence_chain(response.matches[0][0])
|
25
|
+
end
|
26
|
+
|
27
|
+
def generate_random_words(response)
|
28
|
+
response.reply return_word_chain(Random::rand(20))
|
29
|
+
end
|
30
|
+
|
31
|
+
def generate_words_by_number(response)
|
32
|
+
response.reply return_word_chain(response.matches[0][0])
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_markov
|
36
|
+
MarkyMarkov::Dictionary.new('dict/snowcrash')
|
19
37
|
end
|
20
38
|
|
21
|
-
def
|
22
|
-
|
23
|
-
markov =
|
39
|
+
def return_word_chain(number)
|
40
|
+
Lita.logger.info "Generating #{number} words."
|
41
|
+
markov = get_markov # Saves/opens dictionary.mmd
|
24
42
|
markov.generate_n_words(number.to_i)
|
25
43
|
end
|
26
44
|
|
45
|
+
def return_sentence_chain(number)
|
46
|
+
Lita.logger.info "Generating #{number} sentences."
|
47
|
+
markov = get_markov # Saves/opens dictionary.mmd
|
48
|
+
markov.generate_n_sentences(number.to_i)
|
49
|
+
end
|
50
|
+
|
27
51
|
Lita.register_handler(self)
|
28
52
|
end
|
29
53
|
end
|
@@ -2,7 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Lita::Handlers::OnewheelSnowcrash, lita_handler: true do
|
4
4
|
it { is_expected.to route_command('snowcrash') }
|
5
|
-
it { is_expected.to route_command('snowcrash
|
5
|
+
it { is_expected.to route_command('snowcrash 2') }
|
6
|
+
it { is_expected.to route_command('snowcrashwords') }
|
7
|
+
it { is_expected.to route_command('snowcrashwords 22') }
|
6
8
|
|
7
9
|
it 'will generate a random-len chain' do
|
8
10
|
send_command 'snowcrash'
|
@@ -10,8 +12,19 @@ describe Lita::Handlers::OnewheelSnowcrash, lita_handler: true do
|
|
10
12
|
end
|
11
13
|
|
12
14
|
it 'will generate a six-word chain' do
|
13
|
-
send_command '
|
15
|
+
send_command 'snowcrashwords 6'
|
14
16
|
expect(replies.last).not_to be nil
|
15
17
|
expect(replies.last.split(' ').count).to be(6)
|
16
18
|
end
|
19
|
+
|
20
|
+
it 'will generate a sentence chain' do
|
21
|
+
send_command 'snowcrash'
|
22
|
+
expect(replies.last).not_to be nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'will generate a two-sentence chain' do
|
26
|
+
send_command 'snowcrash 2'
|
27
|
+
expect(replies.last).not_to be nil
|
28
|
+
expect(replies.last.split('.').count).to be(2)
|
29
|
+
end
|
17
30
|
end
|