bugfix: fbans: catch fban errors and not exit the process
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,3 +8,4 @@ conf_backup/
|
||||
logs/
|
||||
.mypy_cache
|
||||
psutil
|
||||
app/temp
|
||||
@@ -2,6 +2,7 @@ import asyncio
|
||||
|
||||
from pyrogram import filters
|
||||
from pyrogram.enums import ChatMemberStatus, ChatType
|
||||
from pyrogram.errors import UserNotParticipant
|
||||
from pyrogram.types import Chat, User
|
||||
from ub_core.utils.helpers import get_name
|
||||
|
||||
@@ -116,6 +117,7 @@ async def fed_ban(bot: BOT, message: Message):
|
||||
reason = f"{reason}{proof_str}"
|
||||
|
||||
if message.replied and message.chat.type != ChatType.PRIVATE:
|
||||
try:
|
||||
me = await bot.get_chat_member(chat_id=message.chat.id, user_id="me")
|
||||
if me.status in {ChatMemberStatus.OWNER, ChatMemberStatus.ADMINISTRATOR}:
|
||||
await message.replied.reply(
|
||||
@@ -124,6 +126,8 @@ async def fed_ban(bot: BOT, message: Message):
|
||||
del_in=3,
|
||||
block=False,
|
||||
)
|
||||
except UserNotParticipant:
|
||||
pass
|
||||
|
||||
fban_cmd: str = f"/fban <a href='tg://user?id={user_id}'>{user_id}</a> {reason}"
|
||||
|
||||
@@ -198,19 +202,27 @@ async def perform_fed_task(
|
||||
chat_id = int(fed["_id"])
|
||||
total += 1
|
||||
|
||||
try:
|
||||
cmd: Message = await bot.send_message(
|
||||
chat_id=chat_id, text=command, disable_web_page_preview=True
|
||||
)
|
||||
|
||||
response: Message | None = await cmd.get_response(
|
||||
filters=task_filter, timeout=8
|
||||
)
|
||||
|
||||
if not response:
|
||||
failed.append(fed["name"])
|
||||
elif "Would you like to update this reason" in response.text:
|
||||
await response.click("Update reason")
|
||||
|
||||
except Exception as e:
|
||||
await bot.log_text(
|
||||
text=f"An Error occured while banning in fed: {fed['name']} [{chat_id}]"
|
||||
f"\nError: {e}",
|
||||
type=task_type.upper(),
|
||||
)
|
||||
failed.append(fed["name"])
|
||||
continue
|
||||
|
||||
await asyncio.sleep(1)
|
||||
|
||||
if not total:
|
||||
@@ -239,9 +251,11 @@ async def perform_fed_task(
|
||||
text=resp_str,
|
||||
disable_web_page_preview=True,
|
||||
)
|
||||
|
||||
await progress.edit(
|
||||
text=resp_str, del_in=5, block=True, disable_web_page_preview=True
|
||||
)
|
||||
|
||||
await handle_sudo_fban(command=command)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user