"Этот бот создан с помощью...." возможность выключать в промо

This commit is contained in:
mihalin 2022-04-09 05:42:52 +03:00
parent 7e016a0eb2
commit ff28f5cea5
5 changed files with 32 additions and 2 deletions

View File

@ -80,3 +80,9 @@ async def threads(bot: Bot, call: types.CallbackQuery):
async def additional_info(bot: Bot, call: types.CallbackQuery): async def additional_info(bot: Bot, call: types.CallbackQuery):
bot.enable_additional_info = not bot.enable_additional_info bot.enable_additional_info = not bot.enable_additional_info
await bot.save(update_fields=["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"])

View File

@ -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", callback_data=menu_callback.new(level=3, bot_id=bot.id, operation="additional_info",
chat=empty)) 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( keyboard.insert(
types.InlineKeyboardButton(text=_("<< Назад"), types.InlineKeyboardButton(text=_("<< Назад"),
callback_data=menu_callback.new(level=1, bot_id=bot.id, operation=empty, 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):
<a href="https://olgram.readthedocs.io/ru/latest/options.html#threads">Потоки сообщений</a>: <b>{0}</b> <a href="https://olgram.readthedocs.io/ru/latest/options.html#threads">Потоки сообщений</a>: <b>{0}</b>
<a href="https://olgram.readthedocs.io/ru/latest/options.html#user-info">Данные пользователя</a>: <b>{1}</b> <a href="https://olgram.readthedocs.io/ru/latest/options.html#user-info">Данные пользователя</a>: <b>{1}</b>
""")).format(thread_turn, info_turn) """)).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") await edit_or_create(call, text, reply_markup=keyboard, parse_mode="HTML")

View File

@ -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";

View File

@ -44,6 +44,7 @@ class Bot(Model):
enable_threads = fields.BooleanField(default=False) enable_threads = fields.BooleanField(default=False)
enable_additional_info = fields.BooleanField(default=False) enable_additional_info = fields.BooleanField(default=False)
enable_olgram_text = fields.BooleanField(default=True)
def decrypted_token(self): def decrypted_token(self):
cryptor = DatabaseSettings.cryptor() cryptor = DatabaseSettings.cryptor()
@ -60,6 +61,10 @@ class Bot(Model):
return group_chat.chat_id return group_chat.chat_id
return (await self.owner).telegram_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: class Meta:
table = 'bot' table = 'bot'

View File

@ -171,8 +171,10 @@ async def message_handler(message: types.Message, *args, **kwargs):
if message.text and message.text == "/start": if message.text and message.text == "/start":
# На команду start нужно ответить, не пересылая сообщение никуда # На команду start нужно ответить, не пересылая сообщение никуда
return SendMessage(chat_id=message.chat.id, text = bot.start_text
text=bot.start_text + _(ServerSettings.append_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": if message.text and message.text == "/security_policy":
# На команду security_policy нужно ответить, не пересылая сообщение никуда # На команду security_policy нужно ответить, не пересылая сообщение никуда