ZumitoTeam / zumito-bot

Discord Bot
GNU General Public License v3.0
4 stars 1 forks source link

Sweep: Improve command list formatting #131

Closed WilliamAcosta1 closed 6 months ago

WilliamAcosta1 commented 6 months ago

Details

Currently in the help command in your message where it says commands come out in a non-aligned format my request is to align the text shown below:

image

It should look as follows:

image

Possible solution: you can count the string and then do 15-stringSize and you already have the number of spaces

sweep-ai[bot] commented 6 months ago

🚀 Here's the PR! #132

💎 Sweep Pro: You have unlimited Sweep issues

Actions

Relevant files (click to expand). Mentioned files will always appear here. https://github.com/ZumitoTeam/zumito-bot/blob/d79d505bd95233c4872ab153a1824928f7810e16/src/modules/info/commands/help.ts#L1-L280 https://github.com/ZumitoTeam/zumito-bot/blob/d79d505bd95233c4872ab153a1824928f7810e16/src/modules/info/translations/command/help/es.json#L1-L39

Step 2: ⌨️ Coding

src/modules/info/commands/help.ts

Calculate the maximum length of command names and pad each command name with spaces to achieve equal spacing and alignment.
--- 
+++ 
@@ -1,29 +1,13 @@
-                    for (let i = 0; i < commands.length; i++) 
-                    {
-                        if (interaction.values[0] === "information" && i % 4 == 0) { i == 4 && categoryEmbed
-                            .addFields(
-                                {
-                                    name: "📖" + " " + framework.translations.get("command.help.commands", guildSettings.lang),
-                                    value: "```" + (commands[i]?.name || "") + "       " + (commands[i + 1]?.name || "") + "       " + (commands[i + 2]?.name || "") + "       " + (commands[i + 3]?.name || "") + "       " + valuesToPush.join("") + "```",
-                                }
-                            )
-                            .setColor(config.colors.default);
-                            
-                            i == 0 && valuesToPush.push(
+                    const maxLength = commands.reduce((max, command) => Math.max(max, command.name.length), 0);
+                    const paddedCommands = commands.map(command => command.name.padEnd(maxLength, ' '));

-                                (commands[i]?.name || "") + "       " + (commands[i + 1]?.name || "") + "       " + (commands[i + 2]?.name || "") + "       " + (commands[i + 3]?.name || "")
-                                
-                                );
-                        } else { 
-                            if (i % 4 == 0) {
-                                categoryEmbed
-                                .addFields(
-                                    {
-                                        name: "📖" + " " + framework.translations.get("command.help.commands", guildSettings.lang),
-                                        value: "```" + (commands[i]?.name || "") + "       " + (commands[i + 1]?.name || "") + "       " + (commands[i + 2]?.name || "") + "       " + (commands[i + 3]?.name || "") + "       " + "```",
-                                }
-                                )
-                                .setColor(config.colors.default);
+                    for (let i = 0; i < paddedCommands.length; i += 4) {
+                        const row = paddedCommands.slice(i, i + 4).join('  ');
+                        categoryEmbed.addFields(
+                            {
+                                name: "📖" + " " + framework.translations.get("command.help.commands", guildSettings.lang),
+                                value: "```" + row + "```",
                             }
-                        }
+                        )
+                        .setColor(config.colors.default);
                     }

Step 3: 🔄️ Validating

Your changes have been successfully made to the branch sweep/improve_command_list_formatting. I have validated these changes using a syntax checker and a linter.


[!TIP] To recreate the pull request, edit the issue title or description.

This is an automated message generated by Sweep AI.

github-actions[bot] commented 6 months ago

Branch issue-131-Sweep_Improve_command_list_formatting created!