mirror of
https://gitflic.ru/project/alt-gnome/karkas.git
synced 2025-10-03 12:04:06 +03:00
Merged with fix/add-limits-to-report
This commit is contained in:
@@ -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": "*"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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", "Пожаловаться на спам")
|
||||
|
Reference in New Issue
Block a user