From 79298e544191f8e456d8a32ad508c88005e93d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=BB=D0=B8?= =?UTF-8?q?=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Fri, 16 Aug 2024 16:23:57 +0300 Subject: [PATCH] Merged with fix/add-limits-to-report --- gitflic-ci.yaml | 19 +++++++ .../ocab_modules/standard/report/info.json | 9 ++++ .../ocab_modules/standard/report/main.py | 53 ++++++++++++++----- 3 files changed, 69 insertions(+), 12 deletions(-) diff --git a/gitflic-ci.yaml b/gitflic-ci.yaml index c6a98ab..8cc9912 100644 --- a/gitflic-ci.yaml +++ b/gitflic-ci.yaml @@ -1,5 +1,6 @@ stages: - lint + - build lint-pre-commit: stage: lint @@ -12,3 +13,21 @@ lint-pre-commit: paths: - .cache/pip - .cache/pre-commit + +build-altlinux: + stage: build + image: docker:27.1.2 + variables: + CI_REGISTRY: registry.gitflic.ru + IMAGE_NAME: registry.gitflic.ru/project/alt-gnome/karkas/altlinux + before_script: + - docker info + - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} + scripts: + - | + cd ./src/altlinux + export IMAGE_COMMIT=${IMAGE_NAME}:${CI_COMMIT_SHA} + export IMAGE_BRANCH=${IMAGE_NAME}:$(echo $CI_COMMIT_REF_NAME | sed 's/[^a-zA-Z0-9]/-/g') + docker build -t ${IMAGE_COMMIT} -t ${IMAGE_BRANCH} -f Dockerfile ../.. + docker push ${IMAGE_COMMIT} + docker push ${IMAGE_BRANCH} diff --git a/src/ocab_modules/ocab_modules/standard/report/info.json b/src/ocab_modules/ocab_modules/standard/report/info.json index ac5e2f3..27f7d0e 100644 --- a/src/ocab_modules/ocab_modules/standard/report/info.json +++ b/src/ocab_modules/ocab_modules/standard/report/info.json @@ -6,9 +6,18 @@ "version": "1.0.0", "privileged": false, "dependencies": { + "required": { + "standard.config": "^1.0.0" + }, "optional": { "standard.command_helper": "^1.0.0", "standard.filters": "^1.0.0" } + }, + "pythonDependencies": { + "required": { + "random": "*", + "string": "*" + } } } diff --git a/src/ocab_modules/ocab_modules/standard/report/main.py b/src/ocab_modules/ocab_modules/standard/report/main.py index 7d6ea10..43837fa 100644 --- a/src/ocab_modules/ocab_modules/standard/report/main.py +++ b/src/ocab_modules/ocab_modules/standard/report/main.py @@ -1,3 +1,5 @@ +import random +from string import Template from typing import TYPE_CHECKING from aiogram import Router @@ -7,8 +9,11 @@ from aiogram.types import ChatMemberAdministrator, ChatMemberOwner, Message from ocab_core.modules_system.public_api import get_module, log, register_router if TYPE_CHECKING: + from ocab_modules.standard.config import IConfig from ocab_modules.standard.filters import ChatIDFilter as IChatIDFilter +config: "IConfig" = get_module("standard.config", "config") + try: ChatIDFilter: "type[IChatIDFilter]" = get_module("standard.filters", "ChatIDFilter") FILTERS_MODULE_LOADED = True @@ -36,25 +41,50 @@ def can_moderate(admin: ChatMemberOwner | ChatMemberAdministrator) -> bool: async def report(message: Message): try: if message.reply_to_message is None: - await message.reply( - "Пожалуйста, используйте команду /report в ответ на сообщение" - ", которое вы хотите отметить как спам." - ) + await message.reply(config.get("report::errors::no_reply_message")) return - admins = await message.chat.get_administrators() + mention_list = config.get("report::mention::list") - admin_usernames = [ - admin.user.mention_html() for admin in admins if can_moderate(admin) - ] - if admin_usernames: - ping_message = "⚠️ Внимание, жалоба на спам! " + ", ".join(admin_usernames) - await message.reply_to_message.reply(ping_message, parse_mode="HTML") + if mention_list is None: + admins = await message.chat.get_administrators() + mention_list = [ + admin.user.mention_html() for admin in admins if can_moderate(admin) + ] + + random.shuffle(mention_list) + + limit = config.get("report::mention::limit") + if limit != -1: + mention_list = mention_list[:limit] + + if mention_list: + await message.reply_to_message.reply( + Template(config.get("report::mention::text")).substitute( + mention=", ".join(mention_list) + ), + parse_mode="HTML", + ) except Exception as e: log(e) async def module_init(): + config.register("report::mention::limit", "int", default_value=5) + config.register( + "report::mention::list", "string", multiple=True, default_value=None + ) + config.register( + "report::mention::text", + "string", + default_value="⚠️ Внимание, жалоба на спам! $mention", + ) + config.register( + "report::errors::no_reply_message", + "string", + default_value="Пожалуйста, используйте команду в ответ на сообщение", + ) + router = Router() if FILTERS_MODULE_LOADED: @@ -65,5 +95,4 @@ async def module_init(): register_router(router) if COMMAND_HELPER_MODULE_LOADED: - register_command = get_module("standard.command_helper", "register_command") register_command("report", "Пожаловаться на спам")