diff --git a/cogs/fun.py b/cogs/fun.py index ca4338f..8d7a381 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -1,4 +1,4 @@ -from data import paginatedLeaderboard +from data.menus import paginatedLeaderboard from decorators import help import discord from discord.ext import commands diff --git a/cogs/leaderboards.py b/cogs/leaderboards.py index 1d39daf..724bf54 100644 --- a/cogs/leaderboards.py +++ b/cogs/leaderboards.py @@ -1,4 +1,4 @@ -from data import paginatedLeaderboard +from data.menus import paginatedLeaderboard from decorators import help import discord from discord.ext import commands diff --git a/cogs/modCommands.py b/cogs/modCommands.py index 24e6a95..ab24afb 100644 --- a/cogs/modCommands.py +++ b/cogs/modCommands.py @@ -5,11 +5,10 @@ from discord.ext import commands from enums.help_categories import Category from functions import checks, config, timeFormatters from functions.database import memes, githubs, twitch, dadjoke +from functions.database.custom_commands import add_command, add_alias import json import os -from functions.database.custom_commands import is_name_free, add_command, add_alias - class ModCommands(commands.Cog): diff --git a/cogs/other.py b/cogs/other.py new file mode 100644 index 0000000..3e0bfd7 --- /dev/null +++ b/cogs/other.py @@ -0,0 +1,30 @@ +from discord.ext import commands +from data.menus import custom_commands +from decorators import help +from enums.help_categories import Category +from functions.database.custom_commands import get_all +from functions.stringFormatters import capitalize + + +class Other(commands.Cog): + def __init__(self, client): + self.client = client + + # Don't allow any commands to work when locked + def cog_check(self, ctx): + return not self.client.locked + + @commands.command(name="Custom") + @help.Category(category=Category.Didier) + async def list_custom(self, ctx): + """ + Get a list of all custom commands + """ + all_commands = get_all() + formatted = list(sorted(map(lambda x: capitalize(x["name"]), all_commands))) + src = custom_commands.CommandsList(formatted) + await custom_commands.Pages(source=src, clear_reactions_after=True).start(ctx) + + +def setup(client): + client.add_cog(Other(client)) diff --git a/cogs/store.py b/cogs/store.py index cd2f32e..25ee5c1 100644 --- a/cogs/store.py +++ b/cogs/store.py @@ -1,5 +1,5 @@ from converters.numbers import Abbreviated -from data import storePages +from data.menus import storePages from decorators import help import discord from discord.ext import commands diff --git a/cogs/train.py b/cogs/train.py index 093a096..10dcbb0 100644 --- a/cogs/train.py +++ b/cogs/train.py @@ -1,5 +1,4 @@ -from data import paginatedLeaderboard -import datetime +from data.menus import paginatedLeaderboard from decorators import help import discord from discord.ext import commands, menus diff --git a/data/menus/__init__.py b/data/menus/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/data/menus/custom_commands.py b/data/menus/custom_commands.py new file mode 100644 index 0000000..68c79c9 --- /dev/null +++ b/data/menus/custom_commands.py @@ -0,0 +1,21 @@ +import discord +from discord.ext import menus + + +class CommandsList(menus.ListPageSource): + def __init__(self, data, colour=discord.Colour.blue()): + super().__init__(data, per_page=15) + self.colour = colour + + async def format_page(self, menu: menus.MenuPages, entries): + embed = discord.Embed(colour=self.colour) + embed.set_author(name="Custom Commands") + embed.description = "\n".join(entries) + embed.set_footer(text="{}/{}".format(menu.current_page + 1, self.get_max_pages())) + + return embed + + +class Pages(menus.MenuPages): + def __init__(self, source, clear_reactions_after, timeout=30.0): + super().__init__(source, timeout=timeout, delete_message_after=True, clear_reactions_after=clear_reactions_after) diff --git a/data/paginatedLeaderboard.py b/data/menus/paginatedLeaderboard.py similarity index 100% rename from data/paginatedLeaderboard.py rename to data/menus/paginatedLeaderboard.py diff --git a/data/storePages.py b/data/menus/storePages.py similarity index 100% rename from data/storePages.py rename to data/menus/storePages.py diff --git a/files/help.json b/files/help.json index c80b9b3..b099ac3 100644 --- a/files/help.json +++ b/files/help.json @@ -33,6 +33,7 @@ "config": "Past constanten in het config bestand aan.", "corona": "Coronatracker voor [Land].\nIndien je geen land opgeeft is dit standaard Belgiƫ.\nCorona Global voor wereldwijde cijfers.", "corona vaccinations": "Vaccinatiecijfers voor Belgiƫ.", + "custom": "Geeft een lijst van custom commands. Didier > Dyno confirmed once more.", "dadjoke": "Didier vertelt een dad joke.", "define": "Geeft de definitie van [Woord] zoals het in de Urban Dictionary staat.\nZoektermen met spaties moeten **niet** tussen aanhalingstekens staan.", "detect": "Didier probeert de taal van [Tekst] te detecteren.",