Merge pull request #74 from stijndcl/list_custom_commands

Show list of custom commands
pull/77/head
Stijn De Clercq 2021-06-19 23:09:53 +02:00 committed by GitHub
commit 7bbe4db26d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 57 additions and 7 deletions

View File

@ -1,4 +1,4 @@
from data import paginatedLeaderboard
from data.menus import paginatedLeaderboard
from decorators import help
import discord
from discord.ext import commands

View File

@ -1,4 +1,4 @@
from data import paginatedLeaderboard
from data.menus import paginatedLeaderboard
from decorators import help
import discord
from discord.ext import commands

View File

@ -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):

30
cogs/other.py 100644
View File

@ -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))

View File

@ -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

View File

@ -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

View File

View File

@ -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)

View File

@ -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.",