Jelajahi Sumber

Fix stickers padding

ghorsington 4 tahun lalu
induk
melakukan
e556039220
1 mengubah file dengan 4 tambahan dan 3 penghapusan
  1. 4 3
      bot/src/plugins/stickers.ts

+ 4 - 3
bot/src/plugins/stickers.ts

@@ -48,9 +48,10 @@ export class Stickers {
         documentation: { description: "Lists all available stickers", example: "stickers" }
     })
     async listStickers({ message }: ICommandData): Promise<void> {
-        const m = Object.keys(this.stickers)
-            .filter(s => Object.prototype.hasOwnProperty.call(this.stickers, s))
-            .reduce((prev, cur, i) => `${prev}     !${cur}${i != 0 && i % STICKERS_PER_ROW == 0 ? "\n" : ""}`, "");
+        const stickerNames = Object.keys(this.stickers)
+            .filter(s => Object.prototype.hasOwnProperty.call(this.stickers, s));
+        const maxLength = stickerNames.map(s => s.length).reduce((prev, cur) => Math.max(prev, cur), 0);
+        const m = stickerNames.reduce((prev, cur, i) => `${prev}!${cur}${" ".repeat(maxLength - cur.length + 2)}${(i + 1) % STICKERS_PER_ROW == 0 ? "\n" : ""}`, "");
         
         let toSend = `${message.author.toString()}, I have the following stickers:\n\`\`\``;
         const rows = m.split("\n");