Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tournaments] message template #130

Open
leElvyn opened this issue Dec 18, 2020 · 1 comment
Open

[Tournaments] message template #130

leElvyn opened this issue Dec 18, 2020 · 1 comment
Assignees
Labels
Cog: Tournaments An issue or a PR for the Tournaments cog Complex issue This requires a lot of work and/or changes Status: Needs discussion Needs more discussion about the issue/feature introduced Status: Pending Waiting for assignment and validation Type: Feature Adds one or more feature to a cog Work in progress

Comments

@leElvyn
Copy link

leElvyn commented Dec 18, 2020

The plan is to completely change the way messages are handled in tournaments. Currently messages are just stored how you would expect, they're supposed to be used.

Due to the huge number of strings present in this cog, it has became almost impossible to allow user customizable messages. The plan is in two part :

Quick overview

  • First a complete rewrite of how strings are handled in the cog.
  • Second, a new command for server admins to allow custom messages, that could be either in a simple text format, or JSON embed.

First part : message handling

A new file containing a "Templates" class would be created.
The class would be created at the bot's init, and would then be passed to every other part of the cog that requires messages. The class would contain multiple methods, each one would represent a message, like this :

class Templates():
    def __init__(self, bot, data):
        self.data = data

    def tournamentsinfo(self, ctxSelf):
        return _(
                "Laggron's Dumb Cogs V3 - tournaments\n\n"
                "Version: {0.__version__}\n"
                "Authors: {0.__author__[0]}, {0.__author__[1]} and {0.__author__[2]}\n\n"
                "Github repository: https://github.com/retke/Laggrons-Dumb-Cogs/tree/v3\n"
                "Discord server: https://discord.gg/AVzjfpR\n"
                "Documentation: http://laggrons-dumb-cogs.readthedocs.io/\n"
                "Help translating the cog: https://crowdin.com/project/laggrons-dumb-cogs/\n\n"
                "Support my work on Patreon: https://www.patreon.com/retke"
            ).format(ctxSelf)

And in the actual code :

    @commands.command(hidden=True)
    async def tournamentsinfo(self, ctx: commands.Context):
        """
        Get informations about the cog.
        """
        await ctx.send(self.templates.tournamentsinfo(self))

here, we just call a previously created templates objects, and then the arguments is what's used to format the message.
That way, every messages are easily accessible.

Second part : message customization

A new command / subcommand would be created to allow server admins to use their own messages for the bot. The command will set an entry in the config (or be reset by setting it blank). When the code will call a method of the templates class, the method will first check if the key for this message template is blank in the config. If it is, it returns the default message. If it isn't, it will format the message with the context, and return it.

If the command is [p]custommessage, the base command with no arguments will simply return a tree of message categories ( announcments, staff messages, streams ...), and the user will be able to select the right message inside the categories. Each command's help will contain :

  • The commands context
  • A brief detail about the message
  • The default message

The context

When a message method is called, the context will be used to format the message. Context is thing like : {tournament}, which refers to the name of the tournament, {prefix}, or {participant} is the participant object, that can be used to mention the role : {participant.mention}, like Red's custom command system.

Major problem :

How does a user chose between a text message and an embed ?

since the send command takes either an embed, or a message, we can't just return an embed object or a string and send it.

@laggron42 laggron42 added Cog: Tournaments An issue or a PR for the Tournaments cog Complex issue This requires a lot of work and/or changes Status: Needs discussion Needs more discussion about the issue/feature introduced Status: Pending Waiting for assignment and validation Type: Feature Adds one or more feature to a cog Work in progress labels Dec 19, 2020
@laggron42 laggron42 added this to the Tournaments 1.1 milestone Dec 19, 2020
@leElvyn
Copy link
Author

leElvyn commented Dec 19, 2020

Update :

I discovered that passing the Templates object in ever class won't be necessary.
Instead, the object will simply be in the templates.py file.

simply :
templates.py

class Templates():
    def __init__(self, bot, data):
        self.data = data
    def other_messages():
        pass

tournaments.py

from .objects import templates

... 

    def __init__(self, bot):
        templates.object = templates.Templates(data)

then, we just need to import the templates file to use the object :
base.py

from .objects import templates

    def some_commands():
        templates.object.base_some_commands(context)

@laggron42 laggron42 removed this from the Tournaments 1.1 milestone May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cog: Tournaments An issue or a PR for the Tournaments cog Complex issue This requires a lot of work and/or changes Status: Needs discussion Needs more discussion about the issue/feature introduced Status: Pending Waiting for assignment and validation Type: Feature Adds one or more feature to a cog Work in progress
Projects
None yet
Development

No branches or pull requests

2 participants