Migrate to aiogram dev-3.0b6

This commit is contained in:
hok7z 2023-02-18 15:16:54 +02:00
parent 65eada8924
commit f42f28a0ce
15 changed files with 225 additions and 238 deletions

9
app.py
View File

@ -11,14 +11,9 @@ from aiogram.webhook.aiohttp_server import (
) )
# import filters
import config import config
import handlers
# dp.filters_factory.bind(filters.AvaibleRolesFilter)
# dp.filters_factory.bind(filters.ReplayMessageFilter)
# import handlers
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
@ -38,7 +33,7 @@ async def on_startup():
if DATABASE_EMPTY: if DATABASE_EMPTY:
await bot.send_message( await bot.send_message(
config.second_group_id, config.second_group_id,
"Member table is empty, run: `!reload`", parse_mode="Markdown" "Member table is empty, run: `!reload`"
) )
await notify_started_bot(bot) await notify_started_bot(bot)

View File

@ -1,2 +1,3 @@
from .avaible_roles import AvaibleRolesFilter from .available_roles import AvailableRoles
from .replay_message import ReplayMessageFilter from .reply_message import MessageReplied
from .chat_type_filter import ChatTypeFilter

View File

@ -1,18 +1,15 @@
from aiogram import types from aiogram import types
from aiogram.dispatcher.filters import BoundFilter from aiogram.filters import Filter
from database import Member, MemberRoles from database import Member, MemberRoles
class AvaibleRolesFilter(BoundFilter): class AvailableRoles(Filter):
"""Filter accessed roles""" """Filter accessed roles"""
key = "available_roles" def __init__(self, *args):
self.avaible_roles: list[MemberRoles] = args
def __init__(self, available_roles: list[MemberRoles]): async def __call__(self, message: types.Message) -> bool:
self.avaible_roles = available_roles
async def check(self, message: types.Message):
member = Member.get(Member.user_id == message.from_user.id) member = Member.get(Member.user_id == message.from_user.id)
if (member.role == "owner"): if (member.role == "owner"):

View File

@ -0,0 +1,10 @@
from aiogram.filters import Filter
from aiogram import types
class ChatTypeFilter(Filter):
def __init__(self, *chat_types: list[str]):
self.chat_types = chat_types
async def __call__(self, message: types.Message):
return message.chat.type in self.chat_types

View File

@ -1,16 +0,0 @@
from aiogram import types
from aiogram.dispatcher.filters import BoundFilter
class ReplayMessageFilter(BoundFilter):
"""Check if message replied"""
key = 'replied'
def __init__(self, replied):
self.replied = replied
async def check(self, message: types.Message):
if message.reply_to_message is None:
await message.reply("Is command must be reply")
return False
return True

15
filters/reply_message.py Normal file
View File

@ -0,0 +1,15 @@
from aiogram import types
from aiogram.filters import Filter
class MessageReplied(Filter):
"""Check if message replied"""
def __init__(self, replied=True):
self.replied = replied
async def __call__(self, message: types.Message):
if not message.reply_to_message:
await message.reply("Is command must be reply")
return False
return True

View File

@ -2,6 +2,6 @@ from load import dp, types
from config import group_id from config import group_id
@dp.channel_post_handler() @dp.channel_post()
async def channel_handler(message: types.Message): async def channel_handler(message):
await message.forward(group_id) await message.forward(group_id)

View File

