File size: 5,618 Bytes
a8e9b84 4f7440f a8e9b84 71c7dff 4f7440f 71c7dff 4f7440f 71c7dff a8e9b84 71c7dff 4f7440f 71c7dff 4f7440f 71c7dff a8e9b84 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
import asyncio
from pyrogram import filters
from pyrogram.errors import FloodWait, PeerIdInvalid
from pyrogram.types import Message
from DragMusic import app
from DragMusic.misc import SUDOERS
from DragMusic.utils import get_readable_time
from DragMusic.utils.database import (
add_banned_user,
get_banned_count,
get_banned_users,
get_served_chats,
is_banned_user,
remove_banned_user,
is_on_off
)
from DragMusic.utils.decorators.language import language
from DragMusic.utils.extraction import extract_user
from config import BANNED_USERS, LOGGER_ID
@app.on_message(filters.command(["gban", "globalban"]) & SUDOERS)
@language
async def global_ban(client, message: Message, _):
if not message.reply_to_message:
if len(message.command) != 2:
return await message.reply_text(_["general_1"])
user = message.command[1]
if user.isdigit():
user = int(user)
else:
user = user.replace("@", "")
try:
user = await app.get_users(user)
except PeerIdInvalid:
return await message.reply_text("Invalid user ID or username. Please check and try again.")
else:
user = await extract_user(message)
if user.id == message.from_user.id:
return await message.reply_text(_["gban_1"])
elif user.id == app.id:
return await message.reply_text(_["gban_2"])
elif user.id in SUDOERS:
return await message.reply_text(_["gban_3"])
is_gbanned = await is_banned_user(user.id)
if is_gbanned:
return await message.reply_text(_["gban_4"].format(user.mention))
if user.id not in BANNED_USERS:
BANNED_USERS.add(user.id)
served_chats = []
chats = await get_served_chats()
for chat in chats:
served_chats.append(int(chat["chat_id"]))
time_expected = get_readable_time(len(served_chats))
mystic = await message.reply_text(_["gban_5"].format(user.mention, time_expected))
number_of_chats = 0
for chat_id in served_chats:
try:
await app.ban_chat_member(chat_id, user.id)
number_of_chats += 1
except FloodWait as fw:
await asyncio.sleep(int(fw.value))
except:
continue
await add_banned_user(user.id)
if await is_on_off(2):
await app.send_message(
chat_id=LOGGER_ID,
text=f"{message.from_user.mention} has globally banned {user.mention}.\n"
f"User ID: <code>{user.id}</code>\n"
f"Banned in {number_of_chats} chats.",
message_thread_id=12357
)
await message.reply_text(
_["gban_6"].format(
app.mention,
message.chat.title,
message.chat.id,
user.mention,
user.id,
message.from_user.mention,
number_of_chats,
)
)
await mystic.delete()
@app.on_message(filters.command(["ungban"]) & SUDOERS)
@language
async def global_un(client, message: Message, _):
if not message.reply_to_message:
if len(message.command) != 2:
return await message.reply_text(_["general_1"])
user = message.command[1]
if user.isdigit():
user = int(user)
else:
user = user.replace("@", "")
try:
user = await app.get_users(user)
except PeerIdInvalid:
return await message.reply_text("Invalid user ID or username. Please check and try again.")
else:
user = await extract_user(message)
is_gbanned = await is_banned_user(user.id)
if not is_gbanned:
return await message.reply_text(_["gban_7"].format(user.mention))
if user.id in BANNED_USERS:
BANNED_USERS.remove(user.id)
served_chats = []
chats = await get_served_chats()
for chat in chats:
served_chats.append(int(chat["chat_id"]))
time_expected = get_readable_time(len(served_chats))
mystic = await message.reply_text(_["gban_8"].format(user.mention, time_expected))
number_of_chats = 0
for chat_id in served_chats:
try:
await app.unban_chat_member(chat_id, user.id)
number_of_chats += 1
except FloodWait as fw:
await asyncio.sleep(int(fw.value))
except:
continue
await remove_banned_user(user.id)
if await is_on_off(2):
await app.send_message(
chat_id=LOGGER_ID,
text=f"{message.from_user.mention} has unbanned {user.mention}.\n"
f"User ID: <code>{user.id}</code>\n"
f"Unbanned from {number_of_chats} chats.",
message_thread_id=12357
)
await message.reply_text(_["gban_9"].format(user.mention, number_of_chats))
await mystic.delete()
@app.on_message(filters.command(["gbannedusers", "gbanlist"]) & SUDOERS)
@language
async def gbanned_list(client, message: Message, _):
counts = await get_banned_count()
if counts == 0:
return await message.reply_text(_["gban_10"])
mystic = await message.reply_text(_["gban_11"])
msg = _["gban_12"]
count = 0
users = await get_banned_users()
for user_id in users:
count += 1
try:
user = await app.get_users(user_id)
user = user.first_name if not user.mention else user.mention
msg += f"{count}➤ {user}\n"
except Exception:
msg += f"{count}➤ {user_id}\n"
continue
if count == 0:
return await mystic.edit_text(_["gban_10"])
else:
return await mystic.edit_text(msg)
|