瀏覽代碼

Fix stickers padding

ghorsington 4 年之前
父節點
當前提交
e556039220
共有 1 個文件被更改,包括 4 次插入3 次删除
  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");