aboutsummaryrefslogtreecommitdiff
path: root/src/commands/dev
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/dev')
-rw-r--r--src/commands/dev/__template.ts61
-rw-r--r--src/commands/dev/eval.ts10
-rw-r--r--src/commands/dev/servers.ts48
-rw-r--r--src/commands/dev/setLevel.ts6
-rw-r--r--src/commands/dev/sh.ts84
5 files changed, 202 insertions, 7 deletions
diff --git a/src/commands/dev/__template.ts b/src/commands/dev/__template.ts
new file mode 100644
index 0000000..ffc67ae
--- /dev/null
+++ b/src/commands/dev/__template.ts
@@ -0,0 +1,61 @@
+import { BushCommand, BushMessage, BushSlashMessage } from '@lib';
+
+export default class TemplateCommand extends BushCommand {
+ public constructor() {
+ super('template', {
+ aliases: ['template'],
+ category: 'template',
+ description: {
+ content: 'Command description.',
+ usage: 'template <requiredArg> [optionalArg]',
+ examples: ['template 1 2']
+ },
+ args: [
+ {
+ id: 'required_argument',
+ type: 'string',
+ match: 'phrase',
+ prompt: {
+ start: 'What would you like to set your first argument to be?',
+ retry: '{error} Pick a valid argument.',
+ optional: false
+ }
+ },
+ {
+ id: 'optional_argument',
+ type: 'string',
+ match: 'phrase',
+ prompt: {
+ start: 'What would you like to set your second argument to be?',
+ retry: '{error} Pick a valid argument.',
+ optional: true
+ }
+ }
+ ],
+ slash: false, //set this to true
+ slashOptions: [
+ {
+ name: 'required_argument',
+ description: 'What would you like to set your first argument to be?',
+ type: 'STRING',
+ required: true
+ },
+ {
+ name: 'optional_argument',
+ description: 'What would you like to set your second argument to be?',
+ type: 'STRING',
+ required: false
+ }
+ ],
+ superUserOnly: true,
+ ownerOnly: true,
+ channel: 'guild',
+ hidden: true,
+ clientPermissions: ['SEND_MESSAGES'],
+ userPermissions: ['SEND_MESSAGES']
+ });
+ }
+ public async exec(message: BushMessage | BushSlashMessage): Promise<unknown> {
+ return await message.util.reply(`${this.client.util.emojis.error} Do not use the template command.`);
+ }
+}
diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts
index f3a30ab..76a78ba 100644
--- a/src/commands/dev/eval.ts
+++ b/src/commands/dev/eval.ts
@@ -20,7 +20,7 @@ export default class EvalCommand extends BushCommand {
aliases: ['eval', 'ev'],
category: 'dev',
description: {
- content: 'Use the command to eval stuff in the bot.',
+ content: 'Evaluate code.',
usage: 'eval [--depth #] <code> [--sudo] [--silent] [--delete] [--proto] [--hidden] [--ts]',
examples: ['eval message.guild.name', 'eval this.client.ownerID']
},
@@ -72,7 +72,6 @@ export default class EvalCommand extends BushCommand {
}
}
],
- ownerOnly: true,
slash: true,
slashOptions: [
{
@@ -117,7 +116,8 @@ export default class EvalCommand extends BushCommand {
type: 'BOOLEAN',
required: false
}
- ]
+ ],
+ ownerOnly: true
});
}
@@ -141,8 +141,8 @@ export default class EvalCommand extends BushCommand {
}
const code: { js?: string | null; ts?: string | null; lang?: 'js' | 'ts' } = {};
args.code = args.code.replace(/[“”]/g, '"');
- args.code = args.code.replace(/```/g, '');
- if (args.typescript) {
+ args.code = args.code.replace(/```*(?:js|ts)?/g, '');
+ if (args.typescript || message) {
code.ts = args.code;
code.js = transpile(args.code);
code.lang = 'ts';
diff --git a/src/commands/dev/servers.ts b/src/commands/dev/servers.ts
new file mode 100644
index 0000000..08f74e8
--- /dev/null
+++ b/src/commands/dev/servers.ts
@@ -0,0 +1,48 @@
+import { Guild, MessageEmbed } from 'discord.js';
+import { BushCommand, BushMessage, BushSlashMessage } from '../../lib';
+
+export default class ServersCommand extends BushCommand {
+ public constructor() {
+ super('servers', {
+ aliases: ['servers'],
+ category: 'dev',
+ description: {
+ content: 'Displays all the severs the bot is in',
+ usage: 'servers',
+ examples: ['servers']
+ },
+ clientPermissions: ['SEND_MESSAGES'],
+ userPermissions: ['SEND_MESSAGES'],
+ superUserOnly: true
+ });
+ }
+
+ public async exec(message: BushMessage | BushSlashMessage): Promise<unknown> {
+ const maxLength = 10;
+ const guilds = this.client.guilds.cache.sort((a, b) => (a.memberCount < b.memberCount ? 1 : -1)).array();
+ const chunkedGuilds: Guild[][] = [];
+ const embeds: MessageEmbed[] = [];
+
+ for (let i = 0, j = guilds.length; i < j; i += maxLength) {
+ chunkedGuilds.push(guilds.slice(i, i + maxLength));
+ }
+
+ chunkedGuilds.forEach((c: Guild[]) => {
+ const embed = new MessageEmbed();
+ c.forEach((g: Guild) => {
+ const owner = this.client.users.cache.get(g.ownerId)?.tag;
+ embed
+ .addField(
+ `**${g.name}**`,
+ `**ID:** ${g.id}\n**Owner:** ${owner ? owner : g.ownerId}\n**Members:** ${g.memberCount.toLocaleString()}`,
+ false
+ )
+ .setTitle('Server List')
+ .setColor(this.client.util.colors.default);
+ });
+ embeds.push(embed);
+ });
+
+ return await this.client.util.buttonPaginate(message, embeds);
+ }
+}
diff --git a/src/commands/dev/setLevel.ts b/src/commands/dev/setLevel.ts
index f2ae6c7..4ec4c08 100644
--- a/src/commands/dev/setLevel.ts
+++ b/src/commands/dev/setLevel.ts
@@ -54,10 +54,12 @@ export default class SetLevelCommand extends BushCommand {
const [levelEntry] = await Level.findOrBuild({
where: {
- id: user.id
+ user: user.id,
+ guild: message.guild.id
},
defaults: {
- id: user.id
+ user: user.id,
+ guild: message.guild.id
}
});
await levelEntry.update({ xp: Level.convertLevelToXp(level) });
diff --git a/src/commands/dev/sh.ts b/src/commands/dev/sh.ts
new file mode 100644
index 0000000..d53e500
--- /dev/null
+++ b/src/commands/dev/sh.ts
@@ -0,0 +1,84 @@
+import { BushCommand, BushMessage, BushSlashMessage } from '@lib';
+import chalk from 'chalk';
+import { exec } from 'child_process';
+import { Constants } from 'discord-akairo';
+import { MessageEmbed, Util } from 'discord.js';
+import { promisify } from 'util';
+
+const sh = promisify(exec);
+const clean = (text) => {
+ chalk.toString;
+ if (typeof text === 'string') {
+ return (text = Util.cleanCodeBlockContent(text));
+ } else return text;
+};
+export default class ShCommand extends BushCommand {
+ public constructor() {
+ super('sh', {
+ aliases: ['sh', 'shell', 'cmd'],
+ category: 'dev',
+ description: {
+ content: 'Run shell commands.',
+ usage: 'sh <command>',
+ examples: ['sh git pull']
+ },
+ args: [
+ {
+ id: 'command',
+ type: Constants.ArgumentTypes.STRING,
+ match: Constants.ArgumentMatches.REST,
+ prompt: {
+ start: 'What would you like run',
+ retry: '{error} Invalid command to run.'
+ }
+ }
+ ],
+ ownerOnly: true
+ });
+ }
+
+ public async exec(message: BushMessage | BushSlashMessage, { command }: { command: string }): Promise<unknown> {
+ if (!this.client.config.owners.includes(message.author.id))
+ return await message.util.reply(`${this.client.util.emojis.error} Only my developers can run this command.`);
+ const input = clean(command);
+
+ const embed = new MessageEmbed()
+ .setColor(this.client.util.colors.gray)
+ .setFooter(message.author.tag, message.author.avatarURL({ dynamic: true }))
+ .setTimestamp()
+ .setTitle('Shell Command')
+ .addField('📥 Input', await this.client.util.codeblock(input, 1024, 'sh'))
+ .addField('Running', this.client.util.emojis.loading);
+
+ await message.util.reply({ embeds: [embed] });
+
+ const pattern = [
+ '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
+ '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
+ ].join('|');
+ function strip(abc: string): string {
+ return abc.replace(new RegExp(pattern, 'g'), '');
+ }
+ try {
+ const output = await sh(command);
+ const stdout = strip(clean(output.stdout));
+ const stderr = strip(clean(output.stderr));
+
+ embed
+ .setTitle(`${this.client.util.emojis.successFull} Executed command successfully.`)
+ .setColor(this.client.util.colors.success)
+ .spliceFields(1, 1);
+
+ if (stdout) embed.addField('📤 stdout', await this.client.util.codeblock(stdout, 1024, 'json'));
+ if (stderr) embed.addField('📤 stderr', await this.client.util.codeblock(stderr, 1024, 'json'));
+ } catch (e) {
+ embed
+ .setTitle(`${this.client.util.emojis.errorFull} An error occurred while executing.`)
+ .setColor(this.client.util.colors.error)
+ .spliceFields(1, 1);
+
+ embed.addField('📤 Output', await this.client.util.codeblock(e?.stack, 1024, 'js'));
+ }
+ await message.util.edit({ embeds: [embed] });
+ }
+}