lita-markov 1.0.1 → 1.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: 01b2f398d9caec20fbf37702c662684da7146cdc
4
- data.tar.gz: a748f843fd1d732e87f54172a86c4c6c591cb4fb
3
+ metadata.gz: 7b5c291ff7b19be493ce427ed3ef9d49eac2ba4d
4
+ data.tar.gz: bec9e862f464c5ed4daeeea15adf946bb22335b7
5
5
  SHA512:
6
- metadata.gz: 9a0098f7c3791ef925b3c4ca91a9ee27dd241f4dfbae1b98f9c594fb7004a1ef41bb25a44980ba7b1d3fc1cfcb65919df0f2306e9eda5ca8faf98c6b8a3d64c8
7
- data.tar.gz: aa74aeb55df9ffa5c5ae47b3d009a49ac779778d08071758967e77c70e201154e6b61afbf2e8e7999f1dbefe0fc942fc4d86cae477e884f370aeb1e1d7386691
6
+ metadata.gz: 5f82af9abdb8fcd6c6413e6f384cf884034d34b4be5a63a6e6f28357d9465a02b81a215447ea16196730aca584ab7bb229b4e8de03bcdcc4615ab9d94c9ab722
7
+ data.tar.gz: b7bc2ad646600648117a2013986d56a02ad803cba950e8e81167f429f688742c5fe08625ae53fa294e507c041f9bbb09500a30d9c8ad2f144bf423fd4f0d6ca8
@@ -69,8 +69,10 @@ class Lita::Handlers::Markov
69
69
  end
70
70
  end
71
71
 
72
- def random_capitalized_word
73
- states = @db[:dictionary].map(:current_state)
72
+ def random_capitalized_word(user)
73
+ states = @db[:dictionary]
74
+ .where(user: user)
75
+ .map(:current_state)
74
76
 
75
77
  capitalized_states = states.select do |state|
76
78
  /^[A-Z]/ =~ state
@@ -87,9 +89,10 @@ class Lita::Handlers::Markov
87
89
  return state.split(' ').first
88
90
  end
89
91
 
90
- def random_second_word(first_word)
92
+ def random_second_word(user, first_word)
91
93
  states = @db[:dictionary]
92
94
  .where(Sequel.like(:current_state, first_word+'%'))
95
+ .where(user: user)
93
96
  .map(:current_state)
94
97
 
95
98
  state = states.sample
@@ -97,7 +100,7 @@ class Lita::Handlers::Markov
97
100
  end
98
101
 
99
102
  def is_punctuation?(string)
100
- PUNCTUATION.any? { |p| string.end_with? p }
103
+ PUNCTUATION.any? { |p| string == p }
101
104
  end
102
105
 
103
106
  def get_next_state(user, current_state)
@@ -114,10 +117,11 @@ class Lita::Handlers::Markov
114
117
  end
115
118
 
116
119
  def generate_sentence_for(user, length = 30)
117
- first_word = random_capitalized_word
118
- second_word = random_second_word first_word
120
+ first_word = random_capitalized_word user
121
+ second_word = random_second_word user, first_word
119
122
 
120
123
  sentence = [first_word, second_word]
124
+ ended_with_punctuation = false
121
125
 
122
126
  while sentence.length < length
123
127
  current_state = sentence.slice(sentence.length - @depth, @depth).join ' '
@@ -129,10 +133,17 @@ class Lita::Handlers::Markov
129
133
 
130
134
  sentence << next_state
131
135
 
132
- break if is_punctuation? next_state
136
+ if is_punctuation? next_state
137
+ ended_with_punctuation = true
138
+ break
139
+ end
133
140
  end
134
141
 
135
- sentence.slice(0..-2).join(' ') + sentence.last
142
+ chain = sentence.slice(0..-2).join(' ')
143
+ chain << ' ' unless ended_with_punctuation
144
+ chain << sentence.last
145
+
146
+ chain
136
147
  end
137
148
 
138
149
  def separate_string string
@@ -31,10 +31,15 @@ module Lita::Handlers
31
31
 
32
32
  def generate(chat)
33
33
  name = chat.matches[0][0].strip
34
- id = Lita::User.fuzzy_find(name).id
34
+ user = Lita::User.fuzzy_find name
35
+
36
+ if user.nil?
37
+ chat.reply "Couldn't find the user #{name}. :("
38
+ return
39
+ end
35
40
 
36
41
  begin
37
- sentence = engine.generate_sentence_for id
42
+ sentence = engine.generate_sentence_for user.id
38
43
 
39
44
  chat.reply sentence
40
45
  rescue Engine::EmptyDictionaryError
data/lita-markov.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-markov"
3
- spec.version = "1.0.1"
3
+ spec.version = "1.0.2"
4
4
  spec.authors = ["Dirk Gadsden"]
5
5
  spec.email = ["dirk@dirk.to"]
6
6
  spec.description = "Markov chains for Lita."
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-markov
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dirk Gadsden