Added help command
This commit is contained in:
parent
5a440d91ab
commit
75d5a3c664
8 changed files with 119 additions and 9 deletions
20
bot.py
20
bot.py
|
@ -23,7 +23,7 @@ logging.info(f"Total {total}, Failed {failed}\n")
|
||||||
client = commands.Bot(command_prefix=config.settings["prefix"], case_insensitive=True)
|
client = commands.Bot(command_prefix=config.settings["prefix"], case_insensitive=True)
|
||||||
|
|
||||||
|
|
||||||
@client.command()
|
@client.command(name="load", description="Loads a cog", usage="load <Cog>")
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
async def load(ctx : commands.Context, extension : str):
|
async def load(ctx : commands.Context, extension : str):
|
||||||
try:
|
try:
|
||||||
|
@ -32,7 +32,7 @@ async def load(ctx : commands.Context, extension : str):
|
||||||
except:
|
except:
|
||||||
await ctx.message.add_reaction("👎")
|
await ctx.message.add_reaction("👎")
|
||||||
|
|
||||||
@client.command()
|
@client.command(name="unload", description="Unoads a cog", usage="unload <Cog>")
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
async def unload(ctx : commands.Context, extension : str):
|
async def unload(ctx : commands.Context, extension : str):
|
||||||
try:
|
try:
|
||||||
|
@ -41,7 +41,7 @@ async def unload(ctx : commands.Context, extension : str):
|
||||||
except:
|
except:
|
||||||
await ctx.message.add_reaction("👎")
|
await ctx.message.add_reaction("👎")
|
||||||
|
|
||||||
@client.command()
|
@client.command(name="reload", description="Reoads a cog", usage="reload <Cog>")
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
async def reload(ctx : commands.Context, extension : str):
|
async def reload(ctx : commands.Context, extension : str):
|
||||||
try:
|
try:
|
||||||
|
@ -59,6 +59,20 @@ async def on_ready():
|
||||||
total = 0
|
total = 0
|
||||||
failed = 0
|
failed = 0
|
||||||
# Load all cogs on startup
|
# Load all cogs on startup
|
||||||
|
for filename in os.listdir("./cogs"):
|
||||||
|
if filename.endswith(".py"):
|
||||||
|
total += 1
|
||||||
|
cog = f"cogs.{filename[:-3]}"
|
||||||
|
|
||||||
|
try:
|
||||||
|
client.load_extension(cog)
|
||||||
|
logging.info(f"Trying {cog}.....Success!")
|
||||||
|
except Exception as e:
|
||||||
|
logging.info(f"Trying {cog}.....Failed!")
|
||||||
|
logging.error(str(e))
|
||||||
|
failed += 1
|
||||||
|
|
||||||
|
|
||||||
# Load "fun" cogs
|
# Load "fun" cogs
|
||||||
for filename in os.listdir("./cogs/fun"):
|
for filename in os.listdir("./cogs/fun"):
|
||||||
if filename.endswith(".py"):
|
if filename.endswith(".py"):
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Inspirobot(commands.Cog):
|
||||||
def __init__(self, client : discord.Client):
|
def __init__(self, client : discord.Client):
|
||||||
self.client = client
|
self.client = client
|
||||||
|
|
||||||
@commands.command(name="Inspirobot", description="Sends a randomly generated inspirational quote", aliases=["inspiration", "inspiro"])
|
@commands.command(name="inspirobot", description="Sends a randomly generated inspirational quote", usage="inspirobot", aliases=["inspiration", "inspiro"])
|
||||||
@commands.cooldown(1, 5)
|
@commands.cooldown(1, 5)
|
||||||
async def inspirobot(self, ctx : commands.Context):
|
async def inspirobot(self, ctx : commands.Context):
|
||||||
image = inspirobot.get_inspirational_quote()
|
image = inspirobot.get_inspirational_quote()
|
||||||
|
|
|
@ -12,7 +12,7 @@ class Nasa(commands.Cog):
|
||||||
def __init__(self, client: discord.Client):
|
def __init__(self, client: discord.Client):
|
||||||
self.client = client
|
self.client = client
|
||||||
|
|
||||||
@commands.command(name="APOD", description="Posts NASA's picture of the day.")
|
@commands.command(name="apod", description="Posts NASA's picture of the day.", usage="apod")
|
||||||
@commands.cooldown(1, 30)
|
@commands.cooldown(1, 30)
|
||||||
async def apod(self, ctx: commands.Context):
|
async def apod(self, ctx: commands.Context):
|
||||||
url = nasa.image_of_the_day()
|
url = nasa.image_of_the_day()
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Steam(commands.Cog):
|
||||||
def __init__(self, client: discord.Client):
|
def __init__(self, client: discord.Client):
|
||||||
self.client = client
|
self.client = client
|
||||||
|
|
||||||
@commands.command(name="SteamLevel", description="Finds the steam level of a user", usage="SteamLevel <Vanity URL>", aliases=["level"])
|
@commands.command(name="steamlevel", description="Finds the steam level of a user", usage="steamlevel <Vanity URL>", aliases=["level"])
|
||||||
@commands.cooldown(1, 2)
|
@commands.cooldown(1, 2)
|
||||||
async def SteamLevel(self, ctx: commands.Context, vanity_url: str):
|
async def SteamLevel(self, ctx: commands.Context, vanity_url: str):
|
||||||
level = steam.get_steam_level(vanity_url)
|
level = steam.get_steam_level(vanity_url)
|
||||||
|
|
|
@ -19,6 +19,9 @@ class Translation(commands.Cog):
|
||||||
return
|
return
|
||||||
|
|
||||||
response = translation.translate(text, code)
|
response = translation.translate(text, code)
|
||||||
|
if len(response) == 0:
|
||||||
|
await ctx.send(embed=embed.make_error_embed(f"The translation API doesn't support **{language}**."))
|
||||||
|
return
|
||||||
translated = response[0]
|
translated = response[0]
|
||||||
direction = response[1].split("-")
|
direction = response[1].split("-")
|
||||||
_from = translation.ISO_to_name(direction[0])
|
_from = translation.ISO_to_name(direction[0])
|
||||||
|
|
|
@ -12,7 +12,7 @@ class Coinflip(commands.Cog):
|
||||||
def __init__(self, client: discord.Client):
|
def __init__(self, client: discord.Client):
|
||||||
self.client = client
|
self.client = client
|
||||||
|
|
||||||
@commands.command(name="coinflip", description="Flips a coin and reacts with the result", aliases=["coin", "flip"])
|
@commands.command(name="coinflip", description="Flips a coin and reacts with the result", usage="coin", aliases=["coin", "flip"])
|
||||||
async def coinflip(self, ctx: commands.Context):
|
async def coinflip(self, ctx: commands.Context):
|
||||||
if random.randint(0, 1) == 0:
|
if random.randint(0, 1) == 0:
|
||||||
await ctx.message.add_reaction("🌑")
|
await ctx.message.add_reaction("🌑")
|
||||||
|
|
80
cogs/help.py
Normal file
80
cogs/help.py
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
import discord
|
||||||
|
from discord.ext import commands
|
||||||
|
from util import config, embed, logging
|
||||||
|
|
||||||
|
class SetupHelp(commands.Cog):
|
||||||
|
def __init__(self, client: discord.Client):
|
||||||
|
self.client = client
|
||||||
|
self._original_help_command = client.help_command
|
||||||
|
client.help_command = Help()
|
||||||
|
client.help_command.cog = self
|
||||||
|
|
||||||
|
class Help(commands.MinimalHelpCommand):
|
||||||
|
async def command_not_found(self, string: str):
|
||||||
|
await self.context.send(embed=embed.make_error_embed("Command not found"))
|
||||||
|
|
||||||
|
async def subcommand_not_found(self, command, string):
|
||||||
|
await self.context.send(embed=embed.make_error_embed("Command not found"))
|
||||||
|
|
||||||
|
async def send_cog_help(self, cog):
|
||||||
|
await self.context.send(embed=embed.make_error_embed("Command not found"))
|
||||||
|
|
||||||
|
async def send_group_help(self, group):
|
||||||
|
await self.context.send(embed=embed.make_error_embed("Command not found"))
|
||||||
|
|
||||||
|
async def send_command_help(self, command):
|
||||||
|
try:
|
||||||
|
alias = ""
|
||||||
|
if command.aliases != []:
|
||||||
|
for i in range(len(command.aliases)):
|
||||||
|
if i == len(command.aliases) - 1:
|
||||||
|
alias = alias + '`' + command.aliases[i] + '`'
|
||||||
|
else:
|
||||||
|
alias = alias + '`' + command.aliases[i] + '`' + ', '
|
||||||
|
else:
|
||||||
|
alias = "`None`"
|
||||||
|
|
||||||
|
await self.context.send(embed=embed.make_embed_fields_ninl(command.name, command.description, ("Usage", f"`{config.settings['prefix']}{command.usage}`"), ("Aliases", alias)))
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(str(e))
|
||||||
|
await self.context.send(embed=embed.make_error_embed("Command not found"))
|
||||||
|
|
||||||
|
|
||||||
|
async def send_bot_help(self, mapping):
|
||||||
|
# get list of commands
|
||||||
|
cmds = []
|
||||||
|
prefix = config.settings['prefix']
|
||||||
|
|
||||||
|
for cog, cog_commands in mapping.items():
|
||||||
|
cmds = cmds + cog_commands
|
||||||
|
|
||||||
|
newCmds = []
|
||||||
|
for item in cmds:
|
||||||
|
newCmds.append(str(item))
|
||||||
|
newCmds = sorted(newCmds)
|
||||||
|
|
||||||
|
finalCmds = []
|
||||||
|
for item in newCmds:
|
||||||
|
try:
|
||||||
|
finalCmds.append(item)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
cmdString = ""
|
||||||
|
if len(finalCmds) != 0:
|
||||||
|
for i in range(len(finalCmds)):
|
||||||
|
if i == len(finalCmds)-1:
|
||||||
|
cmdString = cmdString + '`' + finalCmds[i] + '`'
|
||||||
|
else:
|
||||||
|
cmdString = cmdString + '`' + finalCmds[i] + '`' + ', '
|
||||||
|
|
||||||
|
|
||||||
|
if cmdString != "":
|
||||||
|
await self.context.send(embed=embed.make_embed_field('Help', f'To get further information about a command use `{prefix}help <Command>`', "Commands", cmdString, inline=False))
|
||||||
|
else:
|
||||||
|
await self.context.send(embed=embed.make_error_embed("No commands found."))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def setup(client: discord.Client):
|
||||||
|
client.add_cog(SetupHelp(client))
|
|
@ -9,7 +9,20 @@ def make_embed(title: str, desc: str) -> discord.Embed:
|
||||||
embed = discord.Embed(title=title, description=desc, colour=int(config.settings["color"], 16))
|
embed = discord.Embed(title=title, description=desc, colour=int(config.settings["color"], 16))
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
def make_embed_field(title: str, desc: str, field_name: str, field_val: str) -> discord.Embed:
|
def make_embed_field(title: str, desc: str, field_name: str, field_val: str, inline: bool = True) -> discord.Embed:
|
||||||
embed = discord.Embed(title=title, description=desc, colour=int(config.settings["color"], 16))
|
embed = discord.Embed(title=title, description=desc, colour=int(config.settings["color"], 16))
|
||||||
embed.add_field(name=field_name, value=field_val)
|
embed.add_field(name=field_name, value=field_val, inline=inline)
|
||||||
|
return embed
|
||||||
|
|
||||||
|
def make_embed_fields(title: str, desc: str, *fields: tuple) -> discord.Embed:
|
||||||
|
embed = discord.Embed(title=title, description=desc, colour=int(config.settings["color"], 16))
|
||||||
|
for name, value in fields:
|
||||||
|
embed.add_field(name=name, value=value)
|
||||||
|
return embed
|
||||||
|
|
||||||
|
|
||||||
|
def make_embed_fields_ninl(title: str, desc: str, *fields: tuple) -> discord.Embed:
|
||||||
|
embed = discord.Embed(title=title, description=desc, colour=int(config.settings["color"], 16), inline=False)
|
||||||
|
for name, value in fields:
|
||||||
|
embed.add_field(name=name, value=value)
|
||||||
return embed
|
return embed
|
Loading…
Add table
Add a link
Reference in a new issue