mirror of
https://github.com/civsocit/olgram.git
synced 2025-05-24 18:03:25 +00:00
Compare commits
5 Commits
7bb0951e7f
...
6789d23c28
Author | SHA1 | Date | |
---|---|---|---|
|
6789d23c28 | ||
|
0fd8d541f7 | ||
|
65bc807ab7 | ||
|
f6d47f729d | ||
|
62d00cbd5f |
|
@ -19,6 +19,9 @@ Dash:
|
||||||
История изменений
|
История изменений
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
- `2022-08-01` Защита от флуда
|
||||||
|
- `2022-07-23` Автоответчик не пишет сообщение лишний раз
|
||||||
|
- `2022-07-04` Поддержка двух ботов в одном чате
|
||||||
- `2022-06-25` Поддержка HTML\Markdown в стартовом сообщении и автоответчике
|
- `2022-06-25` Поддержка HTML\Markdown в стартовом сообщении и автоответчике
|
||||||
- `2022-06-25` Пересылка отредактированных сообщений
|
- `2022-06-25` Пересылка отредактированных сообщений
|
||||||
- `2022-06-16` User info по возможности отправляется в том же сообщении, что и сообщение пользователя
|
- `2022-06-16` User info по возможности отправляется в том же сообщении, что и сообщение пользователя
|
||||||
|
|
|
@ -41,3 +41,11 @@ Olgram пересылает сообщения так, чтобы сообщен
|
||||||
|
|
||||||
Включение этой опции меняет текст политики конфиденциальности вашего feedback бота (команда /security_policy)
|
Включение этой опции меняет текст политики конфиденциальности вашего feedback бота (команда /security_policy)
|
||||||
и может отпугнуть некоторых пользователей. Не включайте эту опцию без необходимости.
|
и может отпугнуть некоторых пользователей. Не включайте эту опцию без необходимости.
|
||||||
|
|
||||||
|
.. _antiflood:
|
||||||
|
|
||||||
|
Защита от флуда
|
||||||
|
---------------
|
||||||
|
|
||||||
|
При включении этой опции пользователю запрещается отправлять больше одного сообщения в минуту. Используйте её, если
|
||||||
|
не успеваете обрабатывать входящие сообщения.
|
||||||
|
|
|
@ -15,6 +15,9 @@ TOKEN_ENCRYPTION_KEY=SOME_RANDOM_PASSWORD_HERE
|
||||||
# use your user id or group chat id to restrict access to the bot
|
# use your user id or group chat id to restrict access to the bot
|
||||||
# ADMIN_ID=223453418
|
# ADMIN_ID=223453418
|
||||||
|
|
||||||
|
# use your user id or group chat id to give selected users access to the bot's general statistics (/info command)
|
||||||
|
# SUPERVISOR_ID=223453419
|
||||||
|
|
||||||
# example: 11.143.142.140 or my_domain.com (without quotes, without 'https://' prefix!)
|
# example: 11.143.142.140 or my_domain.com (without quotes, without 'https://' prefix!)
|
||||||
WEBHOOK_HOST=YOUR_HOST_HERE
|
WEBHOOK_HOST=YOUR_HOST_HERE
|
||||||
|
|
||||||
|
|
|
@ -643,3 +643,9 @@ msgstr ""
|
||||||
|
|
||||||
msgid "Не удаётся связаться с владельцем бота"
|
msgid "Не удаётся связаться с владельцем бота"
|
||||||
msgstr "Cannot contact the owner of the bot"
|
msgstr "Cannot contact the owner of the bot"
|
||||||
|
|
||||||
|
msgid "Слишком много сообщений, подождите одну минуту"
|
||||||
|
msgstr "Too many messages, wait one minute"
|
||||||
|
|
||||||
|
msgid "Антифлуд"
|
||||||
|
msgstr "Antiflood"
|
||||||
|
|
|
@ -654,3 +654,9 @@ msgstr ""
|
||||||
|
|
||||||
msgid "Не удаётся связаться с владельцем бота"
|
msgid "Не удаётся связаться с владельцем бота"
|
||||||
msgstr "Не вдається зв'язатися з власником бота"
|
msgstr "Не вдається зв'язатися з власником бота"
|
||||||
|
|
||||||
|
msgid "Слишком много сообщений, подождите одну минуту"
|
||||||
|
msgstr "Забагато повідомлень, зачекайте одну хвилину"
|
||||||
|
|
||||||
|
msgid "Антифлуд"
|
||||||
|
msgstr "Антифлуд"
|
||||||
|
|
|
@ -86,3 +86,8 @@ async def olgram_text(bot: Bot, call: types.CallbackQuery):
|
||||||
if await bot.is_promo():
|
if await bot.is_promo():
|
||||||
bot.enable_olgram_text = not bot.enable_olgram_text
|
bot.enable_olgram_text = not bot.enable_olgram_text
|
||||||
await bot.save(update_fields=["enable_olgram_text"])
|
await bot.save(update_fields=["enable_olgram_text"])
|
||||||
|
|
||||||
|
|
||||||
|
async def antiflood(bot: Bot, call: types.CallbackQuery):
|
||||||
|
bot.enable_antiflood = not bot.enable_antiflood
|
||||||
|
await bot.save(update_fields=["enable_antiflood"])
|
||||||
|
|
|
@ -162,6 +162,11 @@ 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))
|
||||||
)
|
)
|
||||||
|
keyboard.insert(
|
||||||
|
types.InlineKeyboardButton(text=_("Антифлуд"),
|
||||||
|
callback_data=menu_callback.new(level=3, bot_id=bot.id, operation="antiflood",
|
||||||
|
chat=empty))
|
||||||
|
)
|
||||||
is_promo = await bot.is_promo()
|
is_promo = await bot.is_promo()
|
||||||
if is_promo:
|
if is_promo:
|
||||||
keyboard.insert(
|
keyboard.insert(
|
||||||
|
@ -178,10 +183,12 @@ async def send_bot_settings_menu(bot: Bot, call: types.CallbackQuery):
|
||||||
|
|
||||||
thread_turn = _("включены") if bot.enable_threads else _("выключены")
|
thread_turn = _("включены") if bot.enable_threads else _("выключены")
|
||||||
info_turn = _("включены") if bot.enable_additional_info else _("выключены")
|
info_turn = _("включены") if bot.enable_additional_info else _("выключены")
|
||||||
|
antiflood_turn = _("включен") if bot.enable_antiflood else _("выключен")
|
||||||
text = dedent(_("""
|
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#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)
|
<a href="https://olgram.readthedocs.io/ru/latest/options.html#antiflood">Антифлуд</a>: <b>{2}</b>
|
||||||
|
""")).format(thread_turn, info_turn, antiflood_turn)
|
||||||
|
|
||||||
if is_promo:
|
if is_promo:
|
||||||
olgram_turn = _("включена") if bot.enable_olgram_text else _("выключена")
|
olgram_turn = _("включена") if bot.enable_olgram_text else _("выключена")
|
||||||
|
@ -425,6 +432,9 @@ async def callback(call: types.CallbackQuery, callback_data: dict, state: FSMCon
|
||||||
if operation == "threads":
|
if operation == "threads":
|
||||||
await bot_actions.threads(bot, call)
|
await bot_actions.threads(bot, call)
|
||||||
return await send_bot_settings_menu(bot, call)
|
return await send_bot_settings_menu(bot, call)
|
||||||
|
if operation == "antiflood":
|
||||||
|
await bot_actions.antiflood(bot, call)
|
||||||
|
return await send_bot_settings_menu(bot, call)
|
||||||
if operation == "additional_info":
|
if operation == "additional_info":
|
||||||
await bot_actions.additional_info(bot, call)
|
await bot_actions.additional_info(bot, call)
|
||||||
return await send_bot_settings_menu(bot, call)
|
return await send_bot_settings_menu(bot, call)
|
||||||
|
|
4
olgram/migrations/models/14_20220801015243_update.sql
Normal file
4
olgram/migrations/models/14_20220801015243_update.sql
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
-- upgrade --
|
||||||
|
ALTER TABLE "bot" ADD "enable_antiflood" BOOL NOT NULL DEFAULT False;
|
||||||
|
-- downgrade --
|
||||||
|
ALTER TABLE "bot" DROP COLUMN "enable_antiflood";
|
|
@ -45,6 +45,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)
|
enable_olgram_text = fields.BooleanField(default=True)
|
||||||
|
enable_antiflood = fields.BooleanField(default=False)
|
||||||
|
|
||||||
def decrypted_token(self):
|
def decrypted_token(self):
|
||||||
cryptor = DatabaseSettings.cryptor()
|
cryptor = DatabaseSettings.cryptor()
|
||||||
|
|
|
@ -41,7 +41,7 @@ class OlgramSettings(AbstractSettings):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def version(cls):
|
def version(cls):
|
||||||
return "0.4.2"
|
return "0.4.3"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@lru_cache
|
@lru_cache
|
||||||
|
|
|
@ -46,6 +46,10 @@ def _last_message_uid(bot_id: int, chat_id: int) -> str:
|
||||||
return f"lm_{bot_id}_{chat_id}"
|
return f"lm_{bot_id}_{chat_id}"
|
||||||
|
|
||||||
|
|
||||||
|
def _antiflood_marker_uid(bot_id: int, chat_id: int) -> str:
|
||||||
|
return f"af_{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"
|
||||||
|
@ -73,7 +77,7 @@ async def send_user_message(message: types.Message, super_chat_id: int, bot):
|
||||||
user_info += message.from_user.full_name
|
user_info += message.from_user.full_name
|
||||||
if message.from_user.username:
|
if message.from_user.username:
|
||||||
user_info += " | @" + message.from_user.username
|
user_info += " | @" + message.from_user.username
|
||||||
user_info += f" | #{message.from_user.id}"
|
user_info += f" | #ID{message.from_user.id}"
|
||||||
|
|
||||||
# Добавлять информацию в конец текста
|
# Добавлять информацию в конец текста
|
||||||
if message.content_type == types.ContentType.TEXT and len(message.text) + len(user_info) < 4093: # noqa:E721
|
if message.content_type == types.ContentType.TEXT and len(message.text) + len(user_info) < 4093: # noqa:E721
|
||||||
|
@ -130,6 +134,13 @@ async def handle_user_message(message: types.Message, super_chat_id: int, bot):
|
||||||
return SendMessage(chat_id=message.chat.id,
|
return SendMessage(chat_id=message.chat.id,
|
||||||
text=_("Вы заблокированы в этом боте"))
|
text=_("Вы заблокированы в этом боте"))
|
||||||
|
|
||||||
|
# Проверить анти-флуд
|
||||||
|
if bot.enable_antiflood:
|
||||||
|
if await _redis.get(_antiflood_marker_uid(bot.pk, message.chat.id)):
|
||||||
|
return SendMessage(chat_id=message.chat.id,
|
||||||
|
text=_("Слишком много сообщений, подождите одну минуту"))
|
||||||
|
await _redis.setex(_antiflood_marker_uid(bot.pk, message.chat.id), 60, 1)
|
||||||
|
|
||||||
# Пересылаем сообщение в супер-чат
|
# Пересылаем сообщение в супер-чат
|
||||||
try:
|
try:
|
||||||
await send_to_superchat(is_super_group, message, super_chat_id, bot)
|
await send_to_superchat(is_super_group, message, super_chat_id, bot)
|
||||||
|
@ -144,8 +155,8 @@ async def handle_user_message(message: types.Message, super_chat_id: int, bot):
|
||||||
|
|
||||||
# И отправить пользователю специальный текст, если он указан и если давно не отправляли
|
# И отправить пользователю специальный текст, если он указан и если давно не отправляли
|
||||||
if bot.second_text:
|
if bot.second_text:
|
||||||
send_auto = not await _redis.get(_last_message_uid(message.bot.id, message.chat.id))
|
send_auto = not await _redis.get(_last_message_uid(bot.pk, message.chat.id))
|
||||||
await _redis.setex(_last_message_uid(message.bot.id, message.chat.id), 60 * 60 * 3, 1)
|
await _redis.setex(_last_message_uid(bot.pk, message.chat.id), 60 * 60 * 3, 1)
|
||||||
if send_auto:
|
if send_auto:
|
||||||
return SendMessage(chat_id=message.chat.id, text=bot.second_text, parse_mode="HTML")
|
return SendMessage(chat_id=message.chat.id, text=bot.second_text, parse_mode="HTML")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user