@ -1,28 +1,23 @@
import logging import logging
from peewee import DoesNotExist
from load import dp, bot, types from load import dp, bot, types
import config import config
from aiogram.utils.exceptions import Unauthorized from peewee import DoesNotExist
from aiogram.exceptions import TelegramUnauthorizedError
@dp.errors_handler() @dp.errors()
async def errors_handler(update: types.Update, exception): async def errors_handler(event: types.error_event.ErrorEvent):
if (isinstance(exception, Unauthorized)): if (isinstance(event.exception, TelegramUnauthorizedError)):
logging.info(f"Unathorized: {config.token}") logging.info(f"Unathorized: {config.token}")
return True return True
if (isinstance(exception, DoesNotExist)): if (isinstance(event.exception, DoesNotExist)):
await update.message.reply("Membser not found, you shoud update database data `!reload`", event.update.message.reply("Membser not found, you shoud update database data `!reload`")
parse_mode="Markdown")
return True return True
await update.message.answer("Error happaned!\nBot terminated!")
await bot.send_message(config.second_group_id, ( await bot.send_message(config.second_group_id, (
"Bot terminated" "Bot terminated\n"
f"{exception}" f"Exception: {event.exception}"
), parse_mode="Markdown" ))
)

View File

@ -1,50 +1,59 @@
from load import bot, dp, types from load import bot, dp, types
from aiogram import Bot
import config import config
from aiogram.filters import Command
from filters import MessageReplied
from filters import ChatTypeFilter
from database import Member from database import Member
from aiogram.filters.chat_member_updated import \
ChatMemberUpdatedFilter, JOIN_TRANSITION, ChatMemberUpdated
@dp.message_handler(content_types=["new_chat_members"])
async def welcome_message(message: types.Message): @dp.chat_member(
user = Member.get_or_none(Member.user_id == message.from_user.id) ChatMemberUpdatedFilter(member_status_changed=JOIN_TRANSITION)
)
async def welcome_message(event: ChatMemberUpdated, _bot: Bot):
user = Member.get_or_none(Member.user_id == event.from_user.id)
if (user): if (user):
await message.answer(f"Hi, {user.first_name} again") await _bot.send_message(
chat_id=event.chat.id,
text=f"Hi, {user.first_name} again"
)
if not (user): if not (user):
Member.create( Member.create(
user_id=message.from_user.id, user_id=event.from_user.id,
first_name=message.from_user.first_name, first_name=event.from_user.first_name,
username=message.from_user.username, username=event.from_user.username,
) )
await message.answer(( await _bot.send_message(
f"Hi, **{user.first_name}**!\n" chat_id=event.chat.id,
"Please, read [chat rules]({})" text=f"Hi, [{user.first_name}](tg://user?id={user.id})!\n"
).format("https://nometa.xyz"), "Please, read [chat rules](https://nometa.xyz)"
parse_mode="Markdown"
) )
await message.delete()
@dp.message(
@dp.message_handler( Command("start", "help"),
commands=["start", "help"], ChatTypeFilter("supergroup")
chat_type=[types.ChatType.SUPERGROUP]
) )
async def start_command_group(message: types.Message): async def start_command_group(message: types.Message):
await message.answer(( await message.answer((
f"Hi,**{message.from_user.first_name}**!\n" f"Hi, [{message.from_user.first_name}](tg://user?id={message.from_user.id})!\n"
"My commands:\n" "My commands:\n"
" /help , /start - read the message\n" " /help , /start - read the message\n"
" /me , /bio - member information (if member group)"), " /me , /bio - member information (if member group)")
parse_mode="Markdown"
) )
@dp.message_handler( @dp.message(
commands=["leave"], Command("leave"),
chat_type=[types.ChatType.SUPERGROUP] ChatTypeFilter("supergroup")
) )
async def leave_group(message: types.Message): async def leave_group(message: types.Message):
user = message.from_user user = message.from_user
@ -65,30 +74,28 @@ async def leave_group(message: types.Message):
await message.answer(( await message.answer((
f"User [{user.first_name}](tg://user?id={user.id})" f"User [{user.first_name}](tg://user?id={user.id})"
"has leaved chat for forever" "has leaved chat for forever"
), parse_mode="Markdown" ))
)
Member.delete().where(Member.user_id == user.id).execute() Member.delete().where(Member.user_id == user.id).execute()
@dp.message_handler( @dp.message(
commands=["bio", "me"], Command("bio", "me"),
chat_type=[types.ChatType.SUPERGROUP] ChatTypeFilter("supergroup")
) )
async def get_information(message: types.Message): async def get_information(message: types.Message):
user = Member.get(Member.user_id == message.from_user.id) user = Member.get(Member.user_id == message.from_user.id)
await message.answer(( await message.answer((
f"[{user.first_name}](tg://user?id={user.user_id}) ({user.role})\n" f"[{user.first_name}](tg://user?id={user.user_id}) ({user.role})\n"
f"Warns: {user.warns}/{config.limit_of_warns}"), f"Warns: {user.warns}/{config.limit_of_warns}"
parse_mode="Markdown" ))
)
@dp.message_handler( @dp.message(
commands=["report"], Command("report"),
replied=True, MessageReplied(),
chat_type=[types.ChatType.SUPERGROUP] ChatTypeFilter("supergroup")
) )
async def user_report(message: types.Message): async def user_report(message: types.Message):
args = message.text.split() args = message.text.split()
@ -115,6 +122,5 @@ async def user_report(message: types.Message):
reporter_user.id, reporter_user.id,
reason, reason,
message.reply_to_message.link("link message", as_html=False) message.reply_to_message.link("link message", as_html=False)
), )
parse_mode="Markdown",
) )

