flatten cyberlina config

This commit is contained in:
bakatrouble 2019-11-27 21:39:57 +03:00
parent e8fd26af2e
commit 9b48e60db9

View File

@ -17,13 +17,13 @@ from bots.models import TelegramBotModuleConfig
class CyberLinaBotModuleConfig(TelegramBotModuleConfig):
first_part = JSONField(default='{"items": []}')
second_part = JSONField(default='{"items": []}')
third_part = JSONField(default='{"items": []}')
emoji = JSONField(default='{"items": []}')
already_ran = JSONField(default='{"items": []}')
welcome_reactions = JSONField(default='{"items": []}')
inline_reactions = JSONField(default='{"items": []}')
first_part = JSONField(default='[]')
second_part = JSONField(default='[]')
third_part = JSONField(default='[]')
emoji = JSONField(default='[]')
already_ran = JSONField(default='[]')
welcome_reactions = JSONField(default='[]')
inline_reactions = JSONField(default='[]')
MODULE_NAME = 'Киберлиночка'
CUSTOM_WIDGETS = {
@ -42,8 +42,8 @@ class CyberLinaBotModuleConfig(TelegramBotModuleConfig):
CyberLinaUser.from_tg_obj(self, update.effective_chat, update.effective_user)
def goodmorning_handler(self, update: Update, ctx: CallbackContext):
if not all([self.first_part['items'], self.second_part['items'],
self.third_part['items'], self.emoji['items']]):
if not all([self.first_part, self.second_part,
self.third_part, self.emoji]):
return update.effective_message.reply_text('Я не настроена :c')
seed(os.urandom(128))
self.message_handler(update, ctx)
@ -53,7 +53,7 @@ class CyberLinaBotModuleConfig(TelegramBotModuleConfig):
humanize.i18n.activate('ru_RU')
time_left = make_aware(datetime.combine(chat.last_run + timedelta(1), time(6, 0))) - now()
return update.effective_message.reply_text(
choice(self.already_ran['items']).format(
choice(self.already_ran).format(
name=chat.last_choice.name,
time=humanize.naturaldelta(time_left)
)
@ -69,11 +69,11 @@ class CyberLinaBotModuleConfig(TelegramBotModuleConfig):
except BadRequest:
user.delete()
msg = '{}, {}! {}, {} {}'.format(
choice(self.first_part['items']),
choice(self.second_part['items']),
choice(self.first_part),
choice(self.second_part),
mention_html(user.user_id, user.name),
choice(self.third_part['items']),
choice(self.emoji['items']),
choice(self.third_part),
choice(self.emoji),
)
update.effective_chat.send_message(msg, parse_mode='html')
chat.last_run = localdate()
@ -88,7 +88,7 @@ class CyberLinaBotModuleConfig(TelegramBotModuleConfig):
InlineQueryResultArticle(
id=uuid4(),
title='Не нажимай >_<',
input_message_content=InputTextMessageContent(choice(self.inline_reactions['items']))
input_message_content=InputTextMessageContent(choice(self.inline_reactions))
)
]
update.inline_query.answer(results, cache_time=0)