from pyrogram import filters from pyrogram.types import Message from wbb import SUDOERS, app from wbb.core.decorators.errors import capture_err from wbb.utils.dbfunctions import ( blacklist_chat, blacklisted_chats, whitelist_chat, ) __MODULE__ = "群组访问黑名单" __HELP__ = """ **此功能仅供超级管理员使用** /blacklist_chat [群组 ID] - 将群组加入访问黑名单。 /whitelist_chat [群组 ID] - 将群组移出访问黑名单。 /blacklisted_chats - 查看群组访问黑名单。 """ @app.on_message(filters.command("blacklist_chat") & SUDOERS) @capture_err async def blacklist_chat_func(_, message: Message): if len(message.command) != 2: return await message.reply_text( "**用法:**\n/blacklist_chat [群组 ID]" ) chat_id = int(message.text.strip().split()[1]) if chat_id in await blacklisted_chats(): return await message.reply_text("该群组已在访问黑名单中。") blacklisted = await blacklist_chat(chat_id) if blacklisted: return await message.reply_text( "已将该群组加入访问黑名单。" ) await message.reply_text("操作失败,请检查运行日志。") @app.on_message(filters.command("whitelist_chat") & SUDOERS) @capture_err async def whitelist_chat_func(_, message: Message): if len(message.command) != 2: return await message.reply_text( "**用法:**\n/whitelist_chat [群组 ID]" ) chat_id = int(message.text.strip().split()[1]) if chat_id not in await blacklisted_chats(): return await message.reply_text("该群组不在访问黑名单中。") whitelisted = await whitelist_chat(chat_id) if whitelisted: return await message.reply_text( "已将该群组移出访问黑名单。" ) await message.reply_text("操作失败,请检查运行日志。") @app.on_message(filters.command("blacklisted_chats") & SUDOERS) @capture_err async def blacklisted_chats_func(_, message: Message): text = "" for count, chat_id in enumerate(await blacklisted_chats(), 1): try: title = (await app.get_chat(chat_id)).title except Exception: title = "未知群组" text += f"**{count}. {title}** [`{chat_id}`]\n" if text == "": return await message.reply_text("群组访问黑名单为空。") await message.reply_text(text)