Fix peer id invalid in gban

This commit is contained in:
yasirarism 2023-06-16 15:50:16 +00:00 committed by GitHub
parent fb9a5eacea
commit da24e65623
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,6 +25,7 @@ from psutil import virtual_memory, cpu_count, boot_time, net_io_counters
from pyrogram import enums, filters, Client, __version__ as pyrover from pyrogram import enums, filters, Client, __version__ as pyrover
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message, InputMediaPhoto from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message, InputMediaPhoto
from pyrogram.raw.types import UpdateBotStopped from pyrogram.raw.types import UpdateBotStopped
from pyrogram.errors import PeerIdInvalid
from pykeyboard import InlineKeyboard, InlineButton from pykeyboard import InlineKeyboard, InlineButton
from PIL import Image, ImageDraw, ImageFont from PIL import Image, ImageDraw, ImageFont
@ -216,21 +217,27 @@ async def ban_globally(self: Client, ctx: Message):
if not reason: if not reason:
return await ctx.reply("No reason provided.") return await ctx.reply("No reason provided.")
user = await app.get_users(user_id) try:
user = await app.get_users(user_id)
user_mention = user.mention
user_id = user.id
except PeerIdInvalid:
user_mention = int(user_id)
user_id = int(user_id)
from_user = ctx.from_user from_user = ctx.from_user
if user_id in [from_user.id, self.me.id] or user_id in SUDO: if user_id in [from_user.id, self.me.id] or user_id in SUDO:
return await ctx.reply_text("I can't ban that user.") return await ctx.reply_text("I can't ban that user.")
served_chats = await db.get_all_chats() served_chats = await db.get_all_chats()
m = await ctx.reply_text( m = await ctx.reply_text(
f"**Banning {user.mention} Globally!**" f"**Banning {user} Globally! This may take several times.**"
+ f" **This Action Should Take About {len(served_chats)} Seconds.**"
) )
await add_gban_user(user_id) await add_gban_user(user_id)
number_of_chats = 0 number_of_chats = 0
for served_chat in served_chats: for served_chat in served_chats:
try: try:
await app.ban_chat_member(served_chat["chat_id"], user.id) await app.ban_chat_member(served_chat["id"], user_id)
number_of_chats += 1 number_of_chats += 1
await asyncio.sleep(1) await asyncio.sleep(1)
except FloodWait as e: except FloodWait as e:
@ -239,18 +246,18 @@ async def ban_globally(self: Client, ctx: Message):
pass pass
try: try:
await app.send_message( await app.send_message(
user.id, user_id,
f"Hello, You have been globally banned by {from_user.mention}," f"Hello, You have been globally banned by {from_user.mention},"
+ " You can appeal for this ban by talking to him.", + " You can appeal for this ban by talking to him.",
) )
except Exception: except Exception:
pass pass
await m.edit(f"Banned {user.mention} Globally!") await m.edit(f"Banned {user_mention} Globally!")
ban_text = f""" ban_text = f"""
__**New Global Ban**__ __**New Global Ban**__
**Origin:** {message.chat.title} [`{message.chat.id}`] **Origin:** {message.chat.title} [`{message.chat.id}`]
**Admin:** {from_user.mention} **Admin:** {from_user.mention}
**Banned User:** {user.mention} **Banned User:** {user_mention}
**Banned User ID:** `{user_id}` **Banned User ID:** `{user_id}`
**Reason:** __{reason}__ **Reason:** __{reason}__
**Chats:** `{number_of_chats}`""" **Chats:** `{number_of_chats}`"""
@ -261,7 +268,7 @@ __**New Global Ban**__
disable_web_page_preview=True, disable_web_page_preview=True,
) )
await m.edit( await m.edit(
f"Banned {user.mention} Globally!\nAction Log: {m2.link}", f"Banned {user_mention} Globally!\nAction Log: {m2.link}",
disable_web_page_preview=True, disable_web_page_preview=True,
) )
except Exception: except Exception:
@ -276,14 +283,20 @@ async def unban_globally(self: Client, ctx: Message):
user_id = await extract_user(ctx) user_id = await extract_user(ctx)
if not user_id: if not user_id:
return await ctx.reply_text("I can't find that user.") return await ctx.reply_text("I can't find that user.")
user = await app.get_users(user_id) try:
user = await app.get_users(user_id)
user_mention = user.mention
user_id = user.id
except PeerIdInvalid:
user_mention = int(user_id)
user_id = int(user_id)
is_gbanned = await is_gbanned_user(user.id) is_gbanned = await is_gbanned_user(user_id)
if not is_gbanned: if not is_gbanned:
await ctx.reply_text("I don't remember Gbanning him.") await ctx.reply_text("I don't remember Gbanning him.")
else: else:
await remove_gban_user(user.id) await remove_gban_user(user)
await ctx.reply_text(f"Lifted {user.mention}'s Global Ban.'") await ctx.reply_text(f"Lifted {user_mention}'s Global Ban.'")
@app.on_message(filters.command(["shell", "sh", "term"], COMMAND_HANDLER) & filters.user(SUDO)) @app.on_message(filters.command(["shell", "sh", "term"], COMMAND_HANDLER) & filters.user(SUDO))