38 lines
991 B
Python
38 lines
991 B
Python
import re
|
|
from html import escape
|
|
|
|
from ..functions import reply
|
|
from ..models import Message
|
|
|
|
|
|
def init(bot):
|
|
bot.on_command({"help", "usage"}, handle)
|
|
|
|
|
|
async def handle(message: Message):
|
|
bot = message.app
|
|
plugins = {k: p for k, p in bot.plugins.items() if hasattr(p, "HELP")}
|
|
|
|
pname = message.args.str(0)
|
|
if pname not in plugins:
|
|
modnames = ", ".join(f"<code>{m}</code>" for m in sorted(plugins.keys()))
|
|
await reply(message, html=f"Help is available for: {modnames}")
|
|
return
|
|
|
|
me = f"@{message.my_name}: "
|
|
pfix = bot.config.command_prefix
|
|
|
|
plugin = plugins[pname]
|
|
usage: str = plugin.HELP
|
|
usage = re.sub(
|
|
"^(!|@me: )", lambda m: pfix if m[1] == "!" else me, usage, flags=re.M
|
|
)
|
|
|
|
lines = usage.splitlines(False)
|
|
usage = (
|
|
f"<i>{escape(lines[0])}</i><br>\n<code>"
|
|
+ "<br>\n".join(escape(l) for l in lines[1:])
|
|
+ "</code>"
|
|
)
|
|
|
|
await reply(message, html=usage, in_thread=True)
|