'self.database' -> 'self.bot.database'
This commit is contained in:
parent
909ba10263
commit
f24f58ecd0
1 changed files with 8 additions and 8 deletions
|
@ -3,8 +3,8 @@ from src import ModuleManager, utils
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
def _on_load(self):
|
def _on_load(self):
|
||||||
if not self.database.has_table("markov"):
|
if not self.bot.database.has_table("markov"):
|
||||||
self.database.execute("""CREATE TABLE markov
|
self.bot.database.execute("""CREATE TABLE markov
|
||||||
(channel_id INTEGER, first_word TEXT, second_word TEXT,
|
(channel_id INTEGER, first_word TEXT, second_word TEXT,
|
||||||
third_word TEXT, frequency INT,
|
third_word TEXT, frequency INT,
|
||||||
FOREIGN KEY (channel_id) REFERENCES channels(channel_id),
|
FOREIGN KEY (channel_id) REFERENCES channels(channel_id),
|
||||||
|
@ -27,13 +27,13 @@ class Module(ModuleManager.BaseModule):
|
||||||
inserts.append([words[-1], None, None])
|
inserts.append([words[-1], None, None])
|
||||||
|
|
||||||
for insert in inserts:
|
for insert in inserts:
|
||||||
frequency = self.database.execute("""SELECT frequency
|
frequency = self.bot.database.execute("""SELECT frequency
|
||||||
FROM markov WHERE channel_id=? AND first_word=?
|
FROM markov WHERE channel_id=? AND first_word=?
|
||||||
AND second_word=? AND third_word=?""",
|
AND second_word=? AND third_word=?""",
|
||||||
[event["channel"].id]+insert)
|
[event["channel"].id]+insert)
|
||||||
frequency = (frequency or [0])[0]+1
|
frequency = (frequency or [0])[0]+1
|
||||||
|
|
||||||
self.database.execute(
|
self.bot.database.execute(
|
||||||
"INSERT OR REPLACE INTO markov VALUES (?, ?, ?, ?, ?)",
|
"INSERT OR REPLACE INTO markov VALUES (?, ?, ?, ?, ?)",
|
||||||
[event["channel"].id]+insert+[frequency])
|
[event["channel"].id]+insert+[frequency])
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
return random.choices(words, weights=frequencies, k=1)[0]
|
return random.choices(words, weights=frequencies, k=1)[0]
|
||||||
|
|
||||||
def generate(self, channel_id):
|
def generate(self, channel_id):
|
||||||
first_words = self.database.execute("""SELECT third_word, frequency
|
first_words = self.bot.database.execute("""SELECT third_word, frequency
|
||||||
FROM markov WHERE channel_id=? AND first_word IS NULL AND
|
FROM markov WHERE channel_id=? AND first_word IS NULL AND
|
||||||
second_word IS NULL AND third_word NOT NULL""",
|
second_word IS NULL AND third_word NOT NULL""",
|
||||||
[channel_id])
|
[channel_id])
|
||||||
|
@ -52,7 +52,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
return None
|
return None
|
||||||
first_word = self._choose(first_words)
|
first_word = self._choose(first_words)
|
||||||
|
|
||||||
second_words = self.database.execute("""SELECT third_word, frequency
|
second_words = self.bot.database.execute("""SELECT third_word, frequency
|
||||||
FROM markov WHERE channel_id=? AND first_word IS NULL AND
|
FROM markov WHERE channel_id=? AND first_word IS NULL AND
|
||||||
second_word=? AND third_word NOT NULL""",
|
second_word=? AND third_word NOT NULL""",
|
||||||
[channel_id, first_word])
|
[channel_id, first_word])
|
||||||
|
@ -63,8 +63,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
words = [first_word, second_word]
|
words = [first_word, second_word]
|
||||||
for i in range(30):
|
for i in range(30):
|
||||||
two_words = words[-2:]
|
two_words = words[-2:]
|
||||||
third_words = self.database.execute("""SELECT third_word, frequency
|
third_words = self.bot.database.execute("""SELECT third_word,
|
||||||
FROM markov WHERE channel_id=? AND first_word=? AND
|
frequency FROM markov WHERE channel_id=? AND first_word=? AND
|
||||||
second_word=?""", [channel_id]+two_words)
|
second_word=?""", [channel_id]+two_words)
|
||||||
|
|
||||||
third_word = self._choose(third_words)
|
third_word = self._choose(third_words)
|
||||||
|
|
Loading…
Reference in a new issue