aboutsummaryrefslogtreecommitdiff
path: root/src/commands/utilities
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-07-14 21:22:09 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-07-14 21:22:09 -0400
commit53d2b18f7f73d5696fb7cd86d1c164a790dfdcc3 (patch)
treef95f23aad382879b35860d4d3be3642068fac8a2 /src/commands/utilities
parenteaaae08aeee1fa16a4e1ad0b26fceb42885bfcde (diff)
downloadtanzanite-53d2b18f7f73d5696fb7cd86d1c164a790dfdcc3.tar.gz
tanzanite-53d2b18f7f73d5696fb7cd86d1c164a790dfdcc3.tar.bz2
tanzanite-53d2b18f7f73d5696fb7cd86d1c164a790dfdcc3.zip
started moving over some other commands
Diffstat (limited to 'src/commands/utilities')
-rw-r--r--src/commands/utilities/_whoHasRole.ts (renamed from src/commands/utilities/whoHasRole.ts)0
-rw-r--r--src/commands/utilities/decode.ts131
-rw-r--r--src/commands/utilities/serverStatus.ts58
-rw-r--r--src/commands/utilities/uuid.ts43
-rw-r--r--src/commands/utilities/viewraw.ts75
5 files changed, 307 insertions, 0 deletions
diff --git a/src/commands/utilities/whoHasRole.ts b/src/commands/utilities/_whoHasRole.ts
index e69de29..e69de29 100644
--- a/src/commands/utilities/whoHasRole.ts
+++ b/src/commands/utilities/_whoHasRole.ts
diff --git a/src/commands/utilities/decode.ts b/src/commands/utilities/decode.ts
new file mode 100644
index 0000000..97ff444
--- /dev/null
+++ b/src/commands/utilities/decode.ts
@@ -0,0 +1,131 @@
+import { AllowedMentions, BushCommand, BushMessage } from '@lib';
+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`';
+
+export default class DecodeCommand extends BushCommand {
+ public constructor() {
+ super('decode', {
+ aliases: ['decode', 'encode'],
+ category: 'utilities',
+ description: {
+ content: 'Decode / encode.',
+ usage: 'decode <from> <to> <data>',
+ examples: ['decode base64 ascii TmVyZApJbWFnaW5lIGRlY29kaW5nIHRoaXMgbG1hbw==']
+ },
+ args: [
+ {
+ id: 'from',
+ type: encodingTypesArray,
+ prompt: {
+ start: 'What is the encoding of the original data?',
+ retry: `{error} Choose one of the following ${encodingTypesString} for the encoding of the original data.`
+ }
+ },
+ {
+ id: 'to',
+ type: encodingTypesArray,
+ prompt: {
+ start: 'What would you like the encoding of the resulting data to be?',
+ retry: `{error} Choose one of the following ${encodingTypesString} for the encoding of the resulting data.`
+ }
+ },
+ {
+ id: 'data',
+ type: 'string',
+ match: 'restContent',
+ prompt: {
+ start: 'What would you to decode.',
+ retry: '{error} Choose a valid string to decode.'
+ }
+ }
+ ],
+ 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' }
+ ]
+ },
+ {
+ 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' }
+ ]
+ },
+ {
+ name: 'data',
+ description: 'What you would like to decode.',
+ type: 'STRING'
+ }
+ ]
+ });
+ }
+
+ public async exec(
+ message: BushMessage,
+ { from, to, data }: { from: BufferEncoding; to: BufferEncoding; data: string }
+ ): Promise<unknown> {
+ const encodeOrDecode = message?.util?.parsed?.alias?.charAt(0).toUpperCase() + message?.util?.parsed?.alias?.slice(1);
+ const decodedEmbed = new MessageEmbed()
+ .setTitle(`${encodeOrDecode} Information`)
+ .addField('📥 Input', await this.client.util.codeblock(data, 1024));
+ try {
+ const decoded = Buffer.from(data, from).toString(to);
+ decodedEmbed
+ .setColor(this.client.util.colors.success)
+ .addField('📤 Output', await this.client.util.codeblock(decoded, 1024));
+ } catch (error) {
+ decodedEmbed
+ .setColor(this.client.util.colors.error)
+ .addField(`📤 Error ${encodeOrDecode.slice(1)}ing`, await this.client.util.codeblock(error.stack, 1024));
+ }
+ return await message.util.send({ embeds: [decodedEmbed], allowedMentions: AllowedMentions.none() });
+ }
+
+ public async execSlash(
+ message: AkairoMessage,
+ { from, to, data }: { from: BufferEncoding; to: BufferEncoding; data: string }
+ ): Promise<unknown> {
+ const decodedEmbed = new MessageEmbed()
+ .setTitle(`Decoded Information`)
+ .addField('📥 Input', await this.client.util.codeblock(data, 1024));
+ try {
+ const decoded = Buffer.from(data, from).toString(to);
+ decodedEmbed
+ .setColor(this.client.util.colors.success)
+ .addField('📤 Output', await this.client.util.codeblock(decoded, 1024));
+ } catch (error) {
+ decodedEmbed
+ .setColor(this.client.util.colors.error)
+ .addField(`📤 Error decoding`, await this.client.util.codeblock(error.stack, 1024));
+ }
+ return await message.interaction.reply({ embeds: [decodedEmbed], allowedMentions: AllowedMentions.none() });
+ }
+}
diff --git a/src/commands/utilities/serverStatus.ts b/src/commands/utilities/serverStatus.ts
new file mode 100644
index 0000000..a20f0b2
--- /dev/null
+++ b/src/commands/utilities/serverStatus.ts
@@ -0,0 +1,58 @@
+import { MessageEmbed } from 'discord.js';
+import got from 'got';
+import { BushCommand, BushMessage } from '../../lib';
+
+export default class ServerStatusCommand extends BushCommand {
+ public constructor() {
+ super('serverstatus', {
+ aliases: ['serverstatus', 'ss'],
+ category: 'utilities',
+ description: {
+ usage: 'serverstatus',
+ examples: ['serverstatus', 'ss'],
+ content: "Gives the status of moulberry's server"
+ },
+ ratelimit: 4,
+ cooldown: 4000,
+ clientPermissions: ['EMBED_LINKS', 'SEND_MESSAGES'],
+ slash: true
+ });
+ }
+
+ public async exec(message: BushMessage): Promise<void> {
+ const msgEmbed: MessageEmbed = new MessageEmbed()
+ .setTitle('Server status')
+ .setDescription(`Checking server:\n${this.client.util.emojis.loading}`)
+ .setColor(this.client.util.colors.default)
+ .setFooter('Checking https://moulberry.codes/lowestbin.json');
+ await message.util.reply({ embeds: [msgEmbed] });
+ let main;
+ try {
+ await got.get('https://moulberry.codes/lowestbin.json').json();
+ main = this.client.util.emojis.success;
+ } catch (e) {
+ main = this.client.util.emojis.error;
+ }
+ await message.util.edit({ embeds: [msgEmbed.setDescription(`Checking server:\n${main}`)] });
+ if (main == this.client.util.emojis.success) {
+ await message.util.edit({
+ embeds: [
+ msgEmbed
+ .addField('Status', 'The server is online, all features related to prices will likely work.')
+ .setColor(this.client.util.colors.success)
+ ]
+ });
+ } else {
+ await message.util.edit({
+ embeds: [
+ msgEmbed
+ .addField(
+ 'Status',
+ "It appears Moulberry's server is offline, this means that everything related to prices will likely not work."
+ )
+ .setColor(this.client.util.colors.error)
+ ]
+ });
+ }
+ }
+}
diff --git a/src/commands/utilities/uuid.ts b/src/commands/utilities/uuid.ts
new file mode 100644
index 0000000..0b96ce1
--- /dev/null
+++ b/src/commands/utilities/uuid.ts
@@ -0,0 +1,43 @@
+import { Constants } from 'discord-akairo';
+import { BushCommand, BushMessage } from '../../lib';
+
+export default class UuidCommand extends BushCommand {
+ public constructor() {
+ super('uuid', {
+ aliases: ['uuid'],
+ category: 'utilities',
+ description: {
+ content: "Find someone's minecraft uuid",
+ usage: 'uuid <ign>',
+ examples: ['uuid ironm00n']
+ },
+ args: [
+ {
+ id: 'ign',
+ type: /\w{1,16}/im,
+ match: Constants.ArgumentMatches.PHRASE,
+ prompt: {
+ start: 'What ign would you like to find the uuid of?',
+ retry: '{error} Choose a valid ign.',
+ optional: false
+ }
+ }
+ ],
+ cooldown: 4000,
+ ratelimit: 1,
+ clientPermissions: ['SEND_MESSAGES']
+ });
+ }
+
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ public async exec(message: BushMessage, { ign }: { ign: { match: any[]; matches: any[] } }): Promise<unknown> {
+ if (!ign) return await message.util.reply(`${this.client.util.emojis.error} Please enter a valid ign.`);
+ const readableIGN = ign.match[0];
+ try {
+ const uuid = await this.client.util.findUUID(readableIGN);
+ return await message.util.reply(`The uuid for \`${readableIGN}\` is \`${uuid}\``);
+ } catch (e) {
+ return await message.util.reply(`${this.client.util.emojis.error} Could not find an uuid for \`${readableIGN}\`.`);
+ }
+ }
+}
diff --git a/src/commands/utilities/viewraw.ts b/src/commands/utilities/viewraw.ts
new file mode 100644
index 0000000..7642b2a
--- /dev/null
+++ b/src/commands/utilities/viewraw.ts
@@ -0,0 +1,75 @@
+import { Argument, Constants } from 'discord-akairo';
+import { DMChannel, Message, MessageEmbed, NewsChannel, Snowflake, TextChannel } from 'discord.js';
+import { inspect } from 'util';
+import { BushCommand, BushMessage, BushSlashMessage } from '../../lib';
+
+export default class ViewRawCommand extends BushCommand {
+ public constructor() {
+ super('viewraw', {
+ aliases: ['viewraw'],
+ category: 'info',
+ clientPermissions: ['EMBED_LINKS'],
+ description: {
+ usage: 'viewraw <message id> <channel>',
+ examples: ['viewraw 322862723090219008'],
+ content: 'Gives information about a specified user.'
+ },
+ args: [
+ {
+ id: 'message',
+ type: Argument.union(Constants.ArgumentTypes.MESSAGE, Constants.ArgumentTypes.BIGINT),
+ match: Constants.ArgumentMatches.PHRASE,
+ prompt: {
+ start: 'What message would you like to view?',
+ retry: '{error} Choose a valid message.',
+ optional: false
+ }
+ },
+ {
+ id: 'channel',
+ type: Constants.ArgumentTypes.CHANNEL,
+ match: Constants.ArgumentMatches.PHRASE,
+ prompt: {
+ start: 'What channel is the message in?',
+ retry: '{error} Choose a valid channel.',
+ optional: true
+ },
+ default: (m) => m.channel
+ },
+ {
+ id: 'json',
+ match: Constants.ArgumentMatches.FLAG,
+ flag: '--json'
+ }
+ ]
+ });
+ }
+
+ public async exec(
+ message: BushMessage | BushSlashMessage,
+ args: { message: Message | BigInt; channel: TextChannel | NewsChannel | DMChannel; json?: boolean }
+ ): Promise<unknown> {
+ let newMessage: Message | 0;
+ if (!(typeof args.message === 'object')) {
+ newMessage = await args.channel.messages.fetch(`${args.message}` as Snowflake).catch(() => {
+ return 0;
+ });
+ if (!newMessage) {
+ return await message.util.reply(
+ `${this.client.util.emojis.error} There was an error fetching that message, try supplying a channel.`
+ );
+ }
+ } else {
+ newMessage = args.message as Message;
+ }
+ const content = args.json ? inspect(newMessage.toJSON()) || '[No Content]' : newMessage.content || '[No Content]';
+ const messageEmbed = new MessageEmbed()
+ .setFooter(newMessage.author.tag, newMessage.author.avatarURL({ dynamic: true }))
+ .setTimestamp(newMessage.createdTimestamp)
+ .setColor(newMessage.member?.roles?.color?.color || this.client.util.colors.default)
+ .setTitle('Raw Message Information')
+ .setDescription(await this.client.util.codeblock(content, 2048, 'js'));
+
+ return await message.util.reply({ embeds: [messageEmbed] });
+ }
+}