0
0
mirror of https://gitflic.ru/project/maks1ms/ocab.git synced 2025-04-04 08:33:47 +03:00
ocab/src/modules/standard/moderation/moderation.py

76 lines
2.7 KiB
Python

import asyncio
import aiohttp
import aiogram
import time
from ...standard.config.config import *
from ...standard.roles.roles import *
class Moderation:
def __init__(self):
access_rights = get_access_rights()
bot_check_message = bool(self.access_rights["BOT_CHECK_MESSAGE"])
bot_ban_user = bool(self.access_rights["BOT_BAN_USER"])
bot_mute_user = bool(self.access_rights["BOT_MUTE_USER"])
moderator_rights = self.access_rights["MODERATOR_RIGHTS"]
ai_check_message = bool(self.access_rights["AI_CHECK_MESSAGE"])
beta_ai_check_message = bool(self.access_rights["BETA_AI_CHECK_MESSAGE"])
async def time_to_seconds(time):
# Конвертация текстового указания времени по типу 3h, 5m, 10s в минуты
if time[-1] == 'd':
return int(time[:-1]) * 86400
elif time[-1] == 'h':
return int(time[:-1]) * 3600
elif time[-1] == 'm':
return int(time[:-1]) * 60
elif time[-1] == 's':
return int(time[:-1])
async def short_time_to_time(self, time):
# Конвертация времени в длинное название
if time[-1] == 'd':
return str(f"{time[0:-1]} дней")
elif time[-1] == 'h':
return str(f"{time[0:-1]} часов")
elif time[-1] == 'm':
return str(f"{time[0:-1]} минут")
elif time[-1] == 's':
return str(f"{time[0:-1]} секунд")
async def delete_message(self, chat_id, message_id, bot: aiogram.Bot):
await bot.delete_message(chat_id, message_id)
async def ban_user(self, chat_id, user_id, bot: aiogram.Bot):
await bot.ban_chat_member(chat_id, user_id)
async def mute_user(chat_id, user_id, time, bot: aiogram.Bot):
mutePermissions = {
"can_send_messages": False,
"can_send_audios": False,
"can_send_documents": False,
"can_send_photos": False,
"can_send_videos": False,
"can_send_video_notes": False,
"can_send_voice_notes": False,
"can_send_polls": False,
"can_send_other_messages": False,
"can_add_web_page_previews": False,
"can_change_info": False,
"can_invite_users": False,
"can_pin_messages": False,
"can_manage_topics": False
}
end_time = time + int(time.time())
await bot.restrict_chat_member(chat_id, user_id, until_date=end_time, **mutePermissions)
async def unmute_user(chat_id, user_id, bot: aiogram.Bot):
await bot.restrict_chat_member(chat_id, user_id, use_independent_chat_permissions=True)
async def ban_user(chat_id, user_id, bot: aiogram.Bot):
await bot.ban_chat_member(chat_id, user_id)