Skip to content

Commit

Permalink
improve cmd detection in help + filter risky cmds with addscmd -all
Browse files Browse the repository at this point in the history
  • Loading branch information
rking32 committed Feb 5, 2022
1 parent fe2a482 commit fd3f9ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
19 changes: 10 additions & 9 deletions userge/plugins/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ async def helpme(message: Message) -> None: # pylint: disable=missing-function-
f" 📚 <b>info:</b> <i>{cmd.doc}</i>\n\n")
out_str += f"""📕 <b>Usage:</b> <code>{Config.CMD_TRIGGER}help [command_name]</code>"""
else:
commands = userge.manager.enabled_commands
key = key.lstrip(Config.CMD_TRIGGER)
key_ = Config.CMD_TRIGGER + key
if key in commands:
out_str = f"<code>{key}</code>\n\n{commands[key].about}"
elif key_ in commands:
out_str = f"<code>{key_}</code>\n\n{commands[key_].about}"
else:
out_str = f"<i>No Module or Command Found for</i>: <code>{message.input_str}</code>"
triggers = (Config.CMD_TRIGGER, Config.SUDO_TRIGGER, Config.PUBLIC_TRIGGER)
for _ in triggers:
key = key.lstrip(_)
out_str = f"<i>No Module or Command Found for</i>: <code>{message.input_str}</code>"
for name, cmd in userge.manager.enabled_commands.items():
for _ in triggers:
name = name.lstrip(_)
if key == name:
out_str = f"<code>{cmd.name}</code>\n\n{cmd.about}"
break
await message.edit(out_str, del_in=0, parse_mode='html', disable_web_page_preview=True)

if userge.has_bot:
Expand Down
3 changes: 3 additions & 0 deletions userge/plugins/tools/sudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ async def add_sudo_cmd(message: Message):
await SUDO_CMDS_COLLECTION.drop()
Config.ALLOWED_COMMANDS.clear()
tmp_ = []
restricted = ('addsudo', 'addscmd', 'exec', 'eval', 'term')
for c_d in list(userge.manager.enabled_commands):
t_c = c_d.lstrip(Config.CMD_TRIGGER)
if t_c in restricted:
continue
tmp_.append({'_id': t_c})
Config.ALLOWED_COMMANDS.add(t_c)
await asyncio.gather(
Expand Down

0 comments on commit fd3f9ec

Please sign in to comment.