|
|
@@ -0,0 +1,91 @@
|
|
|
+"""
|
|
|
+MIT License
|
|
|
+
|
|
|
+Copyright (c) 2021 TheHamkerCat
|
|
|
+
|
|
|
+Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
+of this software and associated documentation files (the "Software"), to deal
|
|
|
+in the Software without restriction, including without limitation the rights
|
|
|
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
+copies of the Software, and to permit persons to whom the Software is
|
|
|
+furnished to do so, subject to the following conditions:
|
|
|
+
|
|
|
+The above copyright notice and this permission notice shall be included in all
|
|
|
+copies or substantial portions of the Software.
|
|
|
+
|
|
|
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
+SOFTWARE.
|
|
|
+"""
|
|
|
+from wbb import app2, SUDOERS, USERBOT_ID, BOT_ID, USERBOT_PREFIX
|
|
|
+from wbb.core.decorators.errors import capture_err
|
|
|
+from wbb.utils.dbfunctions import add_sudo, remove_sudo, get_sudoers
|
|
|
+from wbb.modules.userbot import edit_or_reply
|
|
|
+from pyrogram import filters
|
|
|
+from pyrogram.types import Message
|
|
|
+import asyncio
|
|
|
+
|
|
|
+__MODULE__ = "Sudo"
|
|
|
+__HELP__ = """
|
|
|
+**THIS MODULE IS ONLY FOR DEVS**
|
|
|
+
|
|
|
+.useradd - To Add A User In Sudoers.
|
|
|
+.userdel - To Remove A User From Sudoers.
|
|
|
+.sudoers - To List Sudo Users.
|
|
|
+
|
|
|
+**NOTE:**
|
|
|
+
|
|
|
+Never add anyone to sudoers unless you trust them,
|
|
|
+sudo users can do anything with your account, they
|
|
|
+can even delete your account.
|
|
|
+"""
|
|
|
+
|
|
|
+
|
|
|
+@app2.on_message(filters.command("useradd", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS))
|
|
|
+async def useradd(_, message):
|
|
|
+ if not message.reply_to_message:
|
|
|
+ await edit_or_reply(message, text="Reply to someone's message to add him to sudoers.")
|
|
|
+ return
|
|
|
+ user_id = message.reply_to_message.from_user.id
|
|
|
+ sudoers = await get_sudoers()
|
|
|
+ if user_id in sudoers:
|
|
|
+ await edit_or_reply(message, text="User is already in sudoers.")
|
|
|
+ return
|
|
|
+ added = await add_sudo(user_id)
|
|
|
+ if added:
|
|
|
+ await edit_or_reply(message, text="Successfully added user in sudoers, Bot will be restarted now.")
|
|
|
+ os.execvp("python3", ["python3", "-m", "wbb"])
|
|
|
+ return
|
|
|
+ await edit_or_reply(message, text="Something wrong happened, check logs.")
|
|
|
+
|
|
|
+
|
|
|
+@app2.on_message(filters.command("userdel", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS))
|
|
|
+async def userdel(_, message):
|
|
|
+ if not message.reply_to_message:
|
|
|
+ await edit_or_reply(message, text="Reply to someone's message to remove him to sudoers.")
|
|
|
+ return
|
|
|
+ user_id = message.reply_to_message.from_user.id
|
|
|
+ if user_id not in await get_sudoers():
|
|
|
+ await edit_or_reply(message, text="User is not in sudoers.")
|
|
|
+ return
|
|
|
+ removed = await remove_sudo(user_id)
|
|
|
+ if removed:
|
|
|
+ await edit_or_reply(message, text="Successfully removed user from sudoers, Bot will be restarted now.")
|
|
|
+ os.execvp("python3", ["python3", "-m", "wbb"])
|
|
|
+ return
|
|
|
+ await edit_or_reply(message, text="Something wrong happened, check logs.")
|
|
|
+
|
|
|
+
|
|
|
+@app2.on_message(filters.command("sudoers", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS))
|
|
|
+async def sudoers_list(_, message):
|
|
|
+ sudoers = await get_sudoers()
|
|
|
+ text = ""
|
|
|
+ for count, user_id in enumerate(sudoers, 1):
|
|
|
+ user = await app2.get_users(user_id)
|
|
|
+ user = user.first_name if not user.mention else user.mention
|
|
|
+ text += f"{count}. {user}\n"
|
|
|
+ await edit_or_reply(message, text=text)
|