/
help.py
76 lines (57 loc) · 2.24 KB
/
help.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import asyncio
import pyrogram.enums.parse_mode
from prettytable import PrettyTable
from pyrogram import filters
from pyrogram.types import Message
from userbot import CMD_HELP, UserBot
from userbot.helpers.utility import split_list
heading = "──「 **{0}** 」──\n"
@UserBot.on_message(filters.command("help", ".") & filters.me)
async def module_help(bot: UserBot, message: Message):
cmd = message.command
help_arg = ""
if len(cmd) > 1:
help_arg = " ".join(cmd[1:])
elif message.reply_to_message and len(cmd) == 1:
help_arg = message.reply_to_message.text
elif not message.reply_to_message and len(cmd) == 1:
all_commands = ""
all_commands += "Please specify which module you want help for!! \nUsage: `.help [module_name]`\n\n"
ac = PrettyTable()
ac.header = False
ac.title = "UserBot Modules"
ac.align = "l"
for x in split_list(sorted(CMD_HELP.keys()), 2):
ac.add_row([x[0], x[1] if len(x) >= 2 else None])
await message.edit(f"```{str(ac)}```")
if help_arg:
if help_arg in CMD_HELP:
commands: dict = CMD_HELP[help_arg]
this_command = "**Help for**\n"
this_command += heading.format(str(help_arg)).upper()
for x in commands:
this_command += f"-> `{str(x)}`\n```{str(commands[x])}```\n"
await message.edit(this_command, parse_mode=pyrogram.enums.ParseMode.MARKDOWN)
else:
await message.edit(
"`Please specify a valid module name.`", parse_mode=pyrogram.enums.ParseMode.MARKDOWN
)
await asyncio.sleep(10)
await message.delete()
def add_command_help(module_name, commands):
"""
Adds a modules help information.
:param module_name: name of the module
:param commands: list of lists, with command and description each.
"""
# Key will be group name
# values will be dict of dicts of key command and value description
if module_name in CMD_HELP.keys():
command_dict = CMD_HELP[module_name]
else:
command_dict = {}
for x in commands:
for y in x:
if y is not x:
command_dict[x[0]] = x[1]
CMD_HELP[module_name] = command_dict