mirror of
https://github.com/house-of-vanity/conf_bot.git
synced 2025-07-06 14:24:08 +00:00
Improve markov chain text generator.
This commit is contained in:
11
database.py
11
database.py
@ -167,14 +167,17 @@ class DataBase:
|
|||||||
|
|
||||||
def get_random_message(self, conf_id=None, count=1):
|
def get_random_message(self, conf_id=None, count=1):
|
||||||
if not conf_id:
|
if not conf_id:
|
||||||
print('get random message from all DB')
|
print('get random message from all DB, count %s' % count)
|
||||||
sql = "SELECT text FROM xxx_message ORDER BY RANDOM() LIMIT %s" % count
|
sql = "SELECT text FROM xxx_message ORDER BY RANDOM() LIMIT %s" % count
|
||||||
else:
|
else:
|
||||||
print('get random message from %s ' % conf_id)
|
print('get random message from %s, count: %s' % (conf_id, count))
|
||||||
sql = """SELECT x.text FROM xxx_message x LEFT JOIN relations r ON r.msg_id == x.id
|
sql = """SELECT x.text FROM xxx_message x LEFT JOIN relations r ON r.msg_id == x.id
|
||||||
WHERE r.conf_id = '%s' ORDER BY RANDOM() DESC LIMIT 1""" % conf_id
|
WHERE r.conf_id = '%s' ORDER BY RANDOM() DESC LIMIT %s""" % (conf_id, count)
|
||||||
result = self.execute(sql)
|
result = self.execute(sql)
|
||||||
return(result[0][0])
|
messages = list()
|
||||||
|
for msg in result:
|
||||||
|
messages.append(msg[0])
|
||||||
|
return(messages)
|
||||||
|
|
||||||
def here(self, user_id, conf_id):
|
def here(self, user_id, conf_id):
|
||||||
sql = """
|
sql = """
|
||||||
|
@ -188,7 +188,6 @@ class MessageWorker:
|
|||||||
else:
|
else:
|
||||||
chat_title = msg['message']['chat']['title']
|
chat_title = msg['message']['chat']['title']
|
||||||
self.db.add_conf(conf_id, chat_title)
|
self.db.add_conf(conf_id, chat_title)
|
||||||
rand_messages = list()
|
|
||||||
max_sen = 100
|
max_sen = 100
|
||||||
try:
|
try:
|
||||||
count = int(msg['message']['text'][8:])
|
count = int(msg['message']['text'][8:])
|
||||||
@ -201,9 +200,10 @@ class MessageWorker:
|
|||||||
except:
|
except:
|
||||||
use_all = False
|
use_all = False
|
||||||
if use_all:
|
if use_all:
|
||||||
rand_messages.append(self.db.get_random_message(count=count))
|
rand_messages = self.db.get_random_message(count=count)
|
||||||
else:
|
else:
|
||||||
rand_messages.append(self.db.get_random_message(conf_id, count=count))
|
rand_messages = self.db.get_random_message(conf_id, count=count)
|
||||||
|
print(count, rand_messages)
|
||||||
rand_text = " ".join(rand_messages)
|
rand_text = " ".join(rand_messages)
|
||||||
gen_text = get(rand_text)
|
gen_text = get(rand_text)
|
||||||
try:
|
try:
|
||||||
|
Reference in New Issue
Block a user