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 нужно ответить, не пересылая сообщение никуда