diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-02-19 18:52:41 -0500 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-02-19 18:52:41 -0500 |
commit | e78beed6c7e094ef48aad5d18da01b2bbed4536c (patch) | |
tree | 32676793af5f7bdc39d438ff284fa5b959274e96 /src/commands/moulberry-bush | |
parent | a3103b629250de3fb97a40a4f9ff7e7ba28f4d16 (diff) | |
download | tanzanite-e78beed6c7e094ef48aad5d18da01b2bbed4536c.tar.gz tanzanite-e78beed6c7e094ef48aad5d18da01b2bbed4536c.tar.bz2 tanzanite-e78beed6c7e094ef48aad5d18da01b2bbed4536c.zip |
fix: a ton of shit
Diffstat (limited to 'src/commands/moulberry-bush')
-rw-r--r-- | src/commands/moulberry-bush/capePermissions.ts | 24 | ||||
-rw-r--r-- | src/commands/moulberry-bush/capes.ts | 51 | ||||
-rw-r--r-- | src/commands/moulberry-bush/report.ts | 5 |
3 files changed, 34 insertions, 46 deletions
diff --git a/src/commands/moulberry-bush/capePermissions.ts b/src/commands/moulberry-bush/capePermissions.ts index e568036..edb2836 100644 --- a/src/commands/moulberry-bush/capePermissions.ts +++ b/src/commands/moulberry-bush/capePermissions.ts @@ -28,21 +28,13 @@ export default class CapePermissionsCommand extends BushCommand { } public override async exec(message: BushMessage | BushSlashMessage, args: { ign: ArgType<'string'> }) { - interface CapePerms { - success: boolean; - perms: User[]; - } - - interface User { - _id: string; - perms: string[]; - } - let capePerms: CapePerms | null, uuid: string; try { uuid = await util.mcUUID(args.ign); } catch (e) { - return await message.util.reply(`${util.emojis.error} \`${args.ign}\` doesn't appear to be a valid username.`); + return await message.util.reply( + `${util.emojis.error} ${util.format.input(args.ign)} doesn't appear to be a valid username.` + ); } try { @@ -77,3 +69,13 @@ export default class CapePermissionsCommand extends BushCommand { } } } + +interface CapePerms { + success: boolean; + perms: User[]; +} + +interface User { + _id: string; + perms: string[]; +} diff --git a/src/commands/moulberry-bush/capes.ts b/src/commands/moulberry-bush/capes.ts index 47a4ea6..551a5c6 100644 --- a/src/commands/moulberry-bush/capes.ts +++ b/src/commands/moulberry-bush/capes.ts @@ -38,49 +38,32 @@ export default class CapesCommand extends BushCommand { const { tree: neuFileTree }: GithubTreeApi = await got .get('https://api.github.com/repos/Moulberry/NotEnoughUpdates/git/trees/master?recursive=1') .json(); - const capes = neuFileTree + const rawCapes = 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; purchasable?: boolean }[] = []; - 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, - purchasable: mapCape.purchasable - }); - } - }); - 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!, purchasable: mapCape?.purchasable }); - }); - - const sortedCapes = capes1.sort((a, b) => { - let aWeight: number | undefined = undefined, - bWeight: number | undefined = undefined; - aWeight ??= a?.index; - bWeight ??= b?.index; - - if (aWeight !== undefined && bWeight !== undefined) { - return aWeight - bWeight; - } else if (aWeight === undefined) { - return 1; - } else if (bWeight === undefined) { - return -1; - } + const capes: { name: string; url: string; index: number; purchasable?: boolean }[] = [ + ...client.consts.mappings.capes + .filter((c) => !rawCapes.some((gitCape) => gitCape.match!.groups!.name === c.name) && c.custom) + .map((c) => ({ name: c.name, url: c.custom!, index: c.index, purchasable: c.purchasable })), + ...rawCapes.map((c) => { + const mapCape = client.consts.mappings.capes.find((a) => a.name === c.match!.groups!.name); + const url = mapCape?.custom ?? `https://github.com/Moulberry/NotEnoughUpdates/raw/master/${c.f.path}`; + const index = mapCape?.index !== undefined ? mapCape.index : null; + return { name: c.match!.groups!.name, url, index: index!, purchasable: mapCape?.purchasable }; + }) + ].sort((a, b) => { + if (a?.index !== undefined && b.index !== undefined) return a.index - b?.index; + else if (a.index === undefined) return 1; + else if (b.index === undefined) return -1; return 0; }); if (args.cape) { - const cape = sortedCapes.find((s_cape) => s_cape.name === args.cape); + const cape = capes.find((s_cape) => s_cape.name === args.cape); if (cape) { const embed = this.makeEmbed(cape); await DeleteButton.send(message, { embeds: [embed] }); @@ -88,7 +71,7 @@ export default class CapesCommand extends BushCommand { await message.util.reply(`${util.emojis.error} Cannot find a cape called \`${args.cape}\`.`); } } else { - const embeds: APIEmbed[] = sortedCapes.map(this.makeEmbed); + const embeds: APIEmbed[] = capes.map(this.makeEmbed); await ButtonPaginator.send(message, embeds, null); } } diff --git a/src/commands/moulberry-bush/report.ts b/src/commands/moulberry-bush/report.ts index becdeeb..fc78a7b 100644 --- a/src/commands/moulberry-bush/report.ts +++ b/src/commands/moulberry-bush/report.ts @@ -1,4 +1,5 @@ import { AllowedMentions, BushCommand, type ArgType, type BushMessage } from '#lib'; +import assert from 'assert'; import { ApplicationCommandOptionType, Embed, PermissionFlagsBits } from 'discord.js'; export default class ReportCommand extends BushCommand { @@ -37,7 +38,9 @@ export default class ReportCommand extends BushCommand { } public override async exec(message: BushMessage, { member, evidence }: { member: ArgType<'member'>; evidence: string }) { - if (!message.guild || !(await message.guild.hasFeature('reporting'))) + assert(message.inGuild()); + + if (!(await message.guild.hasFeature('reporting'))) return await message.util.reply( `${util.emojis.error} This command can only be used in servers where reporting is enabled.` ); |