From d62f4986d2b76ef6f0c07eed4e769c88a93b1052 Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Wed, 27 Nov 2019 23:31:09 +0300 Subject: [PATCH] generate markovify instance just once --- bots/modules/cyberlina.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bots/modules/cyberlina.py b/bots/modules/cyberlina.py index c55a06a..70a8a11 100644 --- a/bots/modules/cyberlina.py +++ b/bots/modules/cyberlina.py @@ -37,9 +37,15 @@ class CyberLinaBotModuleConfig(TelegramBotModuleConfig): 'already_ran': JSONEditor(), 'welcome_reactions': JSONEditor(), 'inline_reactions': JSONEditor(), - '_mtg_data': JSONEditor(), } + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + try: + self.markovify = markovify.Text.from_dict(self._mtg_data) + except: + pass + def message_handler(self, update: Update, ctx: CallbackContext): if not update.effective_chat or not update.effective_user: return @@ -87,7 +93,6 @@ class CyberLinaBotModuleConfig(TelegramBotModuleConfig): def inline_query_handler(self, update: Update, ctx: CallbackContext): if not self.inline_reactions: return - mtg = markovify.Text.from_dict(self._mtg_data) seed(os.urandom(128)) results = [ InlineQueryResultArticle( @@ -98,7 +103,7 @@ class CyberLinaBotModuleConfig(TelegramBotModuleConfig): InlineQueryResultArticle( id=uuid4(), title='ФлаБеПроЛейка', - input_message_content=InputTextMessageContent(mtg.make_sentence(tries=100)) + input_message_content=InputTextMessageContent(self.markovify.make_sentence(tries=100)) ), ] update.inline_query.answer(results, cache_time=0)