Skip to content
This repository was archived by the owner on Jan 17, 2023. It is now read-only.

Commit adfb136

Browse files
author
Benjamin O'Brien
committed
Fix and clean up the help command
1 parent 45fd627 commit adfb136

File tree

1 file changed

+52
-88
lines changed

1 file changed

+52
-88
lines changed

commands/misc/help.py

Lines changed: 52 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import inspect
44

55
import importlib
6-
from json import loads
7-
86
from os import listdir
97

108
from assets.prism import Tools
@@ -15,10 +13,10 @@ class Help(commands.Cog):
1513

1614
def __init__(self, bot):
1715
self.bot = bot
18-
self.desc = "Prism's help command, making life easy"
19-
self.usage = "help [category]"
16+
self.desc = "The help command, listing commands and providing details."
17+
self.usage = "help [category/command]"
2018

21-
def get_commands(self, ctx, category):
19+
def get_commands(self, category):
2220

2321
commands = ""
2422

@@ -30,127 +28,93 @@ def get_commands(self, ctx, category):
3028

3129
return f"``{commands[2:]}``"
3230

33-
async def embed(self, ctx, cat, prefix, commandClass = None):
34-
35-
embed = None
31+
@commands.command(aliases = ["info", "commands", "cmds"])
32+
async def help(self, ctx, *, category = None):
3633

37-
if cat == "default":
34+
if not category:
3835

3936
embed = discord.Embed(title = "The Prism Discord Bot", description = "The only discord bot you actually need.", url = "https://top.gg/bot/685550504276787200", color = 0x126bf1)
4037

41-
embed.add_field(name = ":person_golfing: Entertainment Commands :person_golfing:", value = f"See commands with ``{prefix}help entertain``", inline = False)
38+
embed.add_field(name = ":person_golfing: Entertainment Commands :person_golfing:", value = f"See commands with ``{ctx.prefix}help fun``", inline = False)
4239

43-
embed.add_field(name = ":cat: Pet Commands :dog:", value = f"See commands with ``{prefix}help pets``", inline = False)
40+
embed.add_field(name = ":cat: Pet Commands :dog:", value = f"See commands with ``{ctx.prefix}help pets``", inline = False)
4441

45-
embed.add_field(name = ":moneybag: Currency Commands :moneybag:", value = f"See commands with ``{prefix}help currency``", inline = False)
42+
embed.add_field(name = ":musical_note: Music Commands (beta) :musical_note:", value = f"See commands with ``{ctx.prefix}help music``", inline = False)
4643

47-
embed.add_field(name = ":tools: Moderation Commands :tools:", value = f"See commands with ``{prefix}help mod``", inline = False)
44+
embed.add_field(name = ":moneybag: Currency Commands :moneybag:", value = f"See commands with ``{ctx.prefix}help currency``", inline = False)
4845

49-
embed.add_field(name = ":newspaper: Miscellaneous Commands :newspaper:", value = f"See commands with ``{prefix}help misc``", inline = False)
46+
embed.add_field(name = ":tools: Moderation Commands :tools:", value = f"See commands with ``{ctx.prefix}help mod``", inline = False)
5047

51-
elif cat == "entertainment":
48+
embed.add_field(name = ":newspaper: Miscellaneous Commands :newspaper:", value = f"See commands with ``{ctx.prefix}help misc``", inline = False)
5249

50+
elif category.lower() in ["fun", "entertain", "entertainment"]:
51+
5352
embed = discord.Embed(title = ":person_golfing: Entertainment Commands :person_golfing:", description = "The most interesting and unique commands out there.", color = 0x126bf1)
5453

55-
embed.add_field(name = "Commands", value = self.get_commands(ctx, cat), inline = False)
56-
57-
elif cat == "misc":
58-
54+
embed.add_field(name = "Commands", value = self.get_commands("entertainment"), inline = False)
55+
56+
elif category.lower() == "misc":
57+
5958
embed = discord.Embed(title = ":newspaper: Miscellaneous Commands :newspaper:", description = "The commands that cannot be described.", color = 0x126bf1)
6059

61-
embed.add_field(name = "Commands", value = self.get_commands(ctx, cat), inline = False)
62-
63-
elif cat == "pets":
64-
60+
embed.add_field(name = "Commands", value = self.get_commands("misc"), inline = False)
61+
62+
elif category.lower() == "pets":
63+
6564
embed = discord.Embed(title = ":cat: Pet Commands :dog:", description = "Time to go walk the dog, (digitally of course lmao).", color = 0x126bf1)
6665

67-
embed.add_field(name = "Commands", value = self.get_commands(ctx, cat), inline = False)
66+
embed.add_field(name = "Commands", value = self.get_commands("pets"), inline = False)
6867

