diff --git a/ubot/command_handler.py b/ubot/command_handler.py index 8e9fd77..82e52ec 100644 --- a/ubot/command_handler.py +++ b/ubot/command_handler.py @@ -3,7 +3,7 @@ import asyncio from re import escape, search -from telethon import events +from telethon import events, types class CommandHandler(): @@ -29,6 +29,9 @@ class CommandHandler(): if value["sudo"] and str(event.from_id) not in self.settings.get_config("owner_id").split(","): print(f"Attempted sudo command ({event.text}) from ID {event.from_id}") continue + elif value["admin"] and str(event.from_id) not in self.settings.get_config("owner_id").split(",") and not await self.check_admin(event): + print(f"Attempted admin command ({event.text}) from ID {event.from_id}") + continue event.pattern_match = pattern_match event.args = pattern_match.groups()[-1] @@ -122,3 +125,10 @@ class CommandHandler(): return await coro except: return + + async def check_admin(self, event): + async for user in event.client.iter_participants(event.chat, limit=10000, filter=types.ChannelParticipantsAdmins): + if user.id == event.from_id: + return True + + return False diff --git a/ubot/loader.py b/ubot/loader.py index 65eb13c..edb11ac 100644 --- a/ubot/loader.py +++ b/ubot/loader.py @@ -63,7 +63,9 @@ class Loader(): "function": func, "noprefix": args.get('noprefix', False), "sudo": args.get('sudo', False), - "extras": args.get('extras', None) + "extras": args.get('extras', None), + "nsfw": args.get('nsfw', False), + "admin": args.get('admin', False) } return func diff --git a/ubot/modules/system.py b/ubot/modules/system.py index 50c7db2..a1e2da7 100644 --- a/ubot/modules/system.py +++ b/ubot/modules/system.py @@ -90,3 +90,22 @@ async def ping(event): @ldr.add("repo") async def bot_repo(event): await event.reply("https://github.com/Nick80835/microbot") + + +@ldr.add("nsfw", admin=True) +async def nsfw_toggle(event): + if not event.args or event.args not in ("on", "off"): + if str(event.chat.id) not in ldr.settings.get_list("nsfw_blacklist"): + current_config = 'On' + else: + current_config = 'Off' + + await event.reply(f"Syntax: {ldr.settings.get_config('cmd_prefix') or '.'}nsfw (on|off)\nCurrent config for this chat: {current_config}") + return + + if event.args == "on": + ldr.settings.remove_from_list("nsfw_blacklist", event.chat.id) + await event.reply("NSFW commands disabled for this chat!") + elif event.args == "off": + ldr.settings.add_to_list("nsfw_blacklist", event.chat.id) + await event.reply("NSFW commands enabled for this chat!")