This repository has been archived on 2024-07-28. You can view files and clone it, but cannot push or open issues or pull requests.
moderator-bot/handlers/users/user.py

129 lines
4.3 KiB
Python
Raw Normal View History

2022-11-06 03:48:10 -05:00
from load import dp, types, bot
from database import Member, Restriction
2022-08-07 04:45:35 -04:00
from aiogram.types import KeyboardButton,ReplyKeyboardMarkup
from aiogram.types.reply_keyboard import ReplyKeyboardRemove
import config
from keyboards.default import menu
from aiogram.types import CallbackQuery
from aiogram.dispatcher.filters import Text
from aiogram.dispatcher.storage import FSMContext
from states.report_message import States
from keyboards.inline.report_button import report_button
from keyboards.inline.callback_data import report_callback
@dp.message_handler(commands=["start","help"],chat_type=[types.ChatType.PRIVATE])
async def start_command_private(message:types.Message):
await message.answer((
2022-11-06 03:48:10 -05:00
f"Hi, **{message.from_user.first_name}**!\n"
2022-08-16 06:28:08 -04:00
"My commands:\n"
"\t\t/help /start - read this message.")
2022-08-07 04:45:35 -04:00
,parse_mode="Markdown",reply_markup=menu
)
# Keyboard
@dp.message_handler(Text(equals=["About Us"]))
async def about_us(message:types.Message):
await message.answer((
"Moderator bot - an open source project for managing a Telegram group.\n\n"
"Possibilities:\n"
"1. Role system\n"
"2. Simple commands such as !ban, !mute\n"
"3. Convenient sticker/photo disabling with !stickers, !media\n"
"4. Users can report admins.\n"
"5. Admins can give warnings to users.\n"
"\nRelease version:2.5.2\n"
"[Github](https://github.com/hok7z/moderator-bot)"),
parse_mode="Markdown"
)
@dp.message_handler(Text(equals=["Check restrictions"]),state=None)
async def check_for_restrict(message:types.Message):
2022-11-06 03:48:10 -05:00
user = Member.get(Member.user_id == message.from_user.id)
2022-12-01 05:54:32 -05:00
restrictions = Restriction.select().where(Restriction.to_user == user)
2022-08-07 04:45:35 -04:00
2022-11-06 03:48:10 -05:00
if (not restrictions):
2022-08-07 04:45:35 -04:00
await message.answer("✅No restrictions.")
return
for restriction in restrictions:
2022-11-06 03:48:10 -05:00
callback = report_callback.new(restriction_id=restriction.id)
2022-08-07 04:45:35 -04:00
markup = report_button("✉️ Report restriction",callback)
2022-12-01 05:54:32 -05:00
from_user = restriction.from_user
to_user = restriction.to_user
await message.answer(
(
f"Restriction #{restriction.id}\n"
f"from user: [{from_user.first_name}](tg://user?id={from_user.user_id})\n"
f"to user: [{from_user.first_name}](tg://user?id={to_user.user_id})\n"
f"{restriction.text}\n"
f"{restriction.timestamp}\n"
),parse_mode="Markdown",
reply_markup=markup
)
2022-08-07 04:45:35 -04:00
await States.state1.set()
@dp.callback_query_handler(text_contains="report_restriction",state=States.state1)
2022-11-06 03:48:10 -05:00
async def report_restriction(call:CallbackQuery, state:FSMContext):
2022-08-07 04:45:35 -04:00
await call.answer(cache_time=60)
2022-11-06 03:48:10 -05:00
callback_data = call.data
restriction_id = callback_data.split(":")[1]
2022-08-07 04:45:35 -04:00
markup = ReplyKeyboardMarkup(resize_keyboard=True)
cancel = KeyboardButton("❌ Cancel")
markup.add(cancel)
await state.update_data(restriction_id=restriction_id)
await call.message.answer("Please,enter your report.",reply_markup=markup)
2022-11-06 03:48:10 -05:00
await States.next()
2022-08-07 04:45:35 -04:00
@dp.message_handler(state=States.state2)
2022-11-06 03:48:10 -05:00
async def get_message_report(message:types.Message, state:FSMContext):
2022-08-07 04:45:35 -04:00
answer = message.text
2022-11-06 03:48:10 -05:00
2022-08-07 04:45:35 -04:00
if not ("Cancel" in answer):
2022-11-06 03:48:10 -05:00
data = await state.get_data()
restriction_id = data.get("restriction_id")
2022-12-01 05:54:32 -05:00
restriction = Restriction.get(id=restriction_id)
2022-08-07 04:45:35 -04:00
2022-11-06 03:48:10 -05:00
from_user = restriction.from_user
to_user = restriction.to_user
2022-08-07 04:45:35 -04:00
2022-12-01 05:54:32 -05:00
await bot.send_message(config.second_group_id,
(
"Report on restriction #{}\n"
"from user: [{}](tg://user?id={})\n"
"to user: [{}](tg://user?id={})\n"
"{}\n"
"{}\n"
"Message:{}"
).format(
restriction_id,
from_user.first_name,
from_user.user_id,
to_user.first_name,
to_user.user_id,
restriction.text,
restriction.timestamp,
answer,
)
,parse_mode="Markdown"
)
2022-08-07 04:45:35 -04:00
await message.answer("Report restriction sended",reply_markup=ReplyKeyboardRemove())
else:
await message.answer("Operation cancaled",reply_markup=ReplyKeyboardRemove())
await state.finish()