aboutsummaryrefslogtreecommitdiff
path: root/src/commands/utilities
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/utilities
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/utilities')
-rw-r--r--src/commands/utilities/activity.ts4
-rw-r--r--src/commands/utilities/calculator.ts4
-rw-r--r--src/commands/utilities/decode.ts33
-rw-r--r--src/commands/utilities/hash.ts3
-rw-r--r--src/commands/utilities/price.ts11
-rw-r--r--src/commands/utilities/steal.ts4
-rw-r--r--src/commands/utilities/suicide.ts22
-rw-r--r--src/commands/utilities/uuid.ts6
-rw-r--r--src/commands/utilities/viewraw.ts38
-rw-r--r--src/commands/utilities/whoHasRole.ts7
-rw-r--r--src/commands/utilities/wolframAlpha.ts40
11 files changed, 102 insertions, 70 deletions
diff --git a/src/commands/utilities/activity.ts b/src/commands/utilities/activity.ts
index de7e79f..c3839e5 100644
--- a/src/commands/utilities/activity.ts
+++ b/src/commands/utilities/activity.ts
@@ -100,8 +100,8 @@ export default class YouTubeCommand extends BushCommand {
choices: Object.keys(activityMap).map((key) => ({ name: key, value: activityMap[key as keyof typeof activityMap] }))
}
],
- clientPermissions: ['SEND_MESSAGES'],
- userPermissions: ['SEND_MESSAGES']
+ clientPermissions: (m) => util.clientSendAndPermCheck(m),
+ userPermissions: []
});
}
diff --git a/src/commands/utilities/calculator.ts b/src/commands/utilities/calculator.ts
index a2c91e4..743e9b2 100644
--- a/src/commands/utilities/calculator.ts
+++ b/src/commands/utilities/calculator.ts
@@ -33,8 +33,8 @@ export default class CalculatorCommand extends BushCommand {
required: true
}
],
- clientPermissions: ['SEND_MESSAGES'],
- userPermissions: ['SEND_MESSAGES']
+ clientPermissions: (m) => util.clientSendAndPermCheck(m),
+ userPermissions: []
});
}
public override async exec(message: BushMessage | BushSlashMessage, args: { expression: string }): Promise<unknown> {
diff --git a/src/commands/utilities/decode.ts b/src/commands/utilities/decode.ts
index e48c644..c497183 100644
--- a/src/commands/utilities/decode.ts
+++ b/src/commands/utilities/decode.ts
@@ -3,7 +3,7 @@ import { AkairoMessage } from 'discord-akairo';
import { MessageEmbed } from 'discord.js';
const encodingTypesArray = ['ascii', 'utf8', 'utf-8', 'utf16le', 'ucs2', 'ucs-2', 'base64', 'latin1', 'binary', 'hex'];
-const encodingTypesString = '`ascii`, `utf8`, `utf-8`, `utf16le`, `ucs2`, `ucs-2`, `base64`, `latin1`, `binary`, `hex`';
+const encodingTypesString = encodingTypesArray.map((e) => `\`${e}\``).join(', ');
export default class DecodeCommand extends BushCommand {
public constructor() {
@@ -42,43 +42,20 @@ export default class DecodeCommand extends BushCommand {
}
}
],
- clientPermissions: ['SEND_MESSAGES'],
slash: true,
slashOptions: [
{
name: 'from',
description: 'The type of data you are inputting.',
type: 'STRING',
- choices: [
- { name: 'ascii', value: 'ascii' },
- { name: 'utf8', value: 'utf8' },
- { name: 'utf-8', value: 'utf-8' },
- { name: 'utf16le', value: 'utf16le' },
- { name: 'ucs2', value: 'ucs2' },
- { name: 'ucs-2', value: 'ucs-2' },
- { name: 'base64', value: 'base64' },
- { name: 'latin1', value: 'latin1' },
- { name: 'binary', value: 'binary' },
- { name: 'hex', value: 'hex' }
- ],
+ choices: encodingTypesArray.map((e) => ({ name: e, value: e })),
required: true
},
{
name: 'to',
description: 'The type of data you want the output to be.',
type: 'STRING',
- choices: [
- { name: 'ascii', value: 'ascii' },
- { name: 'utf8', value: 'utf8' },
- { name: 'utf-8', value: 'utf-8' },
- { name: 'utf16le', value: 'utf16le' },
- { name: 'ucs2', value: 'ucs2' },
- { name: 'ucs-2', value: 'ucs-2' },
- { name: 'base64', value: 'base64' },
- { name: 'latin1', value: 'latin1' },
- { name: 'binary', value: 'binary' },
- { name: 'hex', value: 'hex' }
- ],
+ choices: encodingTypesArray.map((e) => ({ name: e, value: e })),
required: true
},
{
@@ -87,7 +64,9 @@ export default class DecodeCommand extends BushCommand {
type: 'STRING',
required: true
}
- ]
+ ],
+ clientPermissions: (m) => util.clientSendAndPermCheck(m),
+ userPermissions: []
});
}
diff --git a/src/commands/utilities/hash.ts b/src/commands/utilities/hash.ts
index 16ace93..df604c8 100644
--- a/src/commands/utilities/hash.ts
+++ b/src/commands/utilities/hash.ts
@@ -22,7 +22,8 @@ export default class HashCommand extends BushCommand {
}
}
],
- clientPermissions: ['SEND_MESSAGES']
+ clientPermissions: (m) => util.clientSendAndPermCheck(m),
+ userPermissions: []
});
}
diff --git a/src/commands/utilities/price.ts b/src/commands/utilities/price.ts
index 497935a..a012501 100644
--- a/src/commands/utilities/price.ts
+++ b/src/commands/utilities/price.ts
@@ -51,15 +51,11 @@ export default class PriceCommand extends BushCommand {
super('price', {
aliases: ['price'],
category: 'utilities',
- clientPermissions: ['EMBED_LINKS', 'SEND_MESSAGES'],
description: {
usage: 'price <item id>',
examples: ['price ASPECT_OF_THE_END'],
content: 'Finds the price information of an item.'
},
- ratelimit: 4,
- cooldown: 4000,
- typing: true,
args: [
{
id: 'item',
@@ -91,7 +87,12 @@ export default class PriceCommand extends BushCommand {
type: 'BOOLEAN',
required: false
}
- ]
+ ],
+ clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true),
+ userPermissions: [],
+ ratelimit: 4,
+ cooldown: 4000,
+ typing: true
});
}
diff --git a/src/commands/utilities/steal.ts b/src/commands/utilities/steal.ts
index 7d61016..767534e 100644
--- a/src/commands/utilities/steal.ts
+++ b/src/commands/utilities/steal.ts
@@ -27,8 +27,8 @@ export default class StealCommand extends BushCommand {
],
slash: false,
channel: 'guild',
- clientPermissions: ['SEND_MESSAGES', 'MANAGE_EMOJIS_AND_STICKERS'],
- userPermissions: ['SEND_MESSAGES', 'MANAGE_EMOJIS_AND_STICKERS']
+ clientPermissions: (m) => util.clientSendAndPermCheck(m, ['MANAGE_EMOJIS_AND_STICKERS']),
+ userPermissions: ['MANAGE_EMOJIS_AND_STICKERS']
});
}
public override async exec(
diff --git a/src/commands/utilities/suicide.ts b/src/commands/utilities/suicide.ts
index 58119ef..9289b1c 100644
--- a/src/commands/utilities/suicide.ts
+++ b/src/commands/utilities/suicide.ts
@@ -12,8 +12,8 @@ export default class TemplateCommand extends BushCommand {
examples: ['suicide']
},
slash: true,
- clientPermissions: ['SEND_MESSAGES'],
- userPermissions: ['SEND_MESSAGES'],
+ clientPermissions: (m) => util.clientSendAndPermCheck(m),
+ userPermissions: [],
bypassChannelBlacklist: true
});
}
@@ -29,16 +29,20 @@ export default class TemplateCommand extends BushCommand {
)
.addField(
'**National Suicide Prevention Hotline (U.S.):**',
- `**Call:** 1-800-273-8255, available 24/7 for emotional support
-**Text: HOME** to 741741
-https://suicidepreventionlifeline.org/chat/
-
-**Outside the U.S**: Find a supportive resource on [this Wikipedia list of worldwide crisis hotlines](https://en.wikipedia.org/wiki/List_of_suicide_crisis_lines)`
+ [
+ '**Call:** 1-800-273-8255, available 24/7 for emotional support',
+ '**Text: HOME** to 741741',
+ 'https://suicidepreventionlifeline.org/chat/',
+ '',
+ '**Outside the U.S**: Find a supportive resource on [this Wikipedia list of worldwide crisis hotlines](https://en.wikipedia.org/wiki/List_of_suicide_crisis_lines)'
+ ].join('\n')
)
.addField(
'**More Support**',
- `For Substance Abuse Support, Eating Disorder Support & Child Abuse and Domestic Violence:
-[Click to go to Discord's Health & Safety Page](https://discord.com/safety/360044103771-Mental-health-on-Discord#h_01EGRGT08QSZ5BNCH2E9HN0NYV)`
+ [
+ 'For Substance Abuse Support, Eating Disorder Support & Child Abuse and Domestic Violence:',
+ "[Click to go to Discord's Health & Safety Page](https://discord.com/safety/360044103771-Mental-health-on-Discord#h_01EGRGT08QSZ5BNCH2E9HN0NYV)"
+ ].join('\n')
);
return (
diff --git a/src/commands/utilities/uuid.ts b/src/commands/utilities/uuid.ts
index 50280a0..9484729 100644
--- a/src/commands/utilities/uuid.ts
+++ b/src/commands/utilities/uuid.ts
@@ -14,7 +14,6 @@ export default class UuidCommand extends BushCommand {
{
id: 'ign',
customType: /\w{1,16}/im,
-
prompt: {
start: 'What ign would you like to find the uuid of?',
retry: '{error} Choose a valid ign.',
@@ -22,9 +21,8 @@ export default class UuidCommand extends BushCommand {
}
}
],
- cooldown: 4000,
- ratelimit: 1,
- clientPermissions: ['SEND_MESSAGES']
+ clientPermissions: (m) => util.clientSendAndPermCheck(m),
+ userPermissions: []
});
}
diff --git a/src/commands/utilities/viewraw.ts b/src/commands/utilities/viewraw.ts
index bd185d4..b7017c6 100644
--- a/src/commands/utilities/viewraw.ts
+++ b/src/commands/utilities/viewraw.ts
@@ -3,11 +3,9 @@ import { BushCommand, BushMessage, BushSlashMessage } from '../../lib';
export default class ViewRawCommand extends BushCommand {
public constructor() {
- super('viewraw', {
- aliases: ['viewraw'],
+ super('view-raw', {
+ aliases: ['view-raw', 'vr'],
category: 'utilities',
- clientPermissions: ['EMBED_LINKS'],
- channel: 'guild',
description: {
usage: 'viewraw <message id> <channel>',
examples: ['viewraw 322862723090219008'],
@@ -42,7 +40,37 @@ export default class ViewRawCommand extends BushCommand {
match: 'flag',
flag: '--js'
}
- ]
+ ],
+ slash: true,
+ slashOptions: [
+ {
+ name: 'message',
+ description: 'What message would you like to view?',
+ type: 'STRING',
+ required: true
+ },
+ {
+ name: 'channel',
+ description: 'What channel is the message in?',
+ type: 'CHANNEL',
+ required: false
+ },
+ {
+ name: 'json',
+ description: 'Would you like to view the raw JSON message data?',
+ type: 'BOOLEAN',
+ required: false
+ },
+ {
+ name: 'js',
+ description: 'Would you like to view the raw message data?',
+ type: 'BOOLEAN',
+ required: false
+ }
+ ],
+ channel: 'guild',
+ clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true),
+ userPermissions: []
});
}
diff --git a/src/commands/utilities/whoHasRole.ts b/src/commands/utilities/whoHasRole.ts
index 1b72d65..bce88d6 100644
--- a/src/commands/utilities/whoHasRole.ts
+++ b/src/commands/utilities/whoHasRole.ts
@@ -1,5 +1,6 @@
import { BushCommand, BushMessage, BushSlashMessage } from '@lib';
import { CommandInteraction, Role, Util } from 'discord.js';
+import { ButtonPaginator } from '../../lib/common/ButtonPaginator';
export default class WhoHasRoleCommand extends BushCommand {
public constructor() {
@@ -32,8 +33,8 @@ export default class WhoHasRoleCommand extends BushCommand {
}
],
channel: 'guild',
- clientPermissions: ['SEND_MESSAGES'],
- userPermissions: ['SEND_MESSAGES'],
+ clientPermissions: (m) => util.clientSendAndPermCheck(m),
+ userPermissions: [],
typing: true
});
}
@@ -51,6 +52,6 @@ export default class WhoHasRoleCommand extends BushCommand {
color
}));
- return await util.buttonPaginate(message, embedPages, null, true);
+ return await ButtonPaginator.send(message, embedPages, null, true);
}
}
diff --git a/src/commands/utilities/wolframAlpha.ts b/src/commands/utilities/wolframAlpha.ts
index 4a357b8..049dd60 100644
--- a/src/commands/utilities/wolframAlpha.ts
+++ b/src/commands/utilities/wolframAlpha.ts
@@ -1,5 +1,5 @@
import { AllowedMentions, BushCommand, BushMessage, BushSlashMessage } from '@lib';
-import { CommandInteraction, MessageEmbed } from 'discord.js';
+import { CommandInteraction, MessageEmbed, MessageOptions } from 'discord.js';
import WolframAlphaAPI from 'wolfram-alpha-api';
export default class WolframAlphaCommand extends BushCommand {
@@ -13,6 +13,7 @@ export default class WolframAlphaCommand extends BushCommand {
examples: ['wolfram-alpha what is the population of france']
},
args: [
+ { id: 'image', match: 'flag', flag: '--image' },
{
id: 'expression',
type: 'string',
@@ -31,30 +32,49 @@ export default class WolframAlphaCommand extends BushCommand {
description: 'What would you like to look up?',
type: 'STRING',
required: true
+ },
+ {
+ name: 'image',
+ description: 'Would you like to use the Simple API instead of the Short Answers API?',
+ type: 'BOOLEAN',
+ required: false
}
],
- clientPermissions: ['SEND_MESSAGES'],
- userPermissions: ['SEND_MESSAGES']
+ clientPermissions: (m) => util.clientSendAndPermCheck(m),
+ userPermissions: []
});
}
- public override async exec(message: BushMessage | BushSlashMessage, args: { expression: string }): Promise<unknown> {
+ public override async exec(
+ message: BushMessage | BushSlashMessage,
+ args: { expression: string; image: boolean }
+ ): Promise<unknown> {
if (message.util.isSlash) await (message.interaction as CommandInteraction).deferReply();
+ args.image && void message.util.reply({ content: `${util.emojis.loading} Loading...`, embeds: [] });
const waApi = WolframAlphaAPI(client.config.credentials.wolframAlphaAppId);
const decodedEmbed = new MessageEmbed().addField('📥 Input', await util.inspectCleanRedactCodeblock(args.expression));
+ const sendOptions: MessageOptions = { content: null, allowedMentions: AllowedMentions.none() };
try {
- const calculated = await waApi.getShort(args.expression);
- decodedEmbed
- .setTitle(`${util.emojis.successFull} Successfully Queried Expression`)
- .setColor(util.colors.success)
- .addField('📤 Output', await util.inspectCleanRedactCodeblock(calculated.toString()));
+ const calculated = await (args.image
+ ? waApi.getSimple({ i: args.expression, timeout: 1, background: '2C2F33', foreground: 'white' })
+ : waApi.getShort(args.expression));
+ decodedEmbed.setTitle(`${util.emojis.successFull} Successfully Queried Expression`).setColor(util.colors.success);
+
+ if (args.image) {
+ decodedEmbed.setImage(await util.uploadImageToImgur(calculated.split(',')[1]));
+ decodedEmbed.addField('📤 Output', '​');
+ } else {
+ decodedEmbed.addField('📤 Output', await util.inspectCleanRedactCodeblock(calculated.toString()));
+ }
} catch (error) {
decodedEmbed
.setTitle(`${util.emojis.errorFull} Unable to Query Expression`)
.setColor(util.colors.error)
.addField(`📤 Error`, await util.inspectCleanRedactCodeblock(`${error.name}: ${error.message}`, 'js'));
}
- return await message.util.reply({ embeds: [decodedEmbed], allowedMentions: AllowedMentions.none() });
+ sendOptions.embeds = [decodedEmbed];
+
+ return await message.util.reply(sendOptions);
}
}