From ff28f5cea51978510a64cf3e5d3793040ec13c00 Mon Sep 17 00:00:00 2001 From: mihalin Date: Sat, 9 Apr 2022 05:42:52 +0300 Subject: [PATCH] =?UTF-8?q?"=D0=AD=D1=82=D0=BE=D1=82=20=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=20=D1=81=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BC=D0=BE=D1=89=D1=8C=D1=8E...."=20=D0=B2=D0=BE=D0=B7=D0=BC?= =?UTF-8?q?=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=B2=D1=8B=D0=BA?= =?UTF-8?q?=D0=BB=D1=8E=D1=87=D0=B0=D1=82=D1=8C=20=D0=B2=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=BC=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- olgram/commands/bot_actions.py | 6 ++++++ olgram/commands/menu.py | 13 +++++++++++++ .../migrations/models/13_20220409051838_update.sql | 4 ++++ olgram/models/models.py | 5 +++++ server/custom.py | 6 ++++-- 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 olgram/migrations/models/13_20220409051838_update.sql diff --git a/olgram/commands/bot_actions.py b/olgram/commands/bot_actions.py index d7ad67a..ec20f93 100644 --- a/olgram/commands/bot_actions.py +++ b/olgram/commands/bot_actions.py @@ -80,3 +80,9 @@ async def threads(bot: Bot, call: types.CallbackQuery): async def additional_info(bot: Bot, call: types.CallbackQuery): bot.enable_additional_info = not bot.enable_additional_info await bot.save(update_fields=["enable_additional_info"]) + + +async def olgram_text(bot: Bot, call: types.CallbackQuery): + if await bot.is_promo(): + bot.enable_olgram_text = not bot.enable_olgram_text + await bot.save(update_fields=["enable_olgram_text"]) diff --git a/olgram/commands/menu.py b/olgram/commands/menu.py index d84b3ab..3a76fc2 100644 --- a/olgram/commands/menu.py +++ b/olgram/commands/menu.py @@ -162,6 +162,14 @@ async def send_bot_settings_menu(bot: Bot, call: types.CallbackQuery): callback_data=menu_callback.new(level=3, bot_id=bot.id, operation="additional_info", chat=empty)) ) + is_promo = await bot.is_promo() + if is_promo: + keyboard.insert( + types.InlineKeyboardButton(text=_("Olgram подпись"), + callback_data=menu_callback.new(level=3, bot_id=bot.id, operation="olgram_text", + chat=empty)) + ) + keyboard.insert( types.InlineKeyboardButton(text=_("<< Назад"), callback_data=menu_callback.new(level=1, bot_id=bot.id, operation=empty, @@ -174,6 +182,11 @@ async def send_bot_settings_menu(bot: Bot, call: types.CallbackQuery): Потоки сообщений: {0} Данные пользователя: {1} """)).format(thread_turn, info_turn) + + if is_promo: + olgram_turn = _("включена") if bot.enable_olgram_text else _("выключена") + text += _("Olgram подпись: {0}").format(olgram_turn) + await edit_or_create(call, text, reply_markup=keyboard, parse_mode="HTML") diff --git a/olgram/migrations/models/13_20220409051838_update.sql b/olgram/migrations/models/13_20220409051838_update.sql new file mode 100644 index 0000000..cdfd36a --- /dev/null +++ b/olgram/migrations/models/13_20220409051838_update.sql @@ -0,0 +1,4 @@ +-- upgrade -- +ALTER TABLE "bot" ADD "enable_olgram_text" BOOL NOT NULL DEFAULT True; +-- downgrade -- +ALTER TABLE "bot" DROP COLUMN "enable_olgram_text"; diff --git a/olgram/models/models.py b/olgram/models/models.py index dc529c7..254c76b 100644 --- a/olgram/models/models.py +++ b/olgram/models/models.py @@ -44,6 +44,7 @@ class Bot(Model): enable_threads = fields.BooleanField(default=False) enable_additional_info = fields.BooleanField(default=False) + enable_olgram_text = fields.BooleanField(default=True) def decrypted_token(self): cryptor = DatabaseSettings.cryptor() @@ -60,6 +61,10 @@ class Bot(Model): return group_chat.chat_id return (await self.owner).telegram_id + async def is_promo(self): + owner = await self.fetch_related("owner") + return await owner.is_promo() + class Meta: table = 'bot' diff --git a/server/custom.py b/server/custom.py index b2cc2a8..b307e3f 100644 --- a/server/custom.py +++ b/server/custom.py @@ -171,8 +171,10 @@ async def message_handler(message: types.Message, *args, **kwargs): if message.text and message.text == "/start": # На команду start нужно ответить, не пересылая сообщение никуда - return SendMessage(chat_id=message.chat.id, - text=bot.start_text + _(ServerSettings.append_text())) + text = bot.start_text + if bot.enable_olgram_text: + text += _(ServerSettings.append_text()) + return SendMessage(chat_id=message.chat.id, text=text) if message.text and message.text == "/security_policy": # На команду security_policy нужно ответить, не пересылая сообщение никуда