mirror of
https://github.com/civsocit/olgram.git
synced 2023-07-22 01:29:12 +03:00
html support in /start message
This commit is contained in:
parent
4063f9f336
commit
944c5ce002
@ -335,7 +335,7 @@ async def start_text_received(message: types.Message, state: FSMContext):
|
|||||||
async with state.proxy() as proxy:
|
async with state.proxy() as proxy:
|
||||||
bot_id = proxy.get("bot_id")
|
bot_id = proxy.get("bot_id")
|
||||||
bot = await Bot.get_or_none(pk=bot_id)
|
bot = await Bot.get_or_none(pk=bot_id)
|
||||||
bot.start_text = message.text
|
bot.start_text = message.html_text
|
||||||
await bot.save()
|
await bot.save()
|
||||||
await send_bot_text_menu(bot, chat_id=message.chat.id)
|
await send_bot_text_menu(bot, chat_id=message.chat.id)
|
||||||
|
|
||||||
@ -345,7 +345,7 @@ async def second_text_received(message: types.Message, state: FSMContext):
|
|||||||
async with state.proxy() as proxy:
|
async with state.proxy() as proxy:
|
||||||
bot_id = proxy.get("bot_id")
|
bot_id = proxy.get("bot_id")
|
||||||
bot = await Bot.get_or_none(pk=bot_id)
|
bot = await Bot.get_or_none(pk=bot_id)
|
||||||
bot.second_text = message.text
|
bot.second_text = message.html_text
|
||||||
await bot.save()
|
await bot.save()
|
||||||
await send_bot_second_text_menu(bot, chat_id=message.chat.id)
|
await send_bot_second_text_menu(bot, chat_id=message.chat.id)
|
||||||
|
|
||||||
|
@ -26,6 +26,10 @@ async def upgrade_1():
|
|||||||
|
|
||||||
async def upgrade_2():
|
async def upgrade_2():
|
||||||
"""Отменяем малый TTL для старых сообщений"""
|
"""Отменяем малый TTL для старых сообщений"""
|
||||||
|
meta_info = await MetaInfo.first()
|
||||||
|
if meta_info.version != 1:
|
||||||
|
logging.info("skip")
|
||||||
|
return
|
||||||
|
|
||||||
con = await aioredis.create_connection(ServerSettings.redis_path())
|
con = await aioredis.create_connection(ServerSettings.redis_path())
|
||||||
client = aioredis.Redis(con)
|
client = aioredis.Redis(con)
|
||||||
@ -35,9 +39,35 @@ async def upgrade_2():
|
|||||||
if not key.startswith(b"thread"):
|
if not key.startswith(b"thread"):
|
||||||
await client.pexpire(key, ServerSettings.redis_timeout_ms())
|
await client.pexpire(key, ServerSettings.redis_timeout_ms())
|
||||||
|
|
||||||
|
meta_info.version = 2
|
||||||
|
await meta_info.save()
|
||||||
|
logging.info("done")
|
||||||
|
|
||||||
|
|
||||||
|
async def upgrade_3():
|
||||||
|
"""start_text и second_text должны быть валидными HTML"""
|
||||||
|
import html
|
||||||
|
|
||||||
|
meta_info = await MetaInfo.first()
|
||||||
|
if meta_info.version != 2:
|
||||||
|
logging.info("skip")
|
||||||
|
return
|
||||||
|
|
||||||
|
async with transactions.in_transaction():
|
||||||
|
bots = await Bot.all()
|
||||||
|
for bot in bots:
|
||||||
|
if bot.start_text:
|
||||||
|
bot.start_text = html.escape(bot.start_text)
|
||||||
|
if bot.second_text:
|
||||||
|
bot.second_text = html.escape(bot.second_text)
|
||||||
|
await bot.save(update_fields=["start_text", "second_text"])
|
||||||
|
meta_info.version = 3
|
||||||
|
await meta_info.save()
|
||||||
|
logging.info("done")
|
||||||
|
|
||||||
|
|
||||||
# Не забудь добавить миграцию в этот лист!
|
# Не забудь добавить миграцию в этот лист!
|
||||||
_migrations = [upgrade_1, upgrade_2]
|
_migrations = [upgrade_1, upgrade_2, upgrade_3]
|
||||||
|
|
||||||
|
|
||||||
async def migrate():
|
async def migrate():
|
||||||
|
@ -137,7 +137,7 @@ async def handle_user_message(message: types.Message, super_chat_id: int, bot):
|
|||||||
|
|
||||||
# И отправить пользователю специальный текст, если он указан
|
# И отправить пользователю специальный текст, если он указан
|
||||||
if bot.second_text:
|
if bot.second_text:
|
||||||
return SendMessage(chat_id=message.chat.id, text=bot.second_text)
|
return SendMessage(chat_id=message.chat.id, text=bot.second_text, parse_mode="HTML")
|
||||||
|
|
||||||
|
|
||||||
async def handle_operator_message(message: types.Message, super_chat_id: int, bot):
|
async def handle_operator_message(message: types.Message, super_chat_id: int, bot):
|
||||||
@ -200,7 +200,7 @@ async def message_handler(message: types.Message, *args, **kwargs):
|
|||||||
text = bot.start_text
|
text = bot.start_text
|
||||||
if bot.enable_olgram_text:
|
if bot.enable_olgram_text:
|
||||||
text += _(ServerSettings.append_text())
|
text += _(ServerSettings.append_text())
|
||||||
return SendMessage(chat_id=message.chat.id, text=text)
|
return SendMessage(chat_id=message.chat.id, text=text, parse_mode="HTML")
|
||||||
|
|
||||||
if message.text and message.text == "/security_policy":
|
if message.text and message.text == "/security_policy":
|
||||||
# На команду security_policy нужно ответить, не пересылая сообщение никуда
|
# На команду security_policy нужно ответить, не пересылая сообщение никуда
|
||||||
|
Loading…
Reference in New Issue
Block a user