Merged with cicd/init

This commit is contained in:
Maxim Slipenko 2024-08-15 20:44:40 +03:00
commit 3514234526
8 changed files with 38 additions and 24 deletions

View File

@ -1,8 +1,8 @@
Руководитель проекта: Руководитель проекта:
- Семен Фомченков (@Armatik), e-mail: armatik@alt-gnome.ru - Семен Фомченков (@Armatik), e-mail: armatik@alt-gnome.ru
Ведущие разработчики: Ведущие разработчики:
- Максим Слипенко (@Maks1m_S), e-mail: maxim@slipenko.com - Максим Слипенко (@Maks1m_S), e-mail: maxim@slipenko.com
Участники проекта: Участники проекта:
- Илья Женецкий (@ilyazheprog) - Илья Женецкий (@ilyazheprog)

14
gitflic-ci.yaml Normal file
View File

@ -0,0 +1,14 @@
stages:
- lint
lint-pre-commit:
stage: lint
image: python:3.12-bullseye
before_script:
- pip install pre-commit
scripts:
- pre-commit run --all-files
cache:
paths:
- .cache/pip
- .cache/pre-commit

View File

@ -2,7 +2,7 @@
## Описание ## Описание
Подготовленная версия OCAB Lite для интеграции в чат [Альт Линукс](https://t.me/alt_linux) Подготовленная версия OCAB Lite для интеграции в чат [Альт Линукс](https://t.me/alt_linux)
## Функционал ## Функционал
Список OCAB-модулей используемых в боте: Список OCAB-модулей используемых в боте:

View File

@ -4,4 +4,4 @@ core:
filters: filters:
approved_chat_id: approved_chat_id:
- -111111 - -111111

View File

@ -85,7 +85,7 @@ class ConfigManager:
value_type: str, value_type: str,
options: List[Any] = None, options: List[Any] = None,
multiple: bool = False, multiple: bool = False,
default_value = None, default_value=None,
editable: bool = True, editable: bool = True,
shared: bool = False, shared: bool = False,
required: bool = False, required: bool = False,

View File

@ -1,7 +1,7 @@
from .filters import ( from .filters import (
ChatIDFilter,
ChatModerOrAdminFilter, ChatModerOrAdminFilter,
ChatNotInApproveFilter, ChatNotInApproveFilter,
ChatIDFilter,
chat_not_in_approve, chat_not_in_approve,
module_init, module_init,
) )

View File

@ -1 +1 @@
from .main import module_init from .main import module_init

View File

@ -1,9 +1,10 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from aiogram import Router from aiogram import Router
from aiogram.filters import Command from aiogram.filters import Command
from aiogram.types import Message, ChatMemberOwner, ChatMemberAdministrator from aiogram.types import ChatMemberAdministrator, ChatMemberOwner, Message
from ocab_core.modules_system.public_api import get_module, register_router, log from ocab_core.modules_system.public_api import get_module, log, register_router
if TYPE_CHECKING: if TYPE_CHECKING:
from ocab_modules.standard.filters import ChatIDFilter as IChatIDFilter from ocab_modules.standard.filters import ChatIDFilter as IChatIDFilter
@ -11,41 +12,40 @@ if TYPE_CHECKING:
try: try:
ChatIDFilter: "type[IChatIDFilter]" = get_module("standard.filters", "ChatIDFilter") ChatIDFilter: "type[IChatIDFilter]" = get_module("standard.filters", "ChatIDFilter")
FILTERS_MODULE_LOADED = True FILTERS_MODULE_LOADED = True
except Exception as e: except Exception:
FILTERS_MODULE_LOADED = False FILTERS_MODULE_LOADED = False
pass pass
try: try:
register_command = get_module("standard.command_helper", "register_command") register_command = get_module("standard.command_helper", "register_command")
COMMAND_HELPER_MODULE_LOADED = True COMMAND_HELPER_MODULE_LOADED = True
except Exception as e: except Exception:
COMMAND_HELPER_MODULE_LOADED = False COMMAND_HELPER_MODULE_LOADED = False
pass pass
def can_moderate(admin: ChatMemberOwner | ChatMemberAdministrator) -> bool: def can_moderate(admin: ChatMemberOwner | ChatMemberAdministrator) -> bool:
if isinstance(admin, ChatMemberOwner): if isinstance(admin, ChatMemberOwner):
return True return True
return ( return admin.user.is_bot is False and (
admin.user.is_bot == False and admin.can_delete_messages and admin.can_restrict_members
(
admin.can_delete_messages and
admin.can_restrict_members
)
) )
async def report(message: Message): async def report(message: Message):
try: try:
if message.reply_to_message is None: if message.reply_to_message is None:
await message.reply("Пожалуйста, используйте команду /report в ответ на сообщение, которое вы хотите отметить как спам.") await message.reply(
return "Пожалуйста, используйте команду /report в ответ на сообщение"
", которое вы хотите отметить как спам."
)
return
admins = await message.chat.get_administrators() admins = await message.chat.get_administrators()
admin_usernames = [ admin_usernames = [
admin.user.mention_html() admin.user.mention_html() for admin in admins if can_moderate(admin)
for admin in admins
if can_moderate(admin)
] ]
if admin_usernames: if admin_usernames:
ping_message = "⚠️ Внимание, жалоба на спам! " + ", ".join(admin_usernames) ping_message = "⚠️ Внимание, жалоба на спам! " + ", ".join(admin_usernames)
@ -66,4 +66,4 @@ async def module_init():
if COMMAND_HELPER_MODULE_LOADED: if COMMAND_HELPER_MODULE_LOADED:
register_command = get_module("standard.command_helper", "register_command") register_command = get_module("standard.command_helper", "register_command")
register_command("report", "Пожаловаться на спам") register_command("report", "Пожаловаться на спам")