implemented general help command and command specific help
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -158,3 +158,6 @@ cython_debug/
|
|||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
# My stuff
|
||||||
|
data/
|
||||||
|
|||||||
18
bot.py
Normal file
18
bot.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
from discord.ext import commands
|
||||||
|
import config
|
||||||
|
from cogs.music.main import music
|
||||||
|
|
||||||
|
cogs = [
|
||||||
|
music
|
||||||
|
]
|
||||||
|
|
||||||
|
class Astro(commands.Bot):
|
||||||
|
|
||||||
|
# Once the bot is up and running
|
||||||
|
async def on_ready(self):
|
||||||
|
# Set the status
|
||||||
|
await self.change_presence(activity=config.get_status())
|
||||||
|
|
||||||
|
# Setup commands
|
||||||
|
for cog in cogs:
|
||||||
|
await self.add_cog(cog(self))
|
||||||
23
cogs/music/main.py
Normal file
23
cogs/music/main.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import discord
|
||||||
|
from discord.ext import commands
|
||||||
|
from discord.ext.commands.context import Context
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
import pytz
|
||||||
|
|
||||||
|
class music(commands.Cog):
|
||||||
|
def __init__(self, client):
|
||||||
|
self.name = "🎶 Music"
|
||||||
|
self.emoji = "🎶"
|
||||||
|
self.client = client
|
||||||
|
|
||||||
|
@commands.command(
|
||||||
|
help="Displays latency from the bot",
|
||||||
|
aliases=['delay'])
|
||||||
|
async def ping(self, e: Context):
|
||||||
|
start_time = datetime.datetime.now(pytz.utc)
|
||||||
|
end_time = e.message.created_at
|
||||||
|
|
||||||
|
delay = int((end_time - start_time).total_seconds() * 1000)
|
||||||
|
|
||||||
|
await e.send(f"Pong! `{delay}MS`")
|
||||||
15
config.py
15
config.py
@@ -2,6 +2,7 @@
|
|||||||
# This file should parse all configurations within the bot
|
# This file should parse all configurations within the bot
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
from discord import Color
|
||||||
import json
|
import json
|
||||||
|
|
||||||
# Read data from JSON file in ./data/config.json
|
# Read data from JSON file in ./data/config.json
|
||||||
@@ -48,6 +49,18 @@ def get_status():
|
|||||||
data.get('link')
|
data.get('link')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Get colors from colorscheme
|
||||||
|
def get_color(color):
|
||||||
|
data = read_data()
|
||||||
|
|
||||||
|
if data is False or data.get('status') is False:
|
||||||
|
raise Exception("Missing config data: color")
|
||||||
|
|
||||||
|
# Grab color
|
||||||
|
string_value = data.get("colorscheme").get(color)
|
||||||
|
hex_value = Color.from_str(string_value)
|
||||||
|
return hex_value
|
||||||
|
|
||||||
|
|
||||||
# Taking JSON variables and converting them into a presence
|
# Taking JSON variables and converting them into a presence
|
||||||
# Use None url incase not provided
|
# Use None url incase not provided
|
||||||
@@ -63,7 +76,7 @@ def translate_status(status_type, status_text, status_url=None):
|
|||||||
return discord.Activity(
|
return discord.Activity(
|
||||||
type=discord.ActivityType.streaming,
|
type=discord.ActivityType.streaming,
|
||||||
name=status_text,
|
name=status_text,
|
||||||
url=status_link
|
url=status_url
|
||||||
)
|
)
|
||||||
|
|
||||||
elif status_type == "listening":
|
elif status_type == "listening":
|
||||||
|
|||||||
79
help.py
79
help.py
@@ -1,23 +1,76 @@
|
|||||||
|
from collections.abc import Mapping
|
||||||
|
from typing import List
|
||||||
import discord
|
import discord
|
||||||
|
from discord.app_commands import Command
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
from discord.ext.commands.cog import Cog
|
||||||
|
import config
|
||||||
|
|
||||||
class AstroHelp(commands.HelpCommand):
|
class AstroHelp(commands.MinimalHelpCommand):
|
||||||
|
|
||||||
# Help regular
|
def __init__(self):
|
||||||
async def send_bot_help(self, mapping):
|
super().__init__()
|
||||||
await self.context.send("This is help")
|
self.command_attrs = {
|
||||||
|
'name': "help",
|
||||||
|
'aliases': ["commands", "?"],
|
||||||
|
'cooldown': commands.CooldownMapping.from_cooldown(2, 5.0, commands.BucketType.user)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Help with specific command
|
# Called when using help no args
|
||||||
|
async def send_bot_help(self, mapping: Mapping[Cog, List[Command]]):
|
||||||
|
|
||||||
|
# Our embed message
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Help",
|
||||||
|
color=config.get_color("main"))
|
||||||
|
embed.add_field(name="",
|
||||||
|
value="Use `help <command>` or `help <category>` for more details",
|
||||||
|
inline=False)
|
||||||
|
|
||||||
|
embed.set_footer(text=f"Prefix: {self.context.prefix}")
|
||||||
|
|
||||||
|
# grabs iterable of (Cog, list[Command])
|
||||||
|
for cog, commands in mapping.items():
|
||||||
|
|
||||||
|
# Grab commands only the user can access
|
||||||
|
# Safe to ignore warning
|
||||||
|
filtered = await self.filter_commands(commands, sort=True)
|
||||||
|
|
||||||
|
# For each command we grab the signature
|
||||||
|
command_signatures = [
|
||||||
|
# Rmove prefix and format command name
|
||||||
|
f"``{self.get_command_signature(c)[1:]}``" for c in filtered]
|
||||||
|
|
||||||
|
# Check if cog has any commands
|
||||||
|
if command_signatures:
|
||||||
|
|
||||||
|
# Use get incase cog is None
|
||||||
|
cog_name = getattr(cog, "name", "No Category")
|
||||||
|
|
||||||
|
# Add cog section to help message
|
||||||
|
embed.add_field(
|
||||||
|
name=f"{cog_name}",
|
||||||
|
value="\n".join(command_signatures),
|
||||||
|
inline=True)
|
||||||
|
|
||||||
|
# Display message
|
||||||
|
channel = self.get_destination()
|
||||||
|
await channel.send(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
|
# Help for specific command
|
||||||
async def send_command_help(self, command):
|
async def send_command_help(self, command):
|
||||||
await self.context.send(f"You asked for help with: {command}")
|
|
||||||
|
|
||||||
|
embed = discord.Embed(
|
||||||
|
title=self.get_command_signature(command)[1:],
|
||||||
|
color=config.get_color("main"))
|
||||||
|
embed.set_footer(text=f"Prefix: {self.context.prefix}")
|
||||||
|
embed.add_field(name="Description", value=command.help)
|
||||||
|
|
||||||
# Help for a group
|
alias = command.aliases
|
||||||
async def send_group_help(self, group):
|
if alias:
|
||||||
await self.context.send(f"This is a group: {group}")
|
embed.add_field(name="Aliases", value=", ".join(alias), inline=False)
|
||||||
|
|
||||||
|
channel = self.get_destination()
|
||||||
# Help for cog
|
await channel.send(embed=embed)
|
||||||
async def send_cog_help(self, cog):
|
|
||||||
await self.context.send(f"This is a cog: {cog}")
|
|
||||||
|
|||||||
17
main.py
17
main.py
@@ -1,22 +1,9 @@
|
|||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from bot import Astro
|
||||||
import config
|
import config
|
||||||
import help
|
import help
|
||||||
|
|
||||||
cogs = []
|
client = Astro(command_prefix=config.get_prefix(), intents=discord.Intents.all())
|
||||||
|
|
||||||
class Serenity(commands.Bot):
|
|
||||||
|
|
||||||
# Once the bot is up and running
|
|
||||||
async def on_ready(self):
|
|
||||||
# Set the status
|
|
||||||
await self.change_presence(activity=config.get_status())
|
|
||||||
|
|
||||||
# Setup commands
|
|
||||||
for cog in cogs:
|
|
||||||
await cog.setup(self)
|
|
||||||
|
|
||||||
client = Serenity(command_prefix=config.get_prefix(), intents=discord.Intents.all())
|
|
||||||
client.help_command = help.AstroHelp()
|
client.help_command = help.AstroHelp()
|
||||||
|
|
||||||
client.run(config.get_login("dev"))
|
client.run(config.get_login("dev"))
|
||||||
|
|||||||
Reference in New Issue
Block a user