WiP-Fbans: Listf and Fbanp.

This commit is contained in:
thedragonsinn
2023-10-04 18:52:36 +05:30
parent 3c1f9e0f26
commit a8b52e6639

View File

@@ -27,12 +27,14 @@ class _User(User):
@bot.add_cmd(cmd="addf") @bot.add_cmd(cmd="addf")
async def add_fed(bot: bot, message: Message): async def add_fed(bot: bot, message: Message):
data = dict( data = dict(name=message.input or message.chat.title, type=str(message.chat.type))
name=message.input or message.chat.title, type=str(message.chat.type)
)
await add_data(collection=FEDS, id=message.chat.id, data=data) await add_data(collection=FEDS, id=message.chat.id, data=data)
await message.reply(f"<b>{data['name']}</b> added to FED LIST.", del_in=5, block=False) await message.reply(
await bot.log(text=f"#FBANS\n<b>{data['name']}</b> <code>{message.chat.id}</code> added to FED LIST.") f"<b>{data['name']}</b> added to FED LIST.", del_in=5, block=False
)
await bot.log(
text=f"#FBANS\n<b>{data['name']}</b> <code>{message.chat.id}</code> added to FED LIST."
)
@bot.add_cmd(cmd="delf") @bot.add_cmd(cmd="delf")
@@ -51,14 +53,18 @@ async def remove_fed(bot: bot, message: Message):
deleted: bool | None = await delete_data(collection=FEDS, id=chat) deleted: bool | None = await delete_data(collection=FEDS, id=chat)
if deleted: if deleted:
await message.reply( await message.reply(
f"<b>{name}</b><code>{chat}</code> removed from FED LIST.", del_in=8, block=False f"<b>{name}</b><code>{chat}</code> removed from FED LIST.",
del_in=8,
block=False,
)
await bot.log(
text=f"#FBANS\n<b>{name}</b><code>{chat}</code> removed from FED LIST."
) )
await bot.log(text=f"#FBANS\n<b>{name}</b><code>{chat}</code> removed from FED LIST.")
else: else:
await message.reply(f"<b>{name or chat}</b> not in FED LIST.", del_in=8) await message.reply(f"<b>{name or chat}</b> not in FED LIST.", del_in=8)
@bot.add_cmd(cmd="fban") @bot.add_cmd(cmd=["fban", "fbanp"])
async def fed_ban(bot: bot, message: Message): async def fed_ban(bot: bot, message: Message):
await message.delete() await message.delete()
progress: Message = await message.reply("") progress: Message = await message.reply("")
@@ -71,20 +77,24 @@ async def fed_ban(bot: bot, message: Message):
if user.id in Config.USERS: if user.id in Config.USERS:
await progress.edit("Cannot Fban Owner/Sudo users.") await progress.edit("Cannot Fban Owner/Sudo users.")
return return
proof_str: str = ""
if message.cmd == "fbanp":
if not message.replied:
await message.reply("Reply to a proof")
proof = await message.replied.forward(Config.FBAN_LOG_CHANNEL)
proof_str = "".join(["{ ", proof.link, " }"])
await progress.edit("") await progress.edit("")
total: int = 0 total: int = 0
failed: list[str] = [] failed: list[str] = []
cmd: str = f"/fban {user.mention} {reason}\n{proof_str}"
async for fed in FEDS.find(): async for fed in FEDS.find():
chat_id = int(fed["_id"]) chat_id = int(fed["_id"])
total += 1 total += 1
cmd: Message = await bot.send_message( cmd: Message = await bot.send_message(
chat_id=chat_id, chat_id=chat_id, text=cmd, disable_web_page_preview=True
text=f"/fban {user.mention} {reason}",
disable_web_page_preview=True,
)
response: Message | None = await cmd.get_response(
filters=(FILTERS), timeout=8
) )
response: Message | None = await cmd.get_response(filters=(FILTERS), timeout=8)
if not response or not (await FBAN_REGEX(bot, response)): if not response or not (await FBAN_REGEX(bot, response)):
failed.append(fed["name"]) failed.append(fed["name"])
elif "Would you like to update this reason" in response.text: elif "Would you like to update this reason" in response.text:
@@ -107,3 +117,18 @@ async def fed_ban(bot: bot, message: Message):
@bot.add_cmd(cmd="unfban") @bot.add_cmd(cmd="unfban")
async def un_fban(bot: bot, message: Message): async def un_fban(bot: bot, message: Message):
... ...
@bot.add_cmd(cmd="listf")
async def fed_list(bot: bot, message: Message):
output: str = "List of Connected Feds:\n\n"
total = 0
async for fed in DB.FED_LIST.find():
output += f'<b>• {fed["name"]}</b>\n'
if "-id" in message.flags:
output += f' <code>{fed["_id"]}</code>\n'
total += 1
if not total:
await message.reply("You don't have any Feds Connected.")
return
await message.reply(output, del_in=30, block=False)