69-
elif cat == "currency":
68+
elif category.lower() == "music":
69+
70+
embed = discord.Embed(title = ":musical_note: Music Commands :musical_note:", description = "Is it just me, or did low quality audio arrive?", color = 0x126bf1)
7071

72+
embed.add_field(name = "Commands", value = self.get_commands("music"), inline = False)
73+
74+
elif category.lower() in ["currency", "economy"]:
75+
7176
embed = discord.Embed(title = ":moneybag: Currency Commands :moneybag:", description = "Go get a job you little lazy man.", color = 0x126bf1)
7277

73-
embed.add_field(name = "Commands", value = self.get_commands(ctx, cat), inline = False)
74-
75-
elif cat == "moderation":
76-
78+
embed.add_field(name = "Commands", value = self.get_commands("currency"), inline = False)
79+
80+
elif category.lower() in ["mod", "moderation"]:
81+
7782
embed = discord.Embed(title = ":tools: Moderation Commands :tools:", description = "Somebody causing problems? Don't worry about it mate.", color = 0x126bf1)
7883

79-
embed.add_field(name = "Commands", value = self.get_commands(ctx, cat), inline = False)
80-
84+
embed.add_field(name = "Commands", value = self.get_commands("moderation"), inline = False)
85+
8186
else:
8287

83-
embed = discord.Embed(title = f"{cat} Command", description = f"{commandClass.desc}; usage: {commandClass.usage}", color = 0x126bf1)
88+
command_path = None
8489

85-
embed.set_author(name = " | Help", icon_url = self.bot.user.avatar_url)
90+
for folder in listdir("commands"):
8691

87-
embed.set_footer(text = f" | Requested by {ctx.author}.", icon_url = ctx.author.avatar_url)
88-
89-
return embed
92+
for file in listdir(f"commands/{folder}"):
9093

91-
@commands.command(aliases = ["info", "commands", "cmds"])
92-
async def help(self, ctx, *, category = None):
94+
if file.endswith(".py") and file[:-3].lower() == category.lower():
9395

94-
if ctx.guild:
96+
command_path = f"commands.{folder}.{file[:-3]}"
9597

96-
db = loads(open("db/guilds", "r").read())
98+
if not command_path:
9799

98-
prefix = db[str(ctx.guild.id)]["prefix"]
100+
return await ctx.send(embed = Tools.error("That command/category could not be found."))
99101

100-
else:
102+
command = importlib.import_module(command_path)
101103

102-
prefix = "p!"
104+
for class_ in inspect.getmembers(command, inspect.isclass):
103105

104-
if not category:
106+
if class_[0].lower() == category.lower():
105107

106-
return await ctx.send(embed = await self.embed(ctx, "default", prefix))
108+
called = class_[1](self.bot)
107109

108-
elif category.lower() in ["fun", "entertain", "entertainment"]:
109-
110-
return await ctx.send(embed = await self.embed(ctx, "entertainment", prefix))
111-
112-
elif category.lower() == "misc":
113-
114-
return await ctx.send(embed = await self.embed(ctx, "misc", prefix))
115-
116-
elif category.lower() == "pets":
117-
118-
return await ctx.send(embed = await self.embed(ctx, "pets", prefix))
119-
120-
elif category.lower() in ["currency", "economy"]:
121-
122-
return await ctx.send(embed = await self.embed(ctx, "currency", prefix))
123-
124-
elif category.lower() in ["mod", "moderation"]:
125-
126-
return await ctx.send(embed = await self.embed(ctx, "moderation", prefix))
127-
128-
else:
129-
130-
for command_folder in listdir("commands"):
131-
132-
for command in listdir(f"commands/{command_folder}"):
133-
134-
if f"{category.lower()}.py" == command:
135-
136-
command_module = importlib.import_module(f"commands.{command_folder}.{command[:-3]}")
137-
138-
for name, obj in inspect.getmembers(command_module):
139-
140-
if inspect.isclass(obj):
141-
142-
try:
143-
144-
commandClass = obj(self.bot)
145-
146-
except:
110+
embed = discord.Embed(title = class_[0] + " Command", description = f"{called.desc}\nUsage: {called.usage}", color = 0x126bf1)
147111

148-
return await ctx.send(embed = Tools.error("That command is bugged (so stay tuned)."))
112+
embed.set_author(name = " | Help", icon_url = self.bot.user.avatar_url)
149113

150-
return await ctx.send(embed = await self.embed(ctx, Tools.uppercase(category), prefix, commandClass))
114+
embed.set_footer(text = f" | Requested by {ctx.author}.", icon_url = ctx.author.avatar_url)
151115

152-
return await ctx.send(embed = await self.embed(ctx, "default", prefix))
116+
return await ctx.send(embed = embed)
153117

154118
# Link to bot
155119
def setup(bot):
156-
bot.add_cog(Help(bot))
120+
bot.add_cog(Help(bot))

0 commit comments

Comments
 (0)