mirror of
https://github.com/Nick80835/microbot
synced 2025-08-22 10:09:40 +00:00
add support for NSFW toggles and admin-level commands
This commit is contained in:
parent
f352ad0e32
commit
252fb65aa9
@ -3,7 +3,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from re import escape, search
|
from re import escape, search
|
||||||
|
|
||||||
from telethon import events
|
from telethon import events, types
|
||||||
|
|
||||||
|
|
||||||
class CommandHandler():
|
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(","):
|
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}")
|
print(f"Attempted sudo command ({event.text}) from ID {event.from_id}")
|
||||||
continue
|
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.pattern_match = pattern_match
|
||||||
event.args = pattern_match.groups()[-1]
|
event.args = pattern_match.groups()[-1]
|
||||||
@ -122,3 +125,10 @@ class CommandHandler():
|
|||||||
return await coro
|
return await coro
|
||||||
except:
|
except:
|
||||||
return
|
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
|
||||||
|
@ -63,7 +63,9 @@ class Loader():
|
|||||||
"function": func,
|
"function": func,
|
||||||
"noprefix": args.get('noprefix', False),
|
"noprefix": args.get('noprefix', False),
|
||||||
"sudo": args.get('sudo', 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
|
return func
|
||||||
|
@ -90,3 +90,22 @@ async def ping(event):
|
|||||||
@ldr.add("repo")
|
@ldr.add("repo")
|
||||||
async def bot_repo(event):
|
async def bot_repo(event):
|
||||||
await event.reply("https://github.com/Nick80835/microbot")
|
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!")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user