mirror of
https://github.com/civsocit/olgram.git
synced 2023-07-22 01:29:12 +03:00
enable and disable threads
This commit is contained in:
parent
64ba75e8cb
commit
715d516952
@ -69,3 +69,8 @@ async def select_chat(bot: Bot, call: types.CallbackQuery, chat: str):
|
|||||||
bot.group_chat = chat_obj
|
bot.group_chat = chat_obj
|
||||||
await bot.save()
|
await bot.save()
|
||||||
await call.answer(f"Выбран чат {chat_obj.name}")
|
await call.answer(f"Выбран чат {chat_obj.name}")
|
||||||
|
|
||||||
|
|
||||||
|
async def threads(bot: Bot, call: types.CallbackQuery):
|
||||||
|
bot.enable_threads = not bot.enable_threads
|
||||||
|
await bot.save(update_fields=["enable_threads"])
|
||||||
|
@ -116,6 +116,11 @@ async def send_bot_menu(bot: Bot, call: types.CallbackQuery):
|
|||||||
types.InlineKeyboardButton(text="<< Назад",
|
types.InlineKeyboardButton(text="<< Назад",
|
||||||
callback_data=menu_callback.new(level=0, bot_id=empty, operation=empty, chat=empty))
|
callback_data=menu_callback.new(level=0, bot_id=empty, operation=empty, chat=empty))
|
||||||
)
|
)
|
||||||
|
keyboard.insert(
|
||||||
|
types.InlineKeyboardButton(text="Опции",
|
||||||
|
callback_data=menu_callback.new(level=2, bot_id=bot.id, operation="settings",
|
||||||
|
chat=empty))
|
||||||
|
)
|
||||||
|
|
||||||
await edit_or_create(call, dedent(f"""
|
await edit_or_create(call, dedent(f"""
|
||||||
Управление ботом @{bot.name}.
|
Управление ботом @{bot.name}.
|
||||||
@ -143,6 +148,27 @@ async def send_bot_delete_menu(bot: Bot, call: types.CallbackQuery):
|
|||||||
"""), reply_markup=keyboard)
|
"""), reply_markup=keyboard)
|
||||||
|
|
||||||
|
|
||||||
|
async def send_bot_settings_menu(bot: Bot, call: types.CallbackQuery):
|
||||||
|
await call.answer()
|
||||||
|
keyboard = types.InlineKeyboardMarkup(row_width=1)
|
||||||
|
keyboard.insert(
|
||||||
|
types.InlineKeyboardButton(text="Потоки сообщений",
|
||||||
|
callback_data=menu_callback.new(level=3, bot_id=bot.id, operation="threads",
|
||||||
|
chat=empty))
|
||||||
|
)
|
||||||
|
keyboard.insert(
|
||||||
|
types.InlineKeyboardButton(text="<< Назад",
|
||||||
|
callback_data=menu_callback.new(level=1, bot_id=bot.id, operation=empty,
|
||||||
|
chat=empty))
|
||||||
|
)
|
||||||
|
|
||||||
|
thread_turn = "включены" if bot.enable_threads else "выключены"
|
||||||
|
text = dedent(f"""
|
||||||
|
<a href="https://olgram.readthedocs.io/ru/latest/threads.html">Потоки сообщений</a>: <b>{thread_turn}</b>
|
||||||
|
""")
|
||||||
|
await edit_or_create(call, text, reply_markup=keyboard, parse_mode="HTML")
|
||||||
|
|
||||||
|
|
||||||
async def send_bot_text_menu(bot: Bot, call: ty.Optional[types.CallbackQuery] = None, chat_id: ty.Optional[int] = None):
|
async def send_bot_text_menu(bot: Bot, call: ty.Optional[types.CallbackQuery] = None, chat_id: ty.Optional[int] = None):
|
||||||
if call:
|
if call:
|
||||||
await call.answer()
|
await call.answer()
|
||||||
@ -360,6 +386,8 @@ async def callback(call: types.CallbackQuery, callback_data: dict, state: FSMCon
|
|||||||
return await send_bot_delete_menu(bot, call)
|
return await send_bot_delete_menu(bot, call)
|
||||||
if operation == "stat":
|
if operation == "stat":
|
||||||
return await send_bot_statistic_menu(bot, call)
|
return await send_bot_statistic_menu(bot, call)
|
||||||
|
if operation == "settings":
|
||||||
|
return await send_bot_settings_menu(bot, call)
|
||||||
if operation == "text":
|
if operation == "text":
|
||||||
await state.set_state("wait_start_text")
|
await state.set_state("wait_start_text")
|
||||||
async with state.proxy() as proxy:
|
async with state.proxy() as proxy:
|
||||||
@ -371,6 +399,9 @@ async def callback(call: types.CallbackQuery, callback_data: dict, state: FSMCon
|
|||||||
return await bot_actions.delete_bot(bot, call)
|
return await bot_actions.delete_bot(bot, call)
|
||||||
if operation == "chat":
|
if operation == "chat":
|
||||||
return await bot_actions.select_chat(bot, call, callback_data.get("chat"))
|
return await bot_actions.select_chat(bot, call, callback_data.get("chat"))
|
||||||
|
if operation == "threads":
|
||||||
|
await bot_actions.threads(bot, call)
|
||||||
|
return await send_bot_settings_menu(bot, call)
|
||||||
if operation == "reset_text":
|
if operation == "reset_text":
|
||||||
await bot_actions.reset_bot_text(bot, call)
|
await bot_actions.reset_bot_text(bot, call)
|
||||||
return await send_bot_text_menu(bot, call)
|
return await send_bot_text_menu(bot, call)
|
||||||
|
@ -41,6 +41,8 @@ class Bot(Model):
|
|||||||
incoming_messages_count = fields.BigIntField(default=0)
|
incoming_messages_count = fields.BigIntField(default=0)
|
||||||
outgoing_messages_count = fields.BigIntField(default=0)
|
outgoing_messages_count = fields.BigIntField(default=0)
|
||||||
|
|
||||||
|
enable_threads = fields.BooleanField(default=False)
|
||||||
|
|
||||||
def decrypted_token(self):
|
def decrypted_token(self):
|
||||||
cryptor = DatabaseSettings.cryptor()
|
cryptor = DatabaseSettings.cryptor()
|
||||||
return cryptor.decrypt(self.token)
|
return cryptor.decrypt(self.token)
|
||||||
|
@ -57,7 +57,7 @@ async def message_handler(message: types.Message, *args, **kwargs):
|
|||||||
text="Вы заблокированы в этом боте")
|
text="Вы заблокированы в этом боте")
|
||||||
|
|
||||||
# Пересылаем сообщение в супер-чат
|
# Пересылаем сообщение в супер-чат
|
||||||
if is_super_group:
|
if is_super_group and bot.enable_threads:
|
||||||
thread_first_message = await _redis.get(_thread_uniqie_id(bot.pk, message.chat.id))
|
thread_first_message = await _redis.get(_thread_uniqie_id(bot.pk, message.chat.id))
|
||||||
if thread_first_message:
|
if thread_first_message:
|
||||||
# переслать в супер-чат, отвечая на предыдущее сообщение
|
# переслать в супер-чат, отвечая на предыдущее сообщение
|
||||||
|
Loading…
Reference in New Issue
Block a user