1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 18:03:12 +00:00

Make a custom Racu help feature

This commit is contained in:
wlinator 2024-03-17 13:59:13 +01:00
parent 454e7f88ae
commit 9a067594ce
6 changed files with 104 additions and 68 deletions

View file

@ -86,7 +86,7 @@ async def on_member_join(member):
@client.event
async def on_application_command_completion(ctx) -> None:
async def on_command_completion(ctx) -> None:
"""
This code is executed when a slash_command has been successfully executed.
This technically serves as a CommandHandler function
@ -112,7 +112,7 @@ async def on_application_command_completion(ctx) -> None:
@client.event
async def on_application_command_error(ctx, error) -> None:
async def on_command_error(ctx, error) -> None:
if isinstance(error, commands.CommandOnCooldown):
seconds = error.retry_after

View file

@ -11,12 +11,13 @@ from main import strings
logs = logging.getLogger('Racu.Core')
class ConfigCog(commands.Cog):
class Config(commands.Cog):
def __init__(self, client):
self.client = client
# COMMAND GROUPS
config = SlashCommandGroup("config", "server config commands.", guild_only=True, default_member_permissions=discord.Permissions(manage_guild=True))
config = SlashCommandGroup("config", "server config commands.", guild_only=True,
default_member_permissions=discord.Permissions(manage_guild=True))
birthday_config = config.create_subgroup(name="birthdays")
command_config = config.create_subgroup(name="commands")
intro_config = config.create_subgroup(name="intros")
@ -347,7 +348,5 @@ class ConfigCog(commands.Cog):
return await ctx.respond(embed=embed)
def setup(client):
client.add_cog(ConfigCog(client))
client.add_cog(Config(client))

46
modules/miscellaneous.py Normal file
View file

@ -0,0 +1,46 @@
import logging
from discord.ext import commands, bridge
import datetime, time
from main import strings
from lib import checks
logs = logging.getLogger('Racu.Core')
class Miscellaneous(commands.Cog):
def __init__(self, client):
self.client = client
self.start_time = time.time()
@bridge.bridge_command(
name="ping",
aliases=["p", "status"],
description="Simple status check.",
help="Simple status check, this command will not return the latency of the bot process as this is "
"fairly irrelevant. If the bot replies, it's good to go.",
guild_only=True
)
@commands.check(checks.channel)
async def ping(self, ctx):
await ctx.respond(content=strings["ping"].format(ctx.author.name))
@bridge.bridge_command(
name="uptime",
description="Racu uptime",
help="See how long Racu has been online, the uptime shown will reset when the Misc module is reloaded.",
guild_only=True
)
@commands.check(checks.channel)
async def uptime(self, ctx):
current_time = time.time()
difference = int(round(current_time - self.start_time))
text = str(datetime.timedelta(seconds=difference))
await ctx.respond(content=strings["uptime"].format(ctx.author.name, text))
def setup(client):
client.add_cog(Miscellaneous(client))

View file

@ -1,27 +0,0 @@
import logging
from discord.ext import commands, bridge
from main import strings
from lib import checks
logs = logging.getLogger('Racu.Core')
class PingCog(commands.Cog):
def __init__(self, client):
self.client = client
@bridge.bridge_command(
name="ping",
aliases=["p"],
description="Simple status check.",
guild_only=True
)
@commands.check(checks.channel)
async def ping(self, ctx):
await ctx.respond(content=strings["ping"].format(ctx.author.name))
def setup(client):
client.add_cog(PingCog(client))

View file

@ -1,28 +0,0 @@
from discord.ext import commands
import datetime, time
from main import strings
from lib import checks
class UptimeCog(commands.Cog):
def __init__(self, client):
self.client = client
self.start_time = time.time()
@commands.slash_command(
name="uptime",
description="Simple status check.",
guild_only=True
)
@commands.check(checks.channel)
async def uptime(self, ctx):
current_time = time.time()
difference = int(round(current_time - self.start_time))
text = str(datetime.timedelta(seconds=difference))
await ctx.respond(content=strings["uptime"].format(ctx.author.name, text))
def setup(client):
client.add_cog(UptimeCog(client))

View file

@ -2,9 +2,55 @@ import discord
from discord.ext import commands
class RacuHelp(commands.MinimalHelpCommand):
async def send_pages(self):
destination = self.get_destination()
for page in self.paginator.pages:
embed = discord.Embed(description=page)
await destination.send(embed=embed)
class RacuHelp(commands.HelpCommand):
def get_command_signature(self, command):
return '%s%s %s' % (self.context.clean_prefix, command.qualified_name, command.signature)
def get_command_qualified_name(self, command):
return '%s%s' % (self.context.clean_prefix, command.qualified_name)
async def send_bot_help(self, mapping):
embed = discord.Embed(title="Help", color=discord.Color.blurple())
for cog, commands in mapping.items():
filtered = await self.filter_commands(commands, sort=True)
if command_signatures := [
self.get_command_qualified_name(c) for c in filtered
]:
# Remove duplicates using set() and convert back to a list
unique_command_signatures = list(set(command_signatures))
cog_name = getattr(cog, "qualified_name", "Help")
embed.add_field(name=cog_name, value="\n".join(unique_command_signatures), inline=False)
channel = self.get_destination()
await channel.send(embed=embed)
async def send_command_help(self, command):
embed = discord.Embed(title=f"{self.context.clean_prefix}{command.qualified_name}",
color=discord.Color.blurple())
if command.help:
embed.description = command.help
if alias := command.aliases:
embed.add_field(name="Aliases", value=", ".join(alias), inline=False)
if command.signature:
embed.add_field(name="Usage",
value='%s%s %s' % (self.context.clean_prefix, command.qualified_name, command.signature))
channel = self.get_destination()
await channel.send(embed=embed)
async def send_help_embed(self, title, description, commands): # a helper function to add commands to an embed
embed = discord.Embed(title=title, description=description or "No help found...")
if filtered_commands := await self.filter_commands(commands):
for command in filtered_commands:
embed.add_field(name=self.get_command_signature(command), value=command.help or "No help found...")
await self.get_destination().send(embed=embed)
async def send_group_help(self, group):
title = self.get_command_signature(group)
await self.send_help_embed(title, group.help, group.commands)
async def send_cog_help(self, cog):
title = cog.qualified_name or "No"
await self.send_help_embed(f'{title} Category', cog.description, cog.get_commands())