aboutsummaryrefslogtreecommitdiff
path: root/src/commands/moulberry-bush/capes.ts
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-10-21 00:05:53 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-10-21 00:05:53 -0400
commit166d7fdf24440db71311c2cda95697c06e7b8b36 (patch)
tree23b0400362b5f3035b156200eb634d202aa54741 /src/commands/moulberry-bush/capes.ts
parent08f33f7d450c8920afc3b9fb8886729547065313 (diff)
downloadtanzanite-166d7fdf24440db71311c2cda95697c06e7b8b36.tar.gz
tanzanite-166d7fdf24440db71311c2cda95697c06e7b8b36.tar.bz2
tanzanite-166d7fdf24440db71311c2cda95697c06e7b8b36.zip
Refactoring, rewrote ButtonPaginator, better permission handling + support for send messages in threads, optimizations, another scam link
Diffstat (limited to 'src/commands/moulberry-bush/capes.ts')
-rw-r--r--src/commands/moulberry-bush/capes.ts49
1 files changed, 27 insertions, 22 deletions
diff --git a/src/commands/moulberry-bush/capes.ts b/src/commands/moulberry-bush/capes.ts
index 14a972e..1a09eb0 100644
--- a/src/commands/moulberry-bush/capes.ts
+++ b/src/commands/moulberry-bush/capes.ts
@@ -1,6 +1,8 @@
-import { MessageEmbed } from 'discord.js';
+import { MessageEmbedOptions } from 'discord.js';
import got from 'got';
import { BushCommand, BushMessage } from '../../lib';
+import { ButtonPaginator } from '../../lib/common/ButtonPaginator';
+import { DeleteButton } from '../../lib/common/DeleteButton';
export interface GithubFile {
path: string;
@@ -58,8 +60,8 @@ export default class CapesCommand extends BushCommand {
required: false
}
],
- clientPermissions: ['EMBED_LINKS', 'SEND_MESSAGES'],
- userPermissions: ['SEND_MESSAGES']
+ clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true),
+ userPermissions: []
});
}
@@ -102,30 +104,33 @@ export default class CapesCommand extends BushCommand {
}
return 0;
});
+
if (args.cape) {
- const capeObj = sortedCapes.find((s_cape) => s_cape.name === args.cape);
- if (capeObj) {
- const embed = new MessageEmbed({
- title: `${capeObj.name} cape`,
- color: util.colors.default
- }).setTimestamp();
- embed.setImage(capeObj.url);
- await util.sendWithDeleteButton(message, { embeds: [embed] });
+ const cape = sortedCapes.find((s_cape) => s_cape.name === args.cape);
+ if (cape) {
+ const embed = this.makeEmbed(cape);
+ await DeleteButton.send(message, { embeds: [embed] });
} else {
await message.util.reply(`${util.emojis.error} Cannot find a cape called \`${args.cape}\`.`);
}
} else {
- const embeds = [];
- for (const capeObj of sortedCapes) {
- const embed = new MessageEmbed({
- title: `${capeObj.name} cape`,
- color: util.colors.default
- }).setTimestamp();
- embed.setImage(capeObj.url);
- if (capeObj.purchasable) embed.setDescription(':money_with_wings: **purchasable** :money_with_wings:');
- embeds.push(embed);
- }
- await util.buttonPaginate(message, embeds, null);
+ const embeds: MessageEmbedOptions[] = sortedCapes.map(this.makeEmbed);
+ await ButtonPaginator.send(message, embeds, null);
}
}
+
+ private makeEmbed(cape: {
+ name: string;
+ url: string;
+ index: number;
+ purchasable?: boolean | undefined;
+ }): MessageEmbedOptions {
+ return {
+ title: `${cape.name} cape`,
+ color: util.colors.default,
+ timestamp: Date.now(),
+ image: { url: cape.url },
+ description: cape.purchasable ? ':money_with_wings: **purchasable** :money_with_wings:' : undefined
+ };
+ }
}