mirror of
https://github.com/MrDetonia/Maki.git
synced 2024-11-22 11:54:16 -05:00
v0.17.5 markovs back to 3 word chains, respond to .markov Maki
This commit is contained in:
parent
86f54bcbcb
commit
8c4b5cf0e9
5
bot.py
5
bot.py
@ -31,7 +31,7 @@ from secret import token, lfmkey
|
|||||||
# CONFIGURATION
|
# CONFIGURATION
|
||||||
|
|
||||||
# bot version
|
# bot version
|
||||||
version = "v0.17.4"
|
version = "v0.17.5"
|
||||||
|
|
||||||
# text shown by .help command
|
# text shown by .help command
|
||||||
helptext = """I am a Discord bot written in Python
|
helptext = """I am a Discord bot written in Python
|
||||||
@ -240,6 +240,9 @@ def on_message(message):
|
|||||||
tmp = message.content[8:]
|
tmp = message.content[8:]
|
||||||
target = ''
|
target = ''
|
||||||
|
|
||||||
|
if tmp == 'Maki':
|
||||||
|
response = "My markovs always say the same thing."
|
||||||
|
else:
|
||||||
# if no user provided, markov the author
|
# if no user provided, markov the author
|
||||||
if tmp == '':
|
if tmp == '':
|
||||||
target = message.server.id + '-' + message.author.id
|
target = message.server.id + '-' + message.author.id
|
||||||
|
19
markov.py
19
markov.py
@ -22,23 +22,30 @@ class Markov(object):
|
|||||||
for i in range(len(self.words) - 1):
|
for i in range(len(self.words) - 1):
|
||||||
yield (self.words[i], self.words[i+1])
|
yield (self.words[i], self.words[i+1])
|
||||||
|
|
||||||
|
def triples(self):
|
||||||
|
if len(self.words) < 3:
|
||||||
|
return
|
||||||
|
|
||||||
|
for i in range(len(self.words) - 2):
|
||||||
|
yield (self.words[i], self.words[i+1], self.words[i+2])
|
||||||
|
|
||||||
def database(self):
|
def database(self):
|
||||||
for w1, w2 in self.doubles():
|
for w1, w2, w3 in self.triples():
|
||||||
key = w1
|
key = (w1, w2)
|
||||||
if key in self.cache:
|
if key in self.cache:
|
||||||
self.cache[key].append(w2)
|
self.cache[key].append(w3)
|
||||||
else:
|
else:
|
||||||
self.cache[key] = [w2]
|
self.cache[key] = [w3]
|
||||||
|
|
||||||
def generate_text(self, size=25):
|
def generate_text(self, size=25):
|
||||||
seed = random.randint(0, self.word_size - 2)
|
seed = random.randint(0, self.word_size - 3)
|
||||||
seed_word, next_word = self.words[seed], self.words[seed+1]
|
seed_word, next_word = self.words[seed], self.words[seed+1]
|
||||||
w1, w2 = seed_word, next_word
|
w1, w2 = seed_word, next_word
|
||||||
gen_words = []
|
gen_words = []
|
||||||
for i in range(size):
|
for i in range(size):
|
||||||
gen_words.append(w1)
|
gen_words.append(w1)
|
||||||
try:
|
try:
|
||||||
w1, w2 = w2, random.choice(self.cache[w2])
|
w1, w2 = w2, random.choice(self.cache[(w1,w2)])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
break
|
break
|
||||||
gen_words.append(w1)
|
gen_words.append(w1)
|
||||||
|
Loading…
Reference in New Issue
Block a user