lita-markov 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lita/handlers/markov/engine.rb +2 -3
- data/lib/lita/handlers/markov.rb +5 -9
- data/lita-markov.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01b2f398d9caec20fbf37702c662684da7146cdc
|
4
|
+
data.tar.gz: a748f843fd1d732e87f54172a86c4c6c591cb4fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a0098f7c3791ef925b3c4ca91a9ee27dd241f4dfbae1b98f9c594fb7004a1ef41bb25a44980ba7b1d3fc1cfcb65919df0f2306e9eda5ca8faf98c6b8a3d64c8
|
7
|
+
data.tar.gz: aa74aeb55df9ffa5c5ae47b3d009a49ac779778d08071758967e77c70e201154e6b61afbf2e8e7999f1dbefe0fc942fc4d86cae477e884f370aeb1e1d7386691
|
@@ -10,12 +10,11 @@ class Lita::Handlers::Markov
|
|
10
10
|
attr_accessor :handler
|
11
11
|
attr_reader :db
|
12
12
|
|
13
|
-
def initialize(
|
13
|
+
def initialize(database_url = nil)
|
14
14
|
@handler = handler
|
15
15
|
@depth = 2
|
16
16
|
|
17
|
-
database_url = DEFAULT_DATABASE_URL
|
18
|
-
database_url ||= handler.config.database_url if handler
|
17
|
+
database_url = database_url || DEFAULT_DATABASE_URL
|
19
18
|
|
20
19
|
@db = Sequel.connect database_url
|
21
20
|
|
data/lib/lita/handlers/markov.rb
CHANGED
@@ -5,9 +5,7 @@ require 'lita/handlers/markov/engine'
|
|
5
5
|
|
6
6
|
module Lita::Handlers
|
7
7
|
class Markov
|
8
|
-
|
9
|
-
|
10
|
-
config :database_url
|
8
|
+
config :database_url, type: String, required: true
|
11
9
|
|
12
10
|
route(/.+/, :ingest, command: false)
|
13
11
|
|
@@ -15,10 +13,8 @@ module Lita::Handlers
|
|
15
13
|
'markov USER' => 'Generate a markov chain from the given user.'
|
16
14
|
})
|
17
15
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
@engine = Engine.new self
|
16
|
+
def engine
|
17
|
+
@engine ||= Engine.new config.database_url
|
22
18
|
end
|
23
19
|
|
24
20
|
def ingest(chat)
|
@@ -30,7 +26,7 @@ module Lita::Handlers
|
|
30
26
|
# Get the mention name (ie. 'dirk') of the user
|
31
27
|
id = chat.user.id
|
32
28
|
|
33
|
-
|
29
|
+
engine.ingest id, message
|
34
30
|
end
|
35
31
|
|
36
32
|
def generate(chat)
|
@@ -38,7 +34,7 @@ module Lita::Handlers
|
|
38
34
|
id = Lita::User.fuzzy_find(name).id
|
39
35
|
|
40
36
|
begin
|
41
|
-
sentence =
|
37
|
+
sentence = engine.generate_sentence_for id
|
42
38
|
|
43
39
|
chat.reply sentence
|
44
40
|
rescue Engine::EmptyDictionaryError
|
data/lita-markov.gemspec
CHANGED