mirror of
https://gitflic.ru/project/alt-gnome/karkas.git
synced 2024-12-23 16:23:02 +03:00
delete legacy modules for OCAB Lite
This commit is contained in:
parent
3076e1af13
commit
39500b77c2
@ -1 +0,0 @@
|
||||
from .moderation import ban_user, unmute_user
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": "Moderation",
|
||||
"description": "Moderation commands for OCAB",
|
||||
"author": "OCAB Team",
|
||||
"version": "1.0"
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
# flake8: noqa
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
|
||||
import aiogram
|
||||
import aiohttp
|
||||
|
||||
from ocab_modules.standard.config.config import *
|
||||
from ocab_modules.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)
|
@ -1,84 +0,0 @@
|
||||
# flake8: noqa
|
||||
|
||||
import asyncio
|
||||
import random
|
||||
from threading import Thread
|
||||
|
||||
from aiogram import Bot
|
||||
from aiogram.types import inline_keyboard_button as types
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
|
||||
from ocab_modules.legacy.moderation import ban_user, unmute_user
|
||||
from src.ocab_modules.standard.config.config import get_telegram_check_bot
|
||||
from src.ocab_modules.standard.database.db_api import *
|
||||
|
||||
|
||||
async def create_math_task():
|
||||
first_number = random.randint(1, 100) # nosec
|
||||
second_number = random.randint(1, 100) # nosec
|
||||
answer = first_number + second_number
|
||||
fake_answers = []
|
||||
for i in range(3):
|
||||
diff = random.randint(1, 10) # nosec
|
||||
diff_sign = random.choice(["+", "-"]) # nosec
|
||||
fake_answers.append(answer + diff if diff_sign == "+" else answer - diff)
|
||||
fake_answers.append(answer)
|
||||
random.shuffle(fake_answers)
|
||||
return [answer, first_number, second_number, fake_answers]
|
||||
|
||||
|
||||
async def ban_user_timer(chat_id: int, user_id: int, time: int, bot: Bot):
|
||||
await asyncio.sleep(time)
|
||||
if get_user(user_id) is not None:
|
||||
pass
|
||||
else:
|
||||
await ban_user()
|
||||
|
||||
|
||||
async def check_new_user(message: Message, bot: Bot):
|
||||
print("check_new_user")
|
||||
if get_telegram_check_bot():
|
||||
# Проверяем наличие пользователя в базе данных
|
||||
|
||||
if get_user(message.from_user.id) is None:
|
||||
# Выдаём пользователю ограничение на отправку сообщений на 3 минуты
|
||||
ban_task = Thread(
|
||||
target=ban_user_timer,
|
||||
args=(message.chat.id, message.from_user.id, 180, bot),
|
||||
)
|
||||
ban_task.start()
|
||||
# Создаём задачу с отложенным выполнением на 3 минуты
|
||||
|
||||
math_task = await create_math_task()
|
||||
text = f"{math_task[1]} + {math_task[2]}"
|
||||
builder = InlineKeyboardBuilder()
|
||||
for answer in math_task[3]:
|
||||
if answer == math_task[0]:
|
||||
builder.add(
|
||||
types.InlineKeyboardButton(
|
||||
text=answer, callback_data=f"check_math_task_true"
|
||||
)
|
||||
)
|
||||
else:
|
||||
builder.add(
|
||||
types.InlineKeyboardButton(
|
||||
text=answer, callback_data=f"check_math_task_false"
|
||||
)
|
||||
)
|
||||
await message.reply(
|
||||
f"Приветствую, {message.from_user.first_name}!\n"
|
||||
f"Для продолжения работы с ботом, пожалуйста, решите математический пример в течении 3х минут:\n"
|
||||
f"*{text}*",
|
||||
reply_markup=builder.as_markup(),
|
||||
)
|
||||
|
||||
|
||||
async def math_task_true(message: Message, bot: Bot):
|
||||
await message.reply(f"Верно! Добро пожаловать в чат {message.from_user.first_name}")
|
||||
await unmute_user(message.chat.id, message.from_user.id, bot)
|
||||
add_user(
|
||||
message.from_user.id,
|
||||
message.from_user.first_name + " " + message.from_user.last_name,
|
||||
message.from_user.username,
|
||||
)
|
||||
pass
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": "Welcome",
|
||||
"description": "Мо",
|
||||
"author": "OCAB Team",
|
||||
"version": "1.0"
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
from aiogram import F, Router
|
||||
|
||||
from .handlers import check_new_user
|
||||
|
||||
router = Router()
|
||||
|
||||
# Если в чат пришел новый пользователь
|
||||
router.message.register(check_new_user, F.new_chat_members.exists())
|
||||
# Ловин колбеки от кнопок с callback_data=f"check_math_task_true"
|
||||
router.callback_query.register(
|
||||
check_new_user, F.callback_data == "check_math_task_true"
|
||||
)
|
Loading…
Reference in New Issue
Block a user