Fix /leave command

This commit is contained in:
hok7z 2022-11-06 16:57:15 +02:00
parent d390d2ebe9
commit 0706448755
1 changed files with 18 additions and 20 deletions

View File

@ -3,26 +3,6 @@ from load import bot, dp, types
import config import config
from database import Member from database import Member
@dp.message_handler(commands=["leave"],chat_type=[types.ChatType.SUPERGROUP])
async def leave_group(message:types.Message):
user = message.from_user
args = message.text.split()
# TODO: translate it too
if (len(args) < 1) or not ( ' '.join(args[1:]) == "I UNDERSTAND" ):
await message.answer("Для того чтобы покинуть чат вам нужно ввести /leave I UNDERSTANT!")
return
# TODO: rewrite it
# database.delete_user(user.id)
# Ban user and save (bool)
status = await bot.kick_chat_member(chat_id=message.chat.id,user_id=user.id,until_date=None)
if status:
await message.answer(f"User [{user.first_name}](tg://user?id={user.id}) has laved chat forever.",
parse_mode="Markdown")
@dp.message_handler(commands=["start","help"],chat_type=[types.ChatType.SUPERGROUP]) @dp.message_handler(commands=["start","help"],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((
@ -33,6 +13,24 @@ async def start_command_group(message:types.Message):
parse_mode="Markdown" parse_mode="Markdown"
) )
@dp.message_handler(commands=["leave"],chat_type=[types.ChatType.SUPERGROUP])
async def leave_group(message:types.Message):
user = message.from_user
arguments = message.get_args()
if (arguments != "I UNDERSTAND!"):
await message.answer("use /leave I UNDERSTAND")
return
Member.delete().where(Member.user_id == user.id).execute()
# Ban user and save (bool)
status = await bot.kick_chat_member(chat_id=message.chat.id,user_id=user.id,until_date=None)
if status:
await message.answer(f"User [{user.first_name}](tg://user?id={user.id}) has laved chat forever",parse_mode="Markdown")
Member.delete().where(Member.user_id == user.id).execute()
@dp.message_handler(commands=["bio","me"],chat_type=[types.ChatType.SUPERGROUP]) @dp.message_handler(commands=["bio","me"],chat_type=[types.ChatType.SUPERGROUP])
async def get_information(message: types.Message): async def get_information(message: types.Message):