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