View File

@ -1,6 +1,7 @@
from load import bot, dp, types from load import bot, dp, types
from aiogram.types.chat_permissions import ChatPermissions from aiogram.types.chat_permissions import ChatPermissions
from aiogram.filters.command import Command
from filters import AvailableRoles
import config import config
from database import Restriction from database import Restriction
@ -9,10 +10,9 @@ from database import MemberRoles
from utils import get_command_args, get_argument, parse_timedelta_from_message from utils import get_command_args, get_argument, parse_timedelta_from_message
@dp.message_handler( @dp.message(
commands=["ban", "sban"], Command("ban", "sban", prefix="!"),
commands_prefix="!", AvailableRoles(MemberRoles.HELPER, MemberRoles.ADMIN)
available_roles=[MemberRoles.HELPER, MemberRoles.ADMIN]
) )
async def ban_user(message: types.Message): async def ban_user(message: types.Message):
command = await get_command_args(message) command = await get_command_args(message)
@ -37,7 +37,7 @@ async def ban_user(message: types.Message):
await message.answer(( await message.answer((
f"[{from_user.first_name}](tg://user?id={from_user.user_id}) has banned " f"[{from_user.first_name}](tg://user?id={from_user.user_id}) has banned "
f"[{to_user.first_name}](tg://user?id={to_user.user_id})" f"[{to_user.first_name}](tg://user?id={to_user.user_id})"
), parse_mode="Markdown") ))
Restriction.create( Restriction.create(
from_user=from_user, from_user=from_user,
@ -47,10 +47,9 @@ async def ban_user(message: types.Message):
) )
@dp.message_handler( @dp.message(
commands=["unban", "sunban"], Command("unban", "sunban", prefix="!"),
commands_prefix="!", AvailableRoles(MemberRoles.HELPER, MemberRoles.ADMIN)
available_roles=[MemberRoles.HELPER, MemberRoles.ADMIN]
) )
async def unban_user(message: types.Message): async def unban_user(message: types.Message):
command = await get_command_args(message) command = await get_command_args(message)
@ -65,13 +64,16 @@ async def unban_user(message: types.Message):
) )
return return
status = await bot.unban_chat_member(chat_id=message.chat.id, user_id=to_user.user_id) status = await bot.unban_chat_member(
chat_id=message.chat.id,
user_id=to_user.user_id
)
if status and (not command.is_silent): if status and (not command.is_silent):
await message.answer(( await message.answer((
f"[{from_user.first_name}](tg://user?id={from_user.user_id}) has unbanned " f"[{from_user.first_name}](tg://user?id={from_user.user_id}) has unbanned "
f"[{to_user.first_name}](tg://user?id={to_user.user_id})" f"[{to_user.first_name}](tg://user?id={to_user.user_id})"
), parse_mode="Markdown") ))
Restriction.create( Restriction.create(
from_user=from_user, from_user=from_user,
@ -81,10 +83,9 @@ async def unban_user(message: types.Message):
) )
@dp.message_handler( @dp.message(
commands=["info"], Command("info", prefix="!"),
commands_prefix="!", AvailableRoles(MemberRoles.HELPER, MemberRoles.ADMIN)
available_roles=[MemberRoles.HELPER, MemberRoles.ADMIN]
) )
async def info_user(message: types.Message): async def info_user(message: types.Message):
command = await get_command_args(message) command = await get_command_args(message)
@ -99,15 +100,13 @@ async def info_user(message: types.Message):
await message.answer(( await message.answer((
f"[{to_user.first_name}](tg://user?id={to_user.user_id}) ({to_user.role})\n" f"[{to_user.first_name}](tg://user?id={to_user.user_id}) ({to_user.role})\n"
f"Warns: {to_user.warns}/{config.limit_of_warns}"), f"Warns: {to_user.warns}/{config.limit_of_warns}")
parse_mode="Markdown"
) )
@dp.message_handler( @dp.message(
commands=["kick", "skick"], Command("kick", "skick", prefix="!"),
commands_prefix="!", AvailableRoles(MemberRoles.HELPER, MemberRoles.ADMIN)
available_roles=[MemberRoles.HELPER, MemberRoles.ADMIN]
) )
async def kick_user(message: types.Message): async def kick_user(message: types.Message):
command = await get_command_args(message) command = await get_command_args(message)
@ -122,7 +121,6 @@ async def kick_user(message: types.Message):
) )
return return
status1 = await bot.kick_chat_member( status1 = await bot.kick_chat_member(
chat_id=message.chat.id, chat_id=message.chat.id,
user_id=to_user.user_id, user_id=to_user.user_id,
@ -138,7 +136,7 @@ async def kick_user(message: types.Message):
await message.answer(( await message.answer((
f"[{from_user.first_name}](tg://user?id={from_user.user_id}) has kicked " f"[{from_user.first_name}](tg://user?id={from_user.user_id}) has kicked "
f"[{to_user.first_name}](tg://user?id={to_user.user_id})" f"[{to_user.first_name}](tg://user?id={to_user.user_id})"
), parse_mode="Markdown") ))
Restriction.create( Restriction.create(
from_user=from_user, from_user=from_user,
@ -148,10 +146,9 @@ async def kick_user(message: types.Message):
) )
@dp.message_handler( @dp.message(
commands=["mute", "smute"], Command("mute", "smute", prefix="!"),
commands_prefix="!", AvailableRoles(MemberRoles.ADMIN)
available_roles=[MemberRoles.ADMIN]
) )
async def mute_user(message: types.Message): async def mute_user(message: types.Message):
command = await get_command_args(message) command = await get_command_args(message)
@ -181,7 +178,7 @@ async def mute_user(message: types.Message):
await message.answer(( await message.answer((
f"[{from_user.first_name}](tg://user?id={from_user.user_id}) has muted " f"[{from_user.first_name}](tg://user?id={from_user.user_id}) has muted "
f"[{to_user.first_name}](tg://user?id={to_user.user_id})" f"[{to_user.first_name}](tg://user?id={to_user.user_id})"
), parse_mode="Markdown") ))
Restriction.create( Restriction.create(
from_user=from_user, from_user=from_user,
@ -191,10 +188,9 @@ async def mute_user(message: types.Message):
) )
@dp.message_handler( @dp.message(
commands=["unmute", "sunmute"], Command("unmute", "sunmute", prefix="!"),
commands_prefix="!", AvailableRoles(MemberRoles.ADMIN)
available_roles=[MemberRoles.ADMIN]
) )
async def umute_user(message: types.Message): async def umute_user(message: types.Message):
# Get information # Get information
@ -205,7 +201,7 @@ async def umute_user(message: types.Message):
if (not to_user) or (not from_user): if (not to_user) or (not from_user):
await message.answer(( await message.answer((
"Usage:!unmute (@username|id) reason=None.\n" "Usage: !unmute (@username|id) reason=None\n"
"Reply to a message or use with a username/id.") "Reply to a message or use with a username/id.")
) )
return return
@ -236,22 +232,20 @@ async def umute_user(message: types.Message):
await message.answer(( await message.answer((
f"[{from_user.first_name}](tg://user?id={from_user.user_id}) has unmuted " f"[{from_user.first_name}](tg://user?id={from_user.user_id}) has unmuted "
f"[{to_user.first_name}](tg://user?id={to_user.user_id})" f"[{to_user.first_name}](tg://user?id={to_user.user_id})"
), parse_mode="Markdown") ))
@dp.message_handler( @dp.message(
commands=["pin"], Command("pin", prefix="!"),
commands_prefix="!", AvailableRoles(MemberRoles.HELPER, MemberRoles.ADMIN)
available_roles=[MemberRoles.HELPER, MemberRoles.ADMIN]
) )
async def pin_message(message: types.Message): async def pin_message(message: types.Message):
await bot.pin_chat_message(message.chat.id, message.reply_to_message.message_id) await bot.pin_chat_message(message.chat.id, message.reply_to_message.message_id)
@dp.message_handler( @dp.message(
commands=["readonly", "ro"], Command("ro", "readonly", prefix="!"),
commands_prefix="!", AvailableRoles(MemberRoles.ADMIN)
available_roles=[MemberRoles.ADMIN]
) )
async def readonly_mode(message: types.Message): async def readonly_mode(message: types.Message):
group_permissions = config.group_permissions group_permissions = config.group_permissions
@ -282,10 +276,9 @@ async def readonly_mode(message: types.Message):
) )
@dp.message_handler( @dp.message(
commands=["warn", "w"], Command("warn", "w", prefix="!"),
commands_prefix="!", AvailableRoles(MemberRoles.HELPER, MemberRoles.ADMIN)
available_roles=[MemberRoles.HELPER, MemberRoles.ADMIN]
) )
async def warn_user(message: types.Message): async def warn_user(message: types.Message):
# Get information # Get information
@ -307,13 +300,13 @@ async def warn_user(message: types.Message):
await message.answer(( await message.answer((
f"[{from_user.first_name}](tg://user?id={from_user.user_id}) has warned " f"[{from_user.first_name}](tg://user?id={from_user.user_id}) has warned "
f"[{to_user.first_name}](tg://user?id={to_user.user_id})" f"[{to_user.first_name}](tg://user?id={to_user.user_id})"
), parse_mode="Markdown") ))
if (to_user.warns == config.limit_of_warns): if (to_user.warns == config.limit_of_warns):
await message.answer(( await message.answer((
f"[{from_user.first_name}](tg://user?id={from_user.user_id}) " f"[{from_user.first_name}](tg://user?id={from_user.user_id}) "
f"has banned {config.limit_of_warns}/{config.limit_of_warns} ⚠️ " f"has banned {config.limit_of_warns}/{config.limit_of_warns} ⚠️ "
), parse_mode="Markdown") ))
await bot.kick_chat_member( await bot.kick_chat_member(
chat_id=message.chat.id, chat_id=message.chat.id,
@ -329,9 +322,8 @@ async def warn_user(message: types.Message):
) )
@dp.message_handler( @dp.message(
commands=["reload"], Command("reload", prefix="!")
commands_prefix="!"
) )
async def reload(message: types.Message): async def reload(message: types.Message):
from utils import reload_users_data from utils import reload_users_data
@ -340,10 +332,9 @@ async def reload(message: types.Message):
await message.answer("Reloaded!") await message.answer("Reloaded!")
@dp.message_handler( @dp.message(
commands=["setrole"], Command("setrole", prefix="!"),
commands_prefix="!", AvailableRoles(MemberRoles.ADMIN)
available_roles=[MemberRoles.ADMIN]
) )
async def set_role(message: types.Message): async def set_role(message: types.Message):
command = await get_command_args(message) command = await get_command_args(message)
@ -373,4 +364,4 @@ async def set_role(message: types.Message):
await message.answer(( await message.answer((
f"{new_role.capitalize()} role set for " f"{new_role.capitalize()} role set for "
f"[{to_user.first_name}](tg://user?id={to_user.user_id})" f"[{to_user.first_name}](tg://user?id={to_user.user_id})"
), parse_mode="Markdown") ))

