diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-08-20 23:07:02 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-08-20 23:07:02 -0400 |
commit | b81f9e8b73cb520ad5ae916c3e571ea55f4ca489 (patch) | |
tree | 25d7f42d66c3e3190022ece043c86082a9e85709 /src/commands | |
parent | f2e5cfff7dc275bd93fac446a508b7d18ecd6c58 (diff) | |
download | tanzanite-b81f9e8b73cb520ad5ae916c3e571ea55f4ca489.tar.gz tanzanite-b81f9e8b73cb520ad5ae916c3e571ea55f4ca489.tar.bz2 tanzanite-b81f9e8b73cb520ad5ae916c3e571ea55f4ca489.zip |
fix ts composite shit, replace got with native fetch, update deps
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/admin/channelPermissions.ts | 2 | ||||
-rw-r--r-- | src/commands/admin/roleAll.ts | 1 | ||||
-rw-r--r-- | src/commands/config/config.ts | 1 | ||||
-rw-r--r-- | src/commands/config/disable.ts | 2 | ||||
-rw-r--r-- | src/commands/dev/eval.ts | 3 | ||||
-rw-r--r-- | src/commands/dev/reload.ts | 15 | ||||
-rw-r--r-- | src/commands/dev/syncAutomod.ts | 11 | ||||
-rw-r--r-- | src/commands/index.ts | 2 | ||||
-rw-r--r-- | src/commands/info/help.ts | 2 | ||||
-rw-r--r-- | src/commands/leveling/level.ts | 32 | ||||
-rw-r--r-- | src/commands/moderation/unmute.ts | 38 | ||||
-rw-r--r-- | src/commands/moulberry-bush/capePermissions.ts | 3 | ||||
-rw-r--r-- | src/commands/moulberry-bush/capes.ts | 10 | ||||
-rw-r--r-- | src/commands/moulberry-bush/serverStatus.ts | 8 | ||||
-rw-r--r-- | src/commands/utilities/hash.ts | 82 | ||||
-rw-r--r-- | src/commands/utilities/price.ts | 9 |
16 files changed, 85 insertions, 136 deletions
diff --git a/src/commands/admin/channelPermissions.ts b/src/commands/admin/channelPermissions.ts index 21abd04..0b09e54 100644 --- a/src/commands/admin/channelPermissions.ts +++ b/src/commands/admin/channelPermissions.ts @@ -1,5 +1,6 @@ import { Arg, + BushCommand, ButtonPaginator, clientSendAndPermCheck, emojis, @@ -10,7 +11,6 @@ import { } from '#lib'; import assert from 'assert/strict'; import { ApplicationCommandOptionType, EmbedBuilder, PermissionFlagsBits } from 'discord.js'; -import { BushCommand } from '../../../lib/extensions/discord-akairo/BushCommand.js'; export default class ChannelPermissionsCommand extends BushCommand { public constructor() { diff --git a/src/commands/admin/roleAll.ts b/src/commands/admin/roleAll.ts index a48bd6b..54afc2a 100644 --- a/src/commands/admin/roleAll.ts +++ b/src/commands/admin/roleAll.ts @@ -7,7 +7,6 @@ import { type CommandMessage, type SlashMessage } from '#lib'; - import assert from 'assert/strict'; import { ApplicationCommandOptionType, PermissionFlagsBits, type GuildMember } from 'discord.js'; diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts index f6b8bfa..39a44d1 100644 --- a/src/commands/config/config.ts +++ b/src/commands/config/config.ts @@ -15,7 +15,6 @@ import { type SlashMessage } from '#lib'; import assert from 'assert/strict'; - import { type ArgumentGeneratorReturn, type SlashOption } from 'discord-akairo'; import { ActionRowBuilder, diff --git a/src/commands/config/disable.ts b/src/commands/config/disable.ts index 00dea76..f9abb4a 100644 --- a/src/commands/config/disable.ts +++ b/src/commands/config/disable.ts @@ -11,7 +11,7 @@ import { } from '#lib'; import assert from 'assert/strict'; import { ApplicationCommandOptionType, AutocompleteInteraction, PermissionFlagsBits } from 'discord.js'; -import Fuse from 'fuse.js'; +import { default as Fuse } from 'fuse.js'; assert(Fuse); diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts index 04db2eb..fdef3ac 100644 --- a/src/commands/dev/eval.ts +++ b/src/commands/dev/eval.ts @@ -45,7 +45,6 @@ import { ReactionCollector, SelectMenuComponent } from 'discord.js'; -import got from 'got'; import path from 'path'; import ts from 'typescript'; import { fileURLToPath } from 'url'; @@ -57,7 +56,7 @@ const { transpile } = ts, /* eslint-enable @typescript-eslint/no-unused-vars */ // prettier-ignore -assertAll(ActivePunishment, BushCommand, Global, Guild, Level, ModLog, Shared, StickyRole, Snowflake_, Canvas, exec, ActionRow, ButtonComponent, ButtonInteraction, Collection, Collector, CommandInteraction, ContextMenuCommandInteraction, DMChannel, Embed, Emoji, InteractionCollector, Message, Attachment, MessageCollector, OAuth2Scopes, PermissionFlagsBits, PermissionsBitField, ReactionCollector, SelectMenuComponent, path, ts, fileURLToPath, promisify, assert, got, transpile, sh, SnowflakeUtil, __dirname); +assertAll(ActivePunishment, BushCommand, Global, Guild, Level, ModLog, Shared, StickyRole, Snowflake_, Canvas, exec, ActionRow, ButtonComponent, ButtonInteraction, Collection, Collector, CommandInteraction, ContextMenuCommandInteraction, DMChannel, Embed, Emoji, InteractionCollector, Message, Attachment, MessageCollector, OAuth2Scopes, PermissionFlagsBits, PermissionsBitField, ReactionCollector, SelectMenuComponent, path, ts, fileURLToPath, promisify, assert, transpile, sh, SnowflakeUtil, __dirname); export default class EvalCommand extends BushCommand { public constructor() { diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts index 40d53eb..8125015 100644 --- a/src/commands/dev/reload.ts +++ b/src/commands/dev/reload.ts @@ -8,17 +8,6 @@ export default class ReloadCommand extends BushCommand { description: 'Reloads the bot', usage: ['reload'], examples: ['reload'], - // args: [ - // { - // id: 'fast', - // description: 'Whether or not to use esbuild for fast compiling.', - // match: 'flag', - // flag: ['--fast'], - // prompt: 'Would you like to use esbuild for fast compiling?', - // optional: true, - // slashType: ApplicationCommandOptionType.Boolean - // } - // ], ownerOnly: true, typing: true, slash: true, @@ -27,13 +16,13 @@ export default class ReloadCommand extends BushCommand { }); } - public override async exec(message: CommandMessage | SlashMessage /* args: { fast: ArgType<'flag'> } */) { + public override async exec(message: CommandMessage | SlashMessage) { if (!message.author.isOwner()) return await message.util.reply(`${emojis.error} Only my developers can run this command.`); let output: { stdout: string; stderr: string }; try { const s = new Date(); - output = await shell(`yarn build:${/* args.fast ? 'esbuild' : */ 'tsc'}`); + output = await shell(`yarn build`); await Promise.all([ this.client.commandHandler.reloadAll(), this.client.listenerHandler.reloadAll(), diff --git a/src/commands/dev/syncAutomod.ts b/src/commands/dev/syncAutomod.ts index c78e6c0..3dbd0be 100644 --- a/src/commands/dev/syncAutomod.ts +++ b/src/commands/dev/syncAutomod.ts @@ -1,5 +1,4 @@ import { BushCommand, clientSendAndPermCheck, emojis, Shared, type CommandMessage, type SlashMessage } from '#lib'; -import got from 'got'; import typescript from 'typescript'; import { NodeVM } from 'vm2'; @@ -22,10 +21,12 @@ export default class SyncAutomodCommand extends BushCommand { if (!message.author.isOwner() && message.author.id !== '497789163555389441') return await message.util.reply(`${emojis.error} Only a very select few may use this command.`); - const badLinks = (await got.get('https://raw.githubusercontent.com/NotEnoughUpdates/bush-bot/master/src/lib/badlinks.ts')) - .body; - const badWords = (await got.get('https://raw.githubusercontent.com/NotEnoughUpdates/bush-bot/master/src/lib/badwords.ts')) - .body; + const badLinks = await fetch('https://raw.githubusercontent.com/NotEnoughUpdates/bush-bot/master/src/lib/badlinks.ts').then( + (p) => p.text() + ); + const badWords = await fetch('https://raw.githubusercontent.com/NotEnoughUpdates/bush-bot/master/src/lib/badwords.ts').then( + (p) => p.text() + ); const transpiledBadLinks = typescript.transpileModule(badLinks, {}).outputText; const transpiledBadWords = typescript.transpileModule(badWords, {}).outputText; diff --git a/src/commands/index.ts b/src/commands/index.ts index a9db0de..59801c7 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -62,7 +62,7 @@ export { default as ServerStatusCommand } from './moulberry-bush/serverStatus.js export { default as ActivityCommand } from './utilities/activity.js'; export { default as CalculatorCommand } from './utilities/calculator.js'; export { default as DecodeCommand } from './utilities/decode.js'; -export { default as HashCommand } from './utilities/hash.js'; +// export { default as HashCommand } from './utilities/hash.js'; export { default as PriceCommand } from './utilities/price.js'; export { default as RemindCommand } from './utilities/remind.js'; export { default as RemindersCommand } from './utilities/reminders.js'; diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index 62f177e..df18403 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -20,7 +20,7 @@ import { EmbedBuilder, PermissionFlagsBits } from 'discord.js'; -import Fuse from 'fuse.js'; +import { default as Fuse } from 'fuse.js'; import packageDotJSON from '../../../package.json' assert { type: 'json' }; assert(Fuse); diff --git a/src/commands/leveling/level.ts b/src/commands/leveling/level.ts index eda43f2..219ae19 100644 --- a/src/commands/leveling/level.ts +++ b/src/commands/leveling/level.ts @@ -13,11 +13,7 @@ import { SimplifyNumber } from '@notenoughupdates/simplify-number'; import assert from 'assert/strict'; import canvas from 'canvas'; import { ApplicationCommandOptionType, AttachmentBuilder, Guild, PermissionFlagsBits, User } from 'discord.js'; -import got from 'got'; -import { dirname, join } from 'path'; -import { fileURLToPath } from 'url'; assert(canvas); -assert(got); assert(SimplifyNumber); export default class LevelCommand extends BushCommand { @@ -85,10 +81,12 @@ export default class LevelCommand extends BushCommand { const white = '#FFFFFF', gray = '#23272A', highlight = user.hexAccentColor ?? '#5865F2'; - // Load roboto font + + // ! Broken on node v18 - install the font instead + /* // Load roboto font canvas.registerFont(join(dirname(fileURLToPath(import.meta.url)), '..', '..', '..', '..', 'assets', 'Roboto-Regular.ttf'), { family: 'Roboto' - }); + }); */ // Create image canvas const levelCard = canvas.createCanvas(800, 200), ctx = levelCard.getContext('2d'); @@ -97,9 +95,14 @@ export default class LevelCommand extends BushCommand { ctx.fillRect(0, 0, levelCard.width, levelCard.height); // Draw avatar const AVATAR_SIZE = 128; - const avatarBuffer = await got.get(user.displayAvatarURL({ extension: 'png', size: AVATAR_SIZE })).buffer(); const avatarImage = new canvas.Image(); - avatarImage.src = avatarBuffer; + avatarImage.src = user.displayAvatarURL({ extension: 'png', size: AVATAR_SIZE }); + + await new Promise((resolve, reject) => { + avatarImage.onload = () => resolve(undefined); + avatarImage.onerror = (e) => reject(e); + }); + const imageTopCoord = levelCard.height / 2 - AVATAR_SIZE / 2; ctx.drawImage(avatarImage, imageTopCoord, imageTopCoord, AVATAR_SIZE, AVATAR_SIZE); // Write tag of user @@ -123,13 +126,12 @@ export default class LevelCommand extends BushCommand { progressBar.draw(); // Draw level data text ctx.fillStyle = white; - ctx.fillText( - `Level: ${userLevel} XP: ${SimplifyNumber(currentLevelXpProgress)}/${SimplifyNumber( - xpForNextLevel - )} Rank: ${SimplifyNumber(rank.indexOf(rank.find((x) => x.user === user.id)!) + 1)}`, - AVATAR_SIZE + 70, - AVATAR_SIZE - 20 - ); + + const xpTxt = `${SimplifyNumber(currentLevelXpProgress)}/${SimplifyNumber(xpForNextLevel)}`; + + const rankTxt = SimplifyNumber(rank.indexOf(rank.find((x) => x.user === user.id)!) + 1); + + ctx.fillText(`Level: ${userLevel} XP: ${xpTxt} Rank: ${rankTxt}`, AVATAR_SIZE + 70, AVATAR_SIZE - 20); // Return image in buffer form return levelCard.toBuffer(); } diff --git a/src/commands/moderation/unmute.ts b/src/commands/moderation/unmute.ts index 620f499..f1e74ab 100644 --- a/src/commands/moderation/unmute.ts +++ b/src/commands/moderation/unmute.ts @@ -1,19 +1,16 @@ import { AllowedMentions, clientSendAndPermCheck, - emojis, - format, + formatUnmuteResponse, Moderation, - unmuteResponse, userGuildPermCheck, type ArgType, type CommandMessage, type OptArgType, - type SlashMessage, - type UnmuteResponse + type SlashMessage } from '#lib'; import assert from 'assert/strict'; -import { ApplicationCommandOptionType, PermissionFlagsBits, type GuildMember } from 'discord.js'; +import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; import { BushCommand } from '../../../lib/extensions/discord-akairo/BushCommand.js'; export default class UnmuteCommand extends BushCommand { @@ -83,35 +80,8 @@ export default class UnmuteCommand extends BushCommand { }); return await message.util.reply({ - content: UnmuteCommand.formatCode(member.client.utils.prefix(message), member, responseCode), + content: formatUnmuteResponse(member.client.utils.prefix(message), member, responseCode), allowedMentions: AllowedMentions.none() }); } - - public static formatCode(prefix: string, member: GuildMember, code: UnmuteResponse): string { - const error = emojis.error; - const victim = format.input(member.user.tag); - switch (code) { - case unmuteResponse.MISSING_PERMISSIONS: - return `${error} Could not unmute ${victim} because I am missing the **Manage Roles** permission.`; - case unmuteResponse.NO_MUTE_ROLE: - return `${error} Could not unmute ${victim}, you must set a mute role with \`${prefix}config muteRole\`.`; - case unmuteResponse.MUTE_ROLE_INVALID: - return `${error} Could not unmute ${victim} because the current mute role no longer exists. Please set a new mute role with \`${prefix}config muteRole\`.`; - case unmuteResponse.MUTE_ROLE_NOT_MANAGEABLE: - return `${error} Could not unmute ${victim} because I cannot assign the current mute role, either change the role's position or set a new mute role with \`${prefix}config muteRole\`.`; - case unmuteResponse.ACTION_ERROR: - return `${error} Could not unmute ${victim}, there was an error removing their mute role.`; - case unmuteResponse.MODLOG_ERROR: - return `${error} While muting ${victim}, there was an error creating a modlog entry, please report this to my developers.`; - case unmuteResponse.PUNISHMENT_ENTRY_REMOVE_ERROR: - return `${error} While muting ${victim}, there was an error removing their mute entry, please report this to my developers.`; - case unmuteResponse.DM_ERROR: - return `${emojis.warn} unmuted ${victim} however I could not send them a dm.`; - case unmuteResponse.SUCCESS: - return `${emojis.success} Successfully unmuted ${victim}.`; - default: - return `${emojis.error} An error occurred: ${format.input(code)}}`; - } - } } diff --git a/src/commands/moulberry-bush/capePermissions.ts b/src/commands/moulberry-bush/capePermissions.ts index 3ad9602..793ac59 100644 --- a/src/commands/moulberry-bush/capePermissions.ts +++ b/src/commands/moulberry-bush/capePermissions.ts @@ -11,7 +11,6 @@ import { type SlashMessage } from '#lib'; import { ApplicationCommandOptionType, EmbedBuilder, PermissionFlagsBits } from 'discord.js'; -import got from 'got'; export default class CapePermissionsCommand extends BushCommand { public constructor() { @@ -50,7 +49,7 @@ export default class CapePermissionsCommand extends BushCommand { } try { - capePerms = await got.get('http://moulberry.codes/permscapes.json').json(); + capePerms = await fetch('http://moulberry.codes/permscapes.json').then((p) => (p.ok ? p.json() : null)); } catch (error) { capePerms = null; } diff --git a/src/commands/moulberry-bush/capes.ts b/src/commands/moulberry-bush/capes.ts index 8693dba..6ffc540 100644 --- a/src/commands/moulberry-bush/capes.ts +++ b/src/commands/moulberry-bush/capes.ts @@ -14,11 +14,9 @@ import { } from '#lib'; import assert from 'assert/strict'; import { ApplicationCommandOptionType, PermissionFlagsBits, type APIEmbed, type AutocompleteInteraction } from 'discord.js'; -import Fuse from 'fuse.js'; -import got from 'got'; +import { default as Fuse } from 'fuse.js'; assert(Fuse); -assert(got); export default class CapesCommand extends BushCommand { public constructor() { @@ -47,9 +45,9 @@ export default class CapesCommand extends BushCommand { } public override async exec(message: CommandMessage | SlashMessage, args: { cape: OptArgType<'string'> }) { - const { tree: neuFileTree }: GithubTreeApi = await got - .get('https://api.github.com/repos/NotEnoughUpdates/NotEnoughUpdates/git/trees/master?recursive=1') - .json(); + const { tree: neuFileTree }: GithubTreeApi = await fetch( + 'https://api.github.com/repos/NotEnoughUpdates/NotEnoughUpdates/git/trees/master?recursive=1' + ).then((p) => (p.ok ? p.json() : { tree: [] })); const rawCapes = neuFileTree .map((f) => ({ match: f.path.match(/src\/main\/resources\/assets\/notenoughupdates\/capes\/(?<name>\w+)_preview\.png/), diff --git a/src/commands/moulberry-bush/serverStatus.ts b/src/commands/moulberry-bush/serverStatus.ts index 1237b3f..cde3f04 100644 --- a/src/commands/moulberry-bush/serverStatus.ts +++ b/src/commands/moulberry-bush/serverStatus.ts @@ -1,9 +1,5 @@ import { BushCommand, clientSendAndPermCheck, colors, emojis, type CommandMessage } from '#lib'; -import assert from 'assert/strict'; import { EmbedBuilder, PermissionFlagsBits } from 'discord.js'; -import got from 'got'; - -assert(got); export default class ServerStatusCommand extends BushCommand { public constructor() { @@ -28,8 +24,8 @@ export default class ServerStatusCommand extends BushCommand { await message.util.reply({ embeds: [msgEmbed] }); let main; try { - await got.get('https://moulberry.codes/lowestbin.json').json(); - main = emojis.success; + const res = await fetch('https://moulberry.codes/lowestbin.json').then((p) => (p.ok ? p.json() : null)); + main = res ? emojis.success : emojis.error; } catch (e) { main = emojis.error; } diff --git a/src/commands/utilities/hash.ts b/src/commands/utilities/hash.ts index 6817f04..251d5e6 100644 --- a/src/commands/utilities/hash.ts +++ b/src/commands/utilities/hash.ts @@ -1,44 +1,44 @@ -import { BushCommand, clientSendAndPermCheck, type CommandMessage } from '#lib'; -import assert from 'assert/strict'; -import crypto from 'crypto'; -import { ApplicationCommandOptionType } from 'discord.js'; -import got from 'got'; +// import { BushCommand, clientSendAndPermCheck, type CommandMessage } from '#lib'; +// import assert from 'assert/strict'; +// import crypto from 'crypto'; +// import { ApplicationCommandOptionType } from 'discord.js'; +// import got from 'got'; -assert(crypto); -assert(got); +// assert(crypto); +// assert(got); -export default class HashCommand extends BushCommand { - public constructor() { - super('hash', { - aliases: ['hash'], - category: 'utilities', - description: 'Gets the file hash of the given discord link', - usage: ['hash <fileUrl>'], - examples: ['hash https://cdn.discordapp.com/emojis/782630946435366942.png?v=1'], //nice - args: [ - { - id: 'url', - description: 'The url of the discord link to find the hash of.', - type: 'url', - prompt: 'What url would you like to find the hash of?', - retry: '{error} Enter a valid url.', - slashType: ApplicationCommandOptionType.String - } - ], - clientPermissions: (m) => clientSendAndPermCheck(m), - userPermissions: [] - }); - } +// export default class HashCommand extends BushCommand { +// public constructor() { +// super('hash', { +// aliases: ['hash'], +// category: 'utilities', +// description: 'Gets the file hash of the given discord link', +// usage: ['hash <fileUrl>'], +// examples: ['hash https://cdn.discordapp.com/emojis/782630946435366942.png?v=1'], //nice +// args: [ +// { +// id: 'url', +// description: 'The url of the discord link to find the hash of.', +// type: 'url', +// prompt: 'What url would you like to find the hash of?', +// retry: '{error} Enter a valid url.', +// slashType: ApplicationCommandOptionType.String +// } +// ], +// clientPermissions: (m) => clientSendAndPermCheck(m), +// userPermissions: [] +// }); +// } - public override async exec(message: CommandMessage, { url }: { url: string }) { - try { - const req = await got.get(url); - const rawHash = crypto.createHash('md5'); - rawHash.update(req.rawBody.toString('binary')); - const hash = rawHash.digest('hex'); - await message.util.reply(`\`${hash}\``); - } catch { - await message.util.reply('Unable to calculate hash.'); - } - } -} +// public override async exec(message: CommandMessage, { url }: { url: string }) { +// try { +// const req = await got.get(url); +// const rawHash = crypto.createHash('md5'); +// rawHash.update(req.rawBody.toString('binary')); +// const hash = rawHash.digest('hex'); +// await message.util.reply(`\`${hash}\``); +// } catch { +// await message.util.reply('Unable to calculate hash.'); +// } +// } +// } diff --git a/src/commands/utilities/price.ts b/src/commands/utilities/price.ts index 8a3b5c6..bfe1f10 100644 --- a/src/commands/utilities/price.ts +++ b/src/commands/utilities/price.ts @@ -1,11 +1,9 @@ import { ArgType, BushCommand, clientSendAndPermCheck, colors, emojis, format, oxford, type CommandMessage } from '#lib'; import assert from 'assert/strict'; import { ApplicationCommandOptionType, AutocompleteInteraction, EmbedBuilder, PermissionFlagsBits } from 'discord.js'; -import Fuse from 'fuse.js'; -import got from 'got'; +import { default as Fuse } from 'fuse.js'; assert(Fuse); -assert(got); export default class PriceCommand extends BushCommand { public static cachedItemList: string[] = []; @@ -57,9 +55,8 @@ export default class PriceCommand extends BushCommand { const [bazaar, currentLowestBIN, averageLowestBIN, auctionAverages] = (await Promise.all( PriceCommand.urls.map(({ url, error }) => - got - .get(url) - .json() + fetch(url) + .then((p) => (p.ok ? p.json() : undefined)) .catch(() => (errors.push(error), undefined)) ) )) as [Bazaar?, LowestBIN?, LowestBIN?, AuctionAverages?]; |