aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-08-31 18:45:38 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-08-31 18:45:38 -0400
commitf850b708da87e56f2a1469b65560f8342e2c0f2b (patch)
tree7f1135f1ecbff3bb1ea467ac2ec500582006dbad
parenta47ef150fd38fff3666faccd6f976f660fdbf9f3 (diff)
downloadtanzanite-f850b708da87e56f2a1469b65560f8342e2c0f2b.tar.gz
tanzanite-f850b708da87e56f2a1469b65560f8342e2c0f2b.tar.bz2
tanzanite-f850b708da87e56f2a1469b65560f8342e2c0f2b.zip
ported roleall and capes command
-rw-r--r--src/commands/admin/roleAll.ts86
-rw-r--r--src/commands/moulberry-bush/capes.ts131
2 files changed, 217 insertions, 0 deletions
diff --git a/src/commands/admin/roleAll.ts b/src/commands/admin/roleAll.ts
new file mode 100644
index 0000000..ec18060
--- /dev/null
+++ b/src/commands/admin/roleAll.ts
@@ -0,0 +1,86 @@
+import { GuildMember, Role } from 'discord.js';
+import { AllowedMentions, BushCommand, BushMessage } from '../../lib';
+
+export default class RoleAllCommand extends BushCommand {
+ public constructor() {
+ super('roleAll', {
+ aliases: ['roleall', 'rall'],
+ category: 'Server Admin',
+ description: {
+ content: 'Give a role to every member on the server.',
+ usage: 'roleAll <role> [another role]... [--bots]',
+ examples: ['roleAll 783794633129197589 --bots']
+ },
+ args: [
+ {
+ id: 'role',
+ type: 'role',
+ prompt: {
+ start: 'What role would you like to give to every member on the server?',
+ retry: '{error} Pick a valid role.'
+ }
+ },
+ {
+ id: 'bots',
+ match: 'flag',
+ flag: '--bots',
+ default: false
+ }
+ ],
+ channel: 'guild',
+ clientPermissions: ['MANAGE_ROLES', 'SEND_MESSAGES'],
+ userPermissions: ['ADMINISTRATOR'],
+ typing: true
+ });
+ }
+
+ public override async exec(message: BushMessage, args: { role: Role; bot?: boolean }): Promise<unknown> {
+ if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a server.`);
+ if (!message.member!.permissions.has('ADMINISTRATOR'))
+ return await message.util.reply(`${this.client.util.emojis.error} You must have admin perms to use this command.`);
+
+ if (args.role.comparePositionTo(message.guild.me!.roles.highest) >= 0 && !args.role) {
+ return await message.util.reply(
+ `${this.client.util.emojis.error} I cannot assign a role higher or equal to my highest role.`
+ );
+ }
+
+ let members = await message.guild.members.fetch();
+ members = members.filter((member: GuildMember) => {
+ try {
+ if (member.user.bot && !args.bot) return false;
+ if (member.roles.cache.has(args.role.id)) return false;
+ } catch {
+ return false;
+ }
+ return true;
+ });
+
+ await message.util.reply(`${this.client.util.emojis.loading} adding roles to ${members.size} members`);
+
+ const promises = members.map((member: GuildMember) => {
+ return member.roles.add(args.role, `RoleAll Command - triggered by ${message.author.tag} (${message.author.id})`);
+ });
+
+ const failed = (await Promise.allSettled(promises)).filter((val) => val.status === 'rejected');
+
+ if (!failed.length) {
+ await message.util.reply({
+ content: `${this.client.util.emojis.success} Finished adding <@&${args.role.id}> to **${members.size}** member${
+ members.size ? 's' : ''
+ }.`,
+ allowedMentions: AllowedMentions.none()
+ });
+ } else {
+ const array = [...members.values()];
+ await message.util.reply({
+ content: `${this.client.util.emojis.warn} Finished adding <@&${args.role.id}> to **${
+ members.size - failed.length
+ }** member${members.size - failed.length ? 's' : ''}! Failed members:\n${failed
+ .map((_, index) => `<@${array[index].id}>`)
+ .join(' ')}`,
+ allowedMentions: AllowedMentions.none()
+ });
+ }
+ }
+}
diff --git a/src/commands/moulberry-bush/capes.ts b/src/commands/moulberry-bush/capes.ts
new file mode 100644
index 0000000..c8d1a05
--- /dev/null
+++ b/src/commands/moulberry-bush/capes.ts
@@ -0,0 +1,131 @@
+import { MessageEmbed } from 'discord.js';
+import got from 'got';
+import { BushCommand, BushMessage } from '../../lib';
+
+export interface GithubFile {
+ path: string;
+ mode: string;
+ type: string;
+ sha: string;
+ size: number;
+ url: string;
+}
+
+export interface GithubBlob {
+ encoding: string;
+ content: string;
+ sha: string;
+ node_id: string;
+ url: string;
+ size: number;
+}
+
+export interface GithubTreeApi {
+ sha: string;
+ url: string;
+ tree: GithubFile[];
+ truncated: boolean;
+}
+
+export default class CapesCommand extends BushCommand {
+ public constructor() {
+ super('capes', {
+ aliases: ['capes', 'cape'],
+ category: "Moulberry's Bush",
+ description: {
+ content: 'A command to see what a cape looks like.',
+ usage: 'cape [cape]',
+ examples: ['capes', 'cape space']
+ },
+ args: [
+ {
+ id: 'cape',
+ type: 'string',
+ prompt: {
+ start: 'What cape would you like to see?',
+ retry: '{error} Choose a cape to see.',
+ optional: true
+ },
+ default: null
+ }
+ ],
+ clientPermissions: ['EMBED_LINKS', 'SEND_MESSAGES'],
+ slash: true,
+ slashOptions: [
+ {
+ name: 'cape',
+ description: 'What cape would you like to see?',
+ type: 'STRING',
+ required: false
+ }
+ ]
+ });
+ }
+
+ public override async exec(message: BushMessage, args: { cape: string | null }): Promise<void> {
+ const { tree: neuFileTree }: GithubTreeApi = await got
+ .get('https://api.github.com/repos/Moulberry/NotEnoughUpdates/git/trees/master?recursive=1')
+ .json();
+ const capes = neuFileTree
+ .map((f) => ({
+ match: f.path.match(/src\/main\/resources\/assets\/notenoughupdates\/capes\/(?<name>\w+)_preview\.png/),
+ f
+ }))
+ .filter((f) => f.match !== null);
+
+ const capes1: { name: string; url: string; index: number }[] = [];
+ client.consts.mappings.capes.forEach((mapCape) => {
+ if (!capes.some((gitCape) => gitCape.match!.groups!.name === mapCape.name) && mapCape.custom) {
+ capes1.push({ name: mapCape.name, url: mapCape.custom, index: mapCape.index });
+ }
+ });
+ capes.forEach((gitCape) => {
+ const mapCape = client.consts.mappings.capes.find((a) => a.name === gitCape.match!.groups!.name);
+ const url = mapCape?.custom ?? `https://github.com/Moulberry/NotEnoughUpdates/raw/master/${gitCape.f.path}`;
+ const index = mapCape?.index !== undefined ? mapCape.index : null;
+ capes1.push({ name: gitCape.match!.groups!.name, url, index: index! });
+ });
+
+ const sortedCapes = capes1.sort((a, b) => {
+ let aWeight: number | undefined = undefined,
+ bWeight: number | undefined = undefined;
+ // eslint-disable-next-line prefer-const
+ aWeight ??= a?.index;
+ // eslint-disable-next-line prefer-const
+ bWeight ??= b?.index;
+
+ if (aWeight !== undefined && bWeight !== undefined) {
+ return aWeight - bWeight;
+ } else if (aWeight === undefined) {
+ return 1;
+ } else if (bWeight === undefined) {
+ return -1;
+ }
+ 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] });
+ } 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);
+ embeds.push(embed);
+ }
+ await util.buttonPaginate(message, embeds, null);
+ }
+ }
+}