View File

@ -1,36 +1,42 @@
from load import dp, types, bot from load import dp, bot, types
from database import Member, Restriction from database import Member, Restriction
from aiogram.types import KeyboardButton, ReplyKeyboardMarkup
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from aiogram.types.reply_keyboard import ReplyKeyboardRemove
import config import config
from keyboards.default import menus
from aiogram.types import CallbackQuery from aiogram.utils.keyboard import InlineKeyboardBuilder, ReplyKeyboardBuilder
from aiogram.dispatcher.filters import Text from aiogram.fsm.context import FSMContext
from aiogram.types import ReplyKeyboardRemove
from aiogram.dispatcher.storage import FSMContext from aiogram.fsm.state import State, StatesGroup
from states.report_message import States
from keyboards.inline.report import report_callback from aiogram import F
from aiogram.filters import Command
from filters import ChatTypeFilter
@dp.message_handler( class ReportRestriction(StatesGroup):
commands=["start", "help"], state1 = State()
chat_type=[types.ChatType.PRIVATE] state2 = State()
@dp.message(
Command("start", "help"),
ChatTypeFilter("private")
) )
async def start_command_private(message: types.Message): async def start_command_private(message: types.Message):
bot_description_menu = ReplyKeyboardBuilder()
bot_description_menu.button(text="Check restrictions")
bot_description_menu.button(text="About Us")
await message.answer(( await message.answer((
f"Hi, **{message.from_user.first_name}**!\n" f"Hi, **{message.from_user.first_name}**!\n"
"My commands:\n" "My commands:\n"
"\t\t/help /start - read this message." "\t\t/help /start - read this message."
), parse_mode="Markdown", reply_markup=menus.bot_description_menu ), reply_markup=bot_description_menu.as_markup(resize_keyboard=True))
)
@dp.message_handler(Text(equals=["About Us"])) @dp.message(F.text == "About Us")
async def about_us(message: types.Message): async def about_us(message: types.Message):
await message.answer(( await message.answer((
"Moderator bot - an open source project for managing a Telegram group.\n\n" "Moderator bot - an open source project for managing a Telegram group.\n\n"
@ -41,15 +47,13 @@ async def about_us(message: types.Message):
"4. Users can report admins.\n" "4. Users can report admins.\n"
"5. Admins can give warnings to users.\n" "5. Admins can give warnings to users.\n"
"\nRelease version: 2.5.2\n" "\nRelease version: 2.5.2\n"
"[Github](https://github.com/hok7z/moderator-bot)"),parse_mode="Markdown" "[Github](https://github.com/hok7z/moderator-bot)")
) )
@dp.message_handler( @dp.message(F.text == "Check restrictions")
Text(equals=["Check restrictions"]), async def check_for_restrict(message: types.Message, state: FSMContext):
state=None await state.set_state(ReportRestriction.state1)
)
async def check_for_restrict(message: types.Message):
user = Member.get(Member.user_id == message.from_user.id) user = Member.get(Member.user_id == message.from_user.id)
restrictions = Restriction.select().where(Restriction.to_user == user) restrictions = Restriction.select().where(Restriction.to_user == user)
@ -58,14 +62,12 @@ async def check_for_restrict(message: types.Message):
return return
for restriction in restrictions: for restriction in restrictions:
callback = report_callback.new(restriction_id=restriction.id) markup = InlineKeyboardBuilder()
markup = InlineKeyboardMarkup() markup.button(
report_restriction = InlineKeyboardButton( text="✉️ Report restriction",
"✉️ Report restriction", callback_data=restriction.id
callback_data=callback
) )
markup.insert(report_restriction)
from_user = restriction.from_user from_user = restriction.from_user
to_user = restriction.to_user to_user = restriction.to_user
@ -87,34 +89,32 @@ async def check_for_restrict(message: types.Message):
restriction.text, restriction.text,
restriction.timestamp restriction.timestamp
), parse_mode="Markdown", reply_markup=markup ), reply_markup=markup.as_markup())
)
await States.state1.set() await state.set_state(ReportRestriction.state1)
@dp.callback_query_handler( @dp.callback_query(ReportRestriction.state1)
text_contains="report_restriction", async def report_restriction(call: types.CallbackQuery, state: FSMContext):
state=States.state1
)
async def report_restriction(call: CallbackQuery, state: FSMContext):
await call.answer(cache_time=60) await call.answer(cache_time=60)
callback_data = call.data callback_data = call.data
restriction_id = callback_data.split(":")[1] restriction_id = int(callback_data)
markup = ReplyKeyboardMarkup(resize_keyboard=True) cancel_markup = ReplyKeyboardBuilder()
cancel = KeyboardButton("❌ Cancel") cancel_markup.button(text="❌ Cancel")
markup.add(cancel)
await state.update_data(restriction_id=restriction_id) await state.update_data(restriction_id=restriction_id)
await call.message.answer("Please,enter your report.", reply_markup=markup) await call.message.answer(
"Please,enter your report",
reply_markup=cancel_markup.as_markup(resize_keyboard=True)
)
await States.next() await state.set_state(ReportRestriction.state2)
@dp.message_handler(state=States.state2) @dp.message(ReportRestriction.state2)
async def get_message_report(message: types.Message, state: FSMContext): async def get_message_report(message: types.Message, state: FSMContext):
answer = message.text answer = message.text
@ -126,7 +126,7 @@ async def get_message_report(message: types.Message, state: FSMContext):
from_user = restriction.from_user from_user = restriction.from_user
to_user = restriction.to_user to_user = restriction.to_user
restriction_timestamp = restriction.timestamp.strftime("%d.%m.%y at %H:%M (server time)") restriction_timestamp = restriction.timestamp.strftime("%d.%m.%y at %H:%M")
await bot.send_message(config.second_group_id, ( await bot.send_message(config.second_group_id, (
"Report on restriction #{}\n" "Report on restriction #{}\n"
@ -144,8 +144,7 @@ async def get_message_report(message: types.Message, state: FSMContext):
restriction.text, restriction.text,
restriction_timestamp, restriction_timestamp,
answer, answer,
), parse_mode="Markdown" ))
)
await message.answer( await message.answer(
"Report restriction sended", "Report restriction sended",
@ -157,4 +156,4 @@ async def get_message_report(message: types.Message, state: FSMContext):
reply_markup=ReplyKeyboardRemove() reply_markup=ReplyKeyboardRemove()
) )
await state.finish() await state.clear()

View File

@ -24,6 +24,7 @@ session = AiohttpSession(
bot = Bot( bot = Bot(
token=config.token, token=config.token,
session=session, session=session,
parse_mode="Markdown"
) )
dp = Dispatcher(storage=storage) dp = Dispatcher(storage=storage)

View File

View File

@ -1,6 +0,0 @@
from aiogram.dispatcher.filters.state import StatesGroup,State
class States(StatesGroup):
state1 = State()
state2 = State()

View File

@ -23,9 +23,8 @@ async def reload_users_data():
user.username = member["username"] user.username = member["username"]
user.save() user.save()
group = await bot.get_chat(config.group_id) group = await bot.get_chat(config.group_id)
group_permissions = dict(group["permissions"]) group_permissions = group.permissions.__dict__
for permission in group_permissions.keys(): for permission in group_permissions.keys():
config.group_permissions[permission] = group_permissions[permission] config.group_permissions[permission] = group_permissions[permission]