mirror of
https://github.com/Nick80835/microbot
synced 2025-08-31 06:26:04 +00:00
rework how commands are processed, implement sudo commands
This commit is contained in:
@@ -10,22 +10,22 @@ from ubot.micro_bot import micro_bot
|
||||
ldr = micro_bot.loader
|
||||
|
||||
|
||||
#@ldr.add(pattern="reload")
|
||||
@ldr.add(pattern="reload", sudo=True)
|
||||
async def reload_modules(event):
|
||||
await event.edit("`Reloading modules…`")
|
||||
reload_msg = await event.reply("`Reloading modules…`")
|
||||
|
||||
errors = ldr.reload_all_modules()
|
||||
|
||||
if errors:
|
||||
await event.edit(errors)
|
||||
await reload_msg.edit(errors)
|
||||
else:
|
||||
try:
|
||||
await event.delete()
|
||||
await reload_msg.edit("`Successfully reloaded.`")
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
@ldr.add(pattern="alive")
|
||||
@ldr.add(pattern="alive", sudo=True)
|
||||
async def alive(event):
|
||||
alive_format = "`μBot is running under {0}.\n\n" \
|
||||
"Version: {1}\n" \
|
||||
@@ -35,39 +35,12 @@ async def alive(event):
|
||||
await event.reply(alive_format.format(uname().node, ldr.botversion, version.__version__, python_version()))
|
||||
|
||||
|
||||
#@ldr.add(pattern="shutdown")
|
||||
@ldr.add(pattern="shutdown", sudo=True)
|
||||
async def shutdown(event):
|
||||
await event.edit("`Goodbye…`")
|
||||
await event.reply("`Goodbye…`")
|
||||
await micro_bot.stop_client()
|
||||
|
||||
|
||||
#@ldr.add(pattern="prefix")
|
||||
async def change_prefix(event):
|
||||
new_prefix = event.pattern_match.group(1)
|
||||
|
||||
if not new_prefix:
|
||||
await event.edit("`Please specify a valid command prefix!`")
|
||||
return
|
||||
|
||||
micro_bot.settings.set_config("cmd_prefix", new_prefix)
|
||||
errors = ldr.reload_all_modules()
|
||||
|
||||
if errors:
|
||||
await event.edit(f"`Command prefix successfully changed to `**{new_prefix}**` but there were errors:`\n\n{errors}")
|
||||
else:
|
||||
await event.edit(f"`Command prefix successfully changed to `**{new_prefix}**`!`")
|
||||
|
||||
|
||||
@ldr.add(pattern="repo")
|
||||
async def bot_repo(event):
|
||||
await event.reply("https://github.com/Nick80835/microbot")
|
||||
|
||||
|
||||
#@ldr.add(pattern="toggleincoming")
|
||||
async def toggleincoming(event):
|
||||
if micro_bot.settings.get_bool("incoming_allowed"):
|
||||
micro_bot.settings.set_config("incoming_allowed", "False")
|
||||
await event.edit("`Successfully disabled incoming commands!`")
|
||||
else:
|
||||
micro_bot.settings.set_config("incoming_allowed", "True")
|
||||
await event.edit("`Successfully enabled incoming commands!`")
|
||||
|
Reference in New Issue
Block a user