mirror of
https://github.com/civsocit/olgram.git
synced 2025-07-12 13:23:25 +00:00
"interrupt threads" option
This commit is contained in:
parent
ae45374490
commit
acb62fb644
|
@ -20,6 +20,7 @@ Litecoin:
|
|||
История изменений
|
||||
----------------
|
||||
|
||||
- `2024-03-01` Непрерывные потоки сообщений (опция)
|
||||
- `2024-02-17` Опция смены режима работы автоответчика: автоответчик отвечает на КАЖДОЕ сообщение
|
||||
- `2024-01-12` Мультиязычность (стартовое сообщение и автоответчик)
|
||||
- `2022-08-01` Защита от флуда
|
||||
|
|
|
@ -58,3 +58,12 @@ Olgram пересылает сообщения так, чтобы сообщен
|
|||
|
||||
По-умолчанию автоответчик отвечает только на первое сообщение в диалоге с пользователем. Чтобы автоответчик отвечал на
|
||||
КАЖДОЕ входящее сообщение, включите эту опцию.
|
||||
|
||||
|
||||
.. thread_interrupt:
|
||||
|
||||
Прерывать поток
|
||||
--------------------------------
|
||||
|
||||
По-умолчанию поток сообщений от одного пользователя прерывается каждые 24 часа. Без этой опции поток сообщений не
|
||||
прерывается никогда.
|
||||
|
|
|
@ -114,6 +114,11 @@ async def always_second_message(bot: Bot, call: types.CallbackQuery):
|
|||
await bot.save(update_fields=["enable_always_second_message"])
|
||||
|
||||
|
||||
async def thread_interrupt(bot: Bot, call: types.CallbackQuery):
|
||||
bot.enable_thread_interrupt = not bot.enable_thread_interrupt
|
||||
await bot.save(update_fields=["enable_thread_interrupt"])
|
||||
|
||||
|
||||
async def olgram_text(bot: Bot, call: types.CallbackQuery):
|
||||
if await bot.is_promo():
|
||||
bot.enable_olgram_text = not bot.enable_olgram_text
|
||||
|
|
|
@ -178,6 +178,12 @@ async def send_bot_settings_menu(bot: Bot, call: types.CallbackQuery):
|
|||
operation="always_second_message",
|
||||
chat=empty))
|
||||
)
|
||||
keyboard.insert(
|
||||
types.InlineKeyboardButton(text=_("Прерывать поток"),
|
||||
callback_data=menu_callback.new(level=3, bot_id=bot.id,
|
||||
operation="thread_interrupt",
|
||||
chat=empty))
|
||||
)
|
||||
is_promo = await bot.is_promo()
|
||||
if is_promo:
|
||||
keyboard.insert(
|
||||
|
@ -196,13 +202,15 @@ async def send_bot_settings_menu(bot: Bot, call: types.CallbackQuery):
|
|||
info_turn = _("включены") if bot.enable_additional_info else _("выключены")
|
||||
antiflood_turn = _("включен") if bot.enable_antiflood else _("выключен")
|
||||
enable_always_second_message = _("включён") if bot.enable_always_second_message else _("выключен")
|
||||
thread_interrupt = _("да") if bot.enable_thread_interrupt else _("нет")
|
||||
text = dedent(_("""
|
||||
<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#antiflood">Антифлуд</a>: <b>{2}</b>
|
||||
<a href="https://olgram.readthedocs.io/ru/latest/options.html#always_second_message">Автоответчик всегда</a>: <b>{3}
|
||||
<a href="https://olgram.readthedocs.io/ru/latest/options.html#thread_interrupt">Прерывать поток</a>: <b>{4}
|
||||
</b>
|
||||
""")).format(thread_turn, info_turn, antiflood_turn, enable_always_second_message)
|
||||
""")).format(thread_turn, info_turn, antiflood_turn, enable_always_second_message, thread_interrupt)
|
||||
|
||||
if is_promo:
|
||||
olgram_turn = _("включена") if bot.enable_olgram_text else _("выключена")
|
||||
|
@ -535,6 +543,9 @@ async def callback(call: types.CallbackQuery, callback_data: dict, state: FSMCon
|
|||
if operation == "always_second_message":
|
||||
await bot_actions.always_second_message(bot, call)
|
||||
return await send_bot_settings_menu(bot, call)
|
||||
if operation == "thread_interrupt":
|
||||
await bot_actions.thread_interrupt(bot, call)
|
||||
return await send_bot_settings_menu(bot, call)
|
||||
if operation == "olgram_text":
|
||||
await bot_actions.olgram_text(bot, call)
|
||||
return await send_bot_settings_menu(bot, call)
|
||||
|
|
4
olgram/migrations/models/19_20240301193152_update.sql
Normal file
4
olgram/migrations/models/19_20240301193152_update.sql
Normal file
|
@ -0,0 +1,4 @@
|
|||
-- upgrade --
|
||||
ALTER TABLE "bot" ADD "enable_thread_interrupt" BOOL NOT NULL DEFAULT True;
|
||||
-- downgrade --
|
||||
ALTER TABLE "bot" DROP COLUMN "enable_thread_interrupt";
|
|
@ -47,6 +47,7 @@ class Bot(Model):
|
|||
enable_olgram_text = fields.BooleanField(default=True)
|
||||
enable_antiflood = fields.BooleanField(default=False)
|
||||
enable_always_second_message = fields.BooleanField(default=False)
|
||||
enable_thread_interrupt = fields.BooleanField(default=True)
|
||||
|
||||
def decrypted_token(self):
|
||||
cryptor = DatabaseSettings.cryptor()
|
||||
|
|
|
@ -41,7 +41,7 @@ class OlgramSettings(AbstractSettings):
|
|||
|
||||
@classmethod
|
||||
def version(cls):
|
||||
return "0.7.0"
|
||||
return "0.7.1"
|
||||
|
||||
@classmethod
|
||||
@lru_cache
|
||||
|
|
1378
poetry.lock
generated
1378
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
|
@ -1 +1 @@
|
|||
/usr/lib/python3.10/Tools/i18n/pygettext.py -d chinese -o locales/olgram.pot olgram/ server/
|
||||
/usr/lib/python3.11/Tools/i18n/pygettext.py -d chinese -o locales/olgram.pot olgram/ server/
|
||||
|
|
|
@ -106,22 +106,26 @@ async def send_user_message(message: types.Message, super_chat_id: int, bot):
|
|||
async def send_to_superchat(is_super_group: bool, message: types.Message, super_chat_id: int, bot):
|
||||
"""Пересылка сообщения от пользователя оператору (логика потоков сообщений)"""
|
||||
if is_super_group and bot.enable_threads:
|
||||
if bot.enable_thread_interrupt:
|
||||
thread_timeout = ServerSettings.thread_timeout_ms()
|
||||
else:
|
||||
thread_timeout = ServerSettings.redis_timeout_ms()
|
||||
thread_first_message = await _redis.get(_thread_uniqie_id(bot.pk, message.chat.id))
|
||||
if thread_first_message:
|
||||
# переслать в супер-чат, отвечая на предыдущее сообщение
|
||||
try:
|
||||
new_message = await message.copy_to(super_chat_id, reply_to_message_id=int(thread_first_message))
|
||||
await _redis.set(_message_unique_id(bot.pk, new_message.message_id), message.chat.id,
|
||||
pexpire=ServerSettings.redis_timeout_ms())
|
||||
pexpire=thread_timeout)
|
||||
except exceptions.BadRequest:
|
||||
new_message = await send_user_message(message, super_chat_id, bot)
|
||||
await _redis.set(_thread_uniqie_id(bot.pk, message.chat.id), new_message.message_id,
|
||||
pexpire=ServerSettings.thread_timeout_ms())
|
||||
await _redis.set(
|
||||
_thread_uniqie_id(bot.pk, message.chat.id), new_message.message_id, pexpire=thread_timeout)
|
||||
else:
|
||||
# переслать супер-чат
|
||||
new_message = await send_user_message(message, super_chat_id, bot)
|
||||
await _redis.set(_thread_uniqie_id(bot.pk, message.chat.id), new_message.message_id,
|
||||
pexpire=ServerSettings.thread_timeout_ms())
|
||||
pexpire=thread_timeout)
|
||||
else: # личные сообщения не поддерживают потоки сообщений: просто отправляем сообщение
|
||||
await send_user_message(message, super_chat_id, bot)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user