mirror of
https://github.com/civsocit/olgram.git
synced 2023-07-22 01:29:12 +03:00
#16 smart auto-reply
This commit is contained in:
parent
c7a52ea9fd
commit
3f978c8d1c
@ -41,7 +41,7 @@ class OlgramSettings(AbstractSettings):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def version(cls):
|
def version(cls):
|
||||||
return "0.4.1"
|
return "0.4.2"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@lru_cache
|
@lru_cache
|
||||||
|
@ -42,6 +42,10 @@ def _thread_uniqie_id(bot_id: int, chat_id: int) -> str:
|
|||||||
return f"thread_{bot_id}_{chat_id}"
|
return f"thread_{bot_id}_{chat_id}"
|
||||||
|
|
||||||
|
|
||||||
|
def _last_message_uid(bot_id: int, chat_id: int) -> str:
|
||||||
|
return f"lm_{bot_id}_{chat_id}"
|
||||||
|
|
||||||
|
|
||||||
def _on_security_policy(message: types.Message, bot):
|
def _on_security_policy(message: types.Message, bot):
|
||||||
_ = _get_translator(message)
|
_ = _get_translator(message)
|
||||||
text = _("<b>Политика конфиденциальности</b>\n\n"
|
text = _("<b>Политика конфиденциальности</b>\n\n"
|
||||||
@ -138,9 +142,12 @@ async def handle_user_message(message: types.Message, super_chat_id: int, bot):
|
|||||||
bot.incoming_messages_count = F("incoming_messages_count") + 1
|
bot.incoming_messages_count = F("incoming_messages_count") + 1
|
||||||
await bot.save(update_fields=["incoming_messages_count"])
|
await bot.save(update_fields=["incoming_messages_count"])
|
||||||
|
|
||||||
# И отправить пользователю специальный текст, если он указан
|
# И отправить пользователю специальный текст, если он указан и если давно не отправляли
|
||||||
if bot.second_text:
|
if bot.second_text:
|
||||||
return SendMessage(chat_id=message.chat.id, text=bot.second_text, parse_mode="HTML")
|
send_auto = not await _redis.get(_last_message_uid(message.bot.id, message.chat.id))
|
||||||
|
await _redis.setex(_last_message_uid(message.bot.id, message.chat.id), 60 * 60 * 3, True)
|
||||||
|
if send_auto:
|
||||||
|
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):
|
||||||
|
Loading…
Reference in New Issue
Block a user