From 481a157a177e60f023b59e4e9acffc549760db40 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 26 May 2021 16:53:45 +0000 Subject: Automatically format code --- src/commands/info/pronouns.ts | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'src/commands') diff --git a/src/commands/info/pronouns.ts b/src/commands/info/pronouns.ts index 07d210f..97cca34 100644 --- a/src/commands/info/pronouns.ts +++ b/src/commands/info/pronouns.ts @@ -59,9 +59,17 @@ export default class PronounsCommand extends BotCommand { slashEmphemeral: true // I'll add dynamic checking to this later }); } - async sendResponse(message: Message|CommandInteraction, user: User, author: boolean): Promise { + async sendResponse( + message: Message | CommandInteraction, + user: User, + author: boolean + ): Promise { try { - const apiRes: { pronouns: pronounsType } = await got.get(`https://pronoundb.org/api/v1/lookup?platform=discord&id=${user.id}`).json(); + const apiRes: { pronouns: pronounsType } = await got + .get( + `https://pronoundb.org/api/v1/lookup?platform=discord&id=${user.id}` + ) + .json(); if (message instanceof Message) { message.reply( new MessageEmbed({ @@ -71,7 +79,7 @@ export default class PronounsCommand extends BotCommand { text: 'Data provided by https://pronoundb.org/' } }) - ) + ); } else { message.reply({ embeds: [ @@ -83,24 +91,31 @@ export default class PronounsCommand extends BotCommand { } }) ] - }) + }); } } catch (e) { if (e instanceof HTTPError && e.response.statusCode === 404) { if (author) { - await message.reply('You do not appear to have any pronouns set. Please go to https://pronoundb.org/ and set your pronouns.'); + await message.reply( + 'You do not appear to have any pronouns set. Please go to https://pronoundb.org/ and set your pronouns.' + ); } else { - await message.reply(`${user.tag} does not appear to have any pronouns set. Please tell them to go to https://pronoundb.org/ and set their pronouns.`); + await message.reply( + `${user.tag} does not appear to have any pronouns set. Please tell them to go to https://pronoundb.org/ and set their pronouns.` + ); } } else throw e; } } async exec(message: Message, { user }: { user?: User }): Promise { const u = user || message.author; - await this.sendResponse(message, u, u.id === message.author.id) + await this.sendResponse(message, u, u.id === message.author.id); } - async execSlash(message: CommandInteraction, { user }: { user?: SlashCommandOption }): Promise { - const u = user?.user || message.user - await this.sendResponse(message, u, u.id === message.user.id) + async execSlash( + message: CommandInteraction, + { user }: { user?: SlashCommandOption } + ): Promise { + const u = user?.user || message.user; + await this.sendResponse(message, u, u.id === message.user.id); } -} \ No newline at end of file +} -- cgit From 0caccda67d97dd74405aa4ece5d3f07e7c7dfc66 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Wed, 26 May 2021 21:36:50 -0400 Subject: some rebranding --- src/commands/admin/prefix.ts | 70 -------------- src/commands/dev/eval.ts | 138 ++++++++++++++++++++++++++++ src/commands/dev/reload.ts | 44 +++++++++ src/commands/dev/setlevel.ts | 91 ++++++++++++++++++ src/commands/info/botinfo.ts | 4 +- src/commands/info/help.ts | 10 +- src/commands/info/ping.ts | 4 +- src/commands/info/pronouns.ts | 4 +- src/commands/moderation/ban.ts | 4 +- src/commands/moderation/kick.ts | 4 +- src/commands/moderation/modlog.ts | 4 +- src/commands/moderation/role.ts | 4 +- src/commands/moderation/warn.ts | 4 +- src/commands/moulberry-bush/capeperms.ts | 4 +- src/commands/moulberry-bush/giveawayping.ts | 4 +- src/commands/moulberry-bush/level.ts | 5 +- src/commands/moulberry-bush/rule.ts | 4 +- src/commands/owner/eval.ts | 138 ---------------------------- src/commands/owner/reload.ts | 43 --------- src/commands/owner/setlevel.ts | 90 ------------------ src/commands/server-config/prefix.ts | 71 ++++++++++++++ 21 files changed, 374 insertions(+), 370 deletions(-) delete mode 100644 src/commands/admin/prefix.ts create mode 100644 src/commands/dev/eval.ts create mode 100644 src/commands/dev/reload.ts create mode 100644 src/commands/dev/setlevel.ts delete mode 100644 src/commands/owner/eval.ts delete mode 100644 src/commands/owner/reload.ts delete mode 100644 src/commands/owner/setlevel.ts create mode 100644 src/commands/server-config/prefix.ts (limited to 'src/commands') diff --git a/src/commands/admin/prefix.ts b/src/commands/admin/prefix.ts deleted file mode 100644 index 112f6b8..0000000 --- a/src/commands/admin/prefix.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { ApplicationCommandOptionType } from 'discord-api-types'; -import { CommandInteraction, Message, Guild as DiscordGuild } from 'discord.js'; -import { BotCommand } from '../../lib/extensions/BotCommand'; -import { SlashCommandOption } from '../../lib/extensions/Util'; -import { Guild } from '../../lib/models'; - -export default class PrefixCommand extends BotCommand { - constructor() { - super('prefix', { - aliases: ['prefix'], - args: [ - { - id: 'prefix' - } - ], - userPermissions: ['MANAGE_GUILD'], - description: { - content: - 'Set the prefix of the current server (resets to default if prefix is not given)', - usage: 'prefix [prefix]', - examples: ['prefix', 'prefix +'] - }, - slashCommandOptions: [ - { - type: ApplicationCommandOptionType.STRING, - name: 'prefix', - description: 'The prefix to set for this server', - required: false - } - ] - }); - } - - async changePrefix(guild: DiscordGuild, prefix?: string): Promise { - if (prefix) { - const row = await Guild.findByPk(guild.id); - row.prefix = prefix; - await row.save(); - } else { - const row = await Guild.findByPk(guild.id); - row.prefix = this.client.config.prefix; - await row.save(); - } - } - - async exec(message: Message, { prefix }: { prefix?: string }): Promise { - await this.changePrefix(message.guild, prefix); - if (prefix) { - await message.util.send(`Sucessfully set prefix to \`${prefix}\``); - } else { - await message.util.send( - `Sucessfully reset prefix to \`${this.client.config.prefix}\`` - ); - } - } - - async execSlash( - message: CommandInteraction, - { prefix }: { prefix?: SlashCommandOption } - ): Promise { - await this.changePrefix(message.guild, prefix?.value); - if (prefix) { - await message.reply(`Sucessfully set prefix to \`${prefix.value}\``); - } else { - await message.reply( - `Sucessfully reset prefix to \`${this.client.config.prefix}\`` - ); - } - } -} diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts new file mode 100644 index 0000000..83e63f6 --- /dev/null +++ b/src/commands/dev/eval.ts @@ -0,0 +1,138 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { MessageEmbed, Message } from 'discord.js'; +import { inspect, promisify } from 'util'; +import { exec } from 'child_process'; + +const clean = (text) => { + if (typeof text === 'string') + return text + .replace(/`/g, '`' + String.fromCharCode(8203)) + .replace(/@/g, '@' + String.fromCharCode(8203)); + else return text; +}; + +export default class EvalCommand extends BushCommand { + public constructor() { + super('eval', { + aliases: ['eval', 'ev'], + category: 'dev', + description: { + content: 'Use the command to eval stuff in the bot.', + usage: 'eval [--silent] [--depth #]', + examples: ['eval message.guild.name', 'eval this.client.ownerID'] + }, + args: [ + { + id: 'depth', + match: 'option', + type: 'number', + flag: '--depth', + default: 0 + }, + { + id: 'silent', + match: 'flag', + flag: '--silent' + }, + { + id: 'code', + match: 'rest', + type: 'string', + prompt: { + start: 'What would you like to eval?', + retry: 'Invalid code to eval. What would you like to eval?' + } + } + ], + ownerOnly: true, + clientPermissions: ['EMBED_LINKS'] + }); + } + + public async exec( + message: Message, + { depth, code, silent }: { depth: number; code: string; silent: boolean } + ): Promise { + const embed: MessageEmbed = new MessageEmbed(); + + try { + let output; + const me = message.member, + member = message.member, + bot = this.client, + guild = message.guild, + channel = message.channel, + config = this.client.config, + sh = promisify(exec), + models = this.client.db.models, + got = require('got'); // eslint-disable-line @typescript-eslint/no-var-requires + output = eval(code); + output = await output; + if (typeof output !== 'string') output = inspect(output, { depth }); + output = output.replace( + new RegExp(this.client.token, 'g'), + '[token omitted]' + ); + output = clean(output); + embed + .setTitle('✅ Evaled code successfully') + .addField( + '📥 Input', + code.length > 1012 + ? 'Too large to display. Hastebin: ' + + (await this.client.util.haste(code)) + : '```js\n' + code + '```' + ) + .addField( + '📤 Output', + output.length > 1012 + ? 'Too large to display. Hastebin: ' + + (await this.client.util.haste(output)) + : '```js\n' + output + '```' + ) + .setColor('#66FF00') + .setFooter( + message.author.username, + message.author.displayAvatarURL({ dynamic: true }) + ) + .setTimestamp(); + } catch (e) { + embed + .setTitle('❌ Code was not able to be evaled') + .addField( + '📥 Input', + code.length > 1012 + ? 'Too large to display. Hastebin: ' + + (await this.client.util.haste(code)) + : '```js\n' + code + '```' + ) + .addField( + '📤 Output', + e.length > 1012 + ? 'Too large to display. Hastebin: ' + + (await this.client.util.haste(e)) + : '```js\n' + + e + + '```Full stack:' + + (await this.client.util.haste(e.stack)) + ) + .setColor('#FF0000') + .setFooter( + message.author.username, + message.author.displayAvatarURL({ dynamic: true }) + ) + .setTimestamp(); + } + if (!silent) { + await message.util.send(embed); + } else { + try { + await message.author.send(embed); + await message.react(''); + } catch (e) { + await message.react('❌'); + } + } + } +} diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts new file mode 100644 index 0000000..64e5745 --- /dev/null +++ b/src/commands/dev/reload.ts @@ -0,0 +1,44 @@ +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { stripIndent } from 'common-tags'; +import { Message } from 'discord.js'; +import { CommandInteraction } from 'discord.js'; + +export default class ReloadCommand extends BushCommand { + constructor() { + super('reload', { + aliases: ['reload'], + category: 'dev', + description: { + content: 'Reloads the bot', + usage: 'reload', + examples: ['reload'] + }, + ownerOnly: true, + typing: true + }); + } + + private async getResponse(): Promise { + try { + await this.client.util.shell('yarn rimraf dist/'); + await this.client.util.shell('yarn tsc'); + this.client.commandHandler.reloadAll(); + this.client.listenerHandler.reloadAll(); + this.client.inhibitorHandler.reloadAll(); + return '🔁 Successfully reloaded!'; + } catch (e) { + return stripIndent` + An error occured while reloading: + ${await this.client.util.haste(e.stack)} + `; + } + } + + public async exec(message: Message): Promise { + await message.util.send(await this.getResponse()); + } + + public async execSlash(message: CommandInteraction): Promise { + await message.reply(await this.getResponse()); + } +} diff --git a/src/commands/dev/setlevel.ts b/src/commands/dev/setlevel.ts new file mode 100644 index 0000000..d1701c5 --- /dev/null +++ b/src/commands/dev/setlevel.ts @@ -0,0 +1,91 @@ +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { CommandInteraction } from 'discord.js'; +import { User } from 'discord.js'; +import { Message } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { SlashCommandOption } from '../../lib/extensions/Util'; +import { Level } from '../../lib/models'; +import AllowedMentions from '../../lib/utils/AllowedMentions'; + +export default class SetLevelCommand extends BushCommand { + constructor() { + super('setlevel', { + aliases: ['setlevel'], + category: 'dev', + description: { + content: 'Sets the level of a user', + usage: 'setlevel ', + examples: ['setlevel @Moulberry 69'] //nice + }, + args: [ + { + id: 'user', + type: 'user', + prompt: { + start: 'What user would you like to change the level of?', + retry: + 'Invalid user. What user would you like to change the level of?' + } + }, + { + id: 'level', + type: 'number', + prompt: { + start: 'What level would you like to set?', + retry: 'Invalid user. What level would you like to set?' + } + } + ], + ownerOnly: true, + slashCommandOptions: [ + { + type: ApplicationCommandOptionType.USER, + name: 'user', + description: 'The user to change the level of', + required: true + }, + { + type: ApplicationCommandOptionType.INTEGER, + name: 'level', + description: 'The level to set the user to', + required: true + } + ] + }); + } + + private async setLevel(user: User, level: number): Promise { + const [levelEntry] = await Level.findOrBuild({ + where: { + id: user.id + }, + defaults: { + id: user.id + } + }); + levelEntry.xp = Level.convertLevelToXp(level); + await levelEntry.save(); + return `Successfully set level of <@${user.id}> to \`${level}\` (\`${levelEntry.xp}\` XP)`; + } + + async exec( + message: Message, + { user, level }: { user: User; level: number } + ): Promise { + await message.util.send(await this.setLevel(user, level), { + allowedMentions: AllowedMentions.none() + }); + } + + async execSlash( + message: CommandInteraction, + { + user, + level + }: { user: SlashCommandOption; level: SlashCommandOption } + ): Promise { + await message.reply(await this.setLevel(user.user, level.value), { + allowedMentions: AllowedMentions.none() + }); + } +} diff --git a/src/commands/info/botinfo.ts b/src/commands/info/botinfo.ts index 8f5f055..e6a4fbb 100644 --- a/src/commands/info/botinfo.ts +++ b/src/commands/info/botinfo.ts @@ -1,8 +1,8 @@ import { MessageEmbed, Message, CommandInteraction } from 'discord.js'; -import { BotCommand } from '../../lib/extensions/BotCommand'; +import { BushCommand } from '../../lib/extensions/BushCommand'; import { duration } from 'moment'; -export default class BotInfoCommand extends BotCommand { +export default class BotInfoCommand extends BushCommand { constructor() { super('botinfo', { aliases: ['botinfo'], diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index 116669c..30c2a21 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -1,11 +1,11 @@ import { Message, MessageEmbed } from 'discord.js'; -import { BotCommand } from '../../lib/extensions/BotCommand'; +import { BushCommand } from '../../lib/extensions/BushCommand'; import { stripIndent } from 'common-tags'; import { ApplicationCommandOptionType } from 'discord-api-types'; import { CommandInteraction } from 'discord.js'; import { SlashCommandOption } from '../../lib/extensions/Util'; -export default class HelpCommand extends BotCommand { +export default class HelpCommand extends BushCommand { constructor() { super('help', { aliases: ['help'], @@ -32,7 +32,7 @@ export default class HelpCommand extends BotCommand { }); } - private generateEmbed(command?: BotCommand): MessageEmbed { + private generateEmbed(command?: BushCommand): MessageEmbed { const prefix = this.handler.prefix; if (!command) { const embed = new MessageEmbed() @@ -85,7 +85,7 @@ export default class HelpCommand extends BotCommand { public async exec( message: Message, - { command }: { command: BotCommand } + { command }: { command: BushCommand } ): Promise { await message.util.send(this.generateEmbed(command)); } @@ -97,7 +97,7 @@ export default class HelpCommand extends BotCommand { if (command) { await message.reply( this.generateEmbed( - this.handler.findCommand(command.value) as BotCommand + this.handler.findCommand(command.value) as BushCommand ) ); } else { diff --git a/src/commands/info/ping.ts b/src/commands/info/ping.ts index e51867f..62b8e60 100644 --- a/src/commands/info/ping.ts +++ b/src/commands/info/ping.ts @@ -1,9 +1,9 @@ import { CommandInteraction } from 'discord.js'; import { Message } from 'discord.js'; import { MessageEmbed } from 'discord.js'; -import { BotCommand } from '../../lib/extensions/BotCommand'; +import { BushCommand } from '../../lib/extensions/BushCommand'; -export default class PingCommand extends BotCommand { +export default class PingCommand extends BushCommand { constructor() { super('ping', { aliases: ['ping'], diff --git a/src/commands/info/pronouns.ts b/src/commands/info/pronouns.ts index 97cca34..f30a981 100644 --- a/src/commands/info/pronouns.ts +++ b/src/commands/info/pronouns.ts @@ -1,4 +1,4 @@ -import { BotCommand } from '../../lib/extensions/BotCommand'; +import { BushCommand } from '../../lib/extensions/BushCommand'; import { User, Message, MessageEmbed } from 'discord.js'; import got, { HTTPError } from 'got'; import { CommandInteraction } from 'discord.js'; @@ -30,7 +30,7 @@ export const pronounMapping = { }; export type pronounsType = keyof typeof pronounMapping; -export default class PronounsCommand extends BotCommand { +export default class PronounsCommand extends BushCommand { constructor() { super('pronouns', { aliases: ['pronouns', 'pronoun'], diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index 556dd6b..1c3b074 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -1,6 +1,6 @@ import { User } from 'discord.js'; import { Guild } from '../../lib/models'; -import { BotCommand } from '../../lib/extensions/BotCommand'; +import { BushCommand } from '../../lib/extensions/BushCommand'; import { Ban, Modlog, ModlogType } from '../../lib/models'; import moment from 'moment'; import { Message } from 'discord.js'; @@ -18,7 +18,7 @@ const durationAliases: Record = { const durationRegex = /(?:(\d+)(d(?:ays?)?|h(?:ours?|rs?)?|m(?:inutes?|ins?)?|mo(?:nths?)?|w(?:eeks?|ks?)?)(?: |$))/g; -export default class PrefixCommand extends BotCommand { +export default class PrefixCommand extends BushCommand { constructor() { super('ban', { aliases: ['ban'], diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts index f31047e..c21352f 100644 --- a/src/commands/moderation/kick.ts +++ b/src/commands/moderation/kick.ts @@ -1,10 +1,10 @@ -import { BotCommand } from '../../lib/extensions/BotCommand'; +import { BushCommand } from '../../lib/extensions/BushCommand'; import { Guild, Modlog, ModlogType } from '../../lib/models'; import { GuildMember, Message } from 'discord.js'; import { ApplicationCommandOptionType } from 'discord-api-types'; import { CommandInteraction } from 'discord.js'; -export default class KickCommand extends BotCommand { +export default class KickCommand extends BushCommand { constructor() { super('kick', { aliases: ['kick'], diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts index 320c6b4..b7923ca 100644 --- a/src/commands/moderation/modlog.ts +++ b/src/commands/moderation/modlog.ts @@ -1,4 +1,4 @@ -import { BotCommand } from '../../lib/extensions/BotCommand'; +import { BushCommand } from '../../lib/extensions/BushCommand'; import { Message } from 'discord.js'; import { Modlog } from '../../lib/models'; import { MessageEmbed } from 'discord.js'; @@ -6,7 +6,7 @@ import moment from 'moment'; import { stripIndent } from 'common-tags'; import { Argument } from 'discord-akairo'; -export default class ModlogCommand extends BotCommand { +export default class ModlogCommand extends BushCommand { constructor() { super('modlog', { aliases: ['modlog', 'modlogs'], diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts index 2a67e5b..29339a3 100644 --- a/src/commands/moderation/role.ts +++ b/src/commands/moderation/role.ts @@ -1,10 +1,10 @@ /* eslint-disable @typescript-eslint/no-empty-function */ -import { BotCommand } from '../../lib/extensions/BotCommand'; +import { BushCommand } from '../../lib/extensions/BushCommand'; import AllowedMentions from '../../lib/utils/AllowedMentions'; import { Message, Role, GuildMember } from 'discord.js'; import { ApplicationCommandOptionType } from 'discord-api-types'; -export default class RoleCommand extends BotCommand { +export default class RoleCommand extends BushCommand { private roleWhitelist: Record = { 'Partner': ['*', 'Admin Perms', 'Sr. Moderator', 'Moderator'], 'Suggester': [ diff --git a/src/commands/moderation/warn.ts b/src/commands/moderation/warn.ts index 41e0032..e8b1401 100644 --- a/src/commands/moderation/warn.ts +++ b/src/commands/moderation/warn.ts @@ -1,8 +1,8 @@ import { GuildMember, Message } from 'discord.js'; -import { BotCommand } from '../../lib/extensions/BotCommand'; +import { BushCommand } from '../../lib/extensions/BushCommand'; import { Guild, Modlog, ModlogType } from '../../lib/models'; -export default class WarnCommand extends BotCommand { +export default class WarnCommand extends BushCommand { public constructor() { super('warn', { aliases: ['warn'], diff --git a/src/commands/moulberry-bush/capeperms.ts b/src/commands/moulberry-bush/capeperms.ts index 5b3dc10..9832083 100644 --- a/src/commands/moulberry-bush/capeperms.ts +++ b/src/commands/moulberry-bush/capeperms.ts @@ -3,7 +3,7 @@ import { MessageEmbed } from 'discord.js'; import { CommandInteraction } from 'discord.js'; import { Message } from 'discord.js'; import got from 'got'; -import { BotCommand } from '../../lib/extensions/BotCommand'; +import { BushCommand } from '../../lib/extensions/BushCommand'; import { SlashCommandOption } from '../../lib/extensions/Util'; interface Capeperms { @@ -15,7 +15,7 @@ interface User { perms: string[]; } -export default class CapePermsCommand extends BotCommand { +export default class CapePermsCommand extends BushCommand { private nameMap = { patreon1: 'Patreon Tier 1', patreon2: 'Patreon Tier 2', diff --git a/src/commands/moulberry-bush/giveawayping.ts b/src/commands/moulberry-bush/giveawayping.ts index d99f475..e6fdd9a 100644 --- a/src/commands/moulberry-bush/giveawayping.ts +++ b/src/commands/moulberry-bush/giveawayping.ts @@ -1,10 +1,10 @@ -import { BotCommand } from '../../lib/extensions/BotCommand'; +import { BushCommand } from '../../lib/extensions/BushCommand'; import AllowedMentions from '../../lib/utils/AllowedMentions'; import { Message, WebhookClient } from 'discord.js'; import { TextChannel } from 'discord.js'; import { NewsChannel } from 'discord.js'; -export default class GiveawayPingCommand extends BotCommand { +export default class GiveawayPingCommand extends BushCommand { constructor() { super('giveawayping', { aliases: ['giveawayping', 'giveawaypong'], diff --git a/src/commands/moulberry-bush/level.ts b/src/commands/moulberry-bush/level.ts index ab08361..decac8a 100644 --- a/src/commands/moulberry-bush/level.ts +++ b/src/commands/moulberry-bush/level.ts @@ -3,13 +3,14 @@ import { Message } from 'discord.js'; import { CommandInteractionOption } from 'discord.js'; import { CommandInteraction } from 'discord.js'; import { User } from 'discord.js'; -import { BotCommand } from '../../lib/extensions/BotCommand'; +import { BushCommand } from '../../lib/extensions/BushCommand'; import { Level } from '../../lib/models'; -export default class LevelCommand extends BotCommand { +export default class LevelCommand extends BushCommand { constructor() { super('level', { aliases: ['level', 'rank'], + category: "Moulberry's Bush", description: { content: 'Shows the level of a user', usage: 'level [user]', diff --git a/src/commands/moulberry-bush/rule.ts b/src/commands/moulberry-bush/rule.ts index bd8b08a..69dcb6e 100644 --- a/src/commands/moulberry-bush/rule.ts +++ b/src/commands/moulberry-bush/rule.ts @@ -1,11 +1,11 @@ import { Argument } from 'discord-akairo'; import { Message, MessageEmbed, User } from 'discord.js'; -import { BotCommand } from '../../lib/extensions/BotCommand'; +import { BushCommand } from '../../lib/extensions/BushCommand'; import { ApplicationCommandOptionType } from 'discord-api-types'; import { CommandInteraction } from 'discord.js'; import { SlashCommandOption } from '../../lib/extensions/Util'; -export default class RuleCommand extends BotCommand { +export default class RuleCommand extends BushCommand { private rules = [ { title: "Follow Discord's TOS", diff --git a/src/commands/owner/eval.ts b/src/commands/owner/eval.ts deleted file mode 100644 index a63b977..0000000 --- a/src/commands/owner/eval.ts +++ /dev/null @@ -1,138 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { BotCommand } from '../../lib/extensions/BotCommand'; -import { MessageEmbed, Message } from 'discord.js'; -import { inspect, promisify } from 'util'; -import { exec } from 'child_process'; - -const clean = (text) => { - if (typeof text === 'string') - return text - .replace(/`/g, '`' + String.fromCharCode(8203)) - .replace(/@/g, '@' + String.fromCharCode(8203)); - else return text; -}; - -export default class EvalCommand extends BotCommand { - public constructor() { - super('eval', { - aliases: ['eval', 'ev'], - category: 'dev', - description: { - content: 'Use the command to eval stuff in the bot.', - usage: 'eval [--silent] [--depth #]', - examples: ['eval message.guild.name', 'eval this.client.ownerID'] - }, - args: [ - { - id: 'depth', - match: 'option', - type: 'number', - flag: '--depth', - default: 0 - }, - { - id: 'silent', - match: 'flag', - flag: '--silent' - }, - { - id: 'code', - match: 'rest', - type: 'string', - prompt: { - start: 'What would you like to eval?', - retry: 'Invalid code to eval. What would you like to eval?' - } - } - ], - ownerOnly: true, - clientPermissions: ['EMBED_LINKS'] - }); - } - - public async exec( - message: Message, - { depth, code, silent }: { depth: number; code: string; silent: boolean } - ): Promise { - const embed: MessageEmbed = new MessageEmbed(); - - try { - let output; - const me = message.member, - member = message.member, - bot = this.client, - guild = message.guild, - channel = message.channel, - config = this.client.config, - sh = promisify(exec), - models = this.client.db.models, - got = require('got'); // eslint-disable-line @typescript-eslint/no-var-requires - output = eval(code); - output = await output; - if (typeof output !== 'string') output = inspect(output, { depth }); - output = output.replace( - new RegExp(this.client.token, 'g'), - '[token omitted]' - ); - output = clean(output); - embed - .setTitle('✅ Evaled code successfully') - .addField( - '📥 Input', - code.length > 1012 - ? 'Too large to display. Hastebin: ' + - (await this.client.util.haste(code)) - : '```js\n' + code + '```' - ) - .addField( - '📤 Output', - output.length > 1012 - ? 'Too large to display. Hastebin: ' + - (await this.client.util.haste(output)) - : '```js\n' + output + '```' - ) - .setColor('#66FF00') - .setFooter( - message.author.username, - message.author.displayAvatarURL({ dynamic: true }) - ) - .setTimestamp(); - } catch (e) { - embed - .setTitle('❌ Code was not able to be evaled') - .addField( - '📥 Input', - code.length > 1012 - ? 'Too large to display. Hastebin: ' + - (await this.client.util.haste(code)) - : '```js\n' + code + '```' - ) - .addField( - '📤 Output', - e.length > 1012 - ? 'Too large to display. Hastebin: ' + - (await this.client.util.haste(e)) - : '```js\n' + - e + - '```Full stack:' + - (await this.client.util.haste(e.stack)) - ) - .setColor('#FF0000') - .setFooter( - message.author.username, - message.author.displayAvatarURL({ dynamic: true }) - ) - .setTimestamp(); - } - if (!silent) { - await message.util.send(embed); - } else { - try { - await message.author.send(embed); - await message.react(''); - } catch (e) { - await message.react('❌'); - } - } - } -} diff --git a/src/commands/owner/reload.ts b/src/commands/owner/reload.ts deleted file mode 100644 index 0330b27..0000000 --- a/src/commands/owner/reload.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { BotCommand } from '../../lib/extensions/BotCommand'; -import { stripIndent } from 'common-tags'; -import { Message } from 'discord.js'; -import { CommandInteraction } from 'discord.js'; - -export default class ReloadCommand extends BotCommand { - constructor() { - super('reload', { - aliases: ['reload'], - description: { - content: 'Reloads the bot', - usage: 'reload', - examples: ['reload'] - }, - ownerOnly: true, - typing: true - }); - } - - private async getResponse(): Promise { - try { - await this.client.util.shell('yarn rimraf dist/'); - await this.client.util.shell('yarn tsc'); - this.client.commandHandler.reloadAll(); - this.client.listenerHandler.reloadAll(); - this.client.inhibitorHandler.reloadAll(); - return '🔁 Successfully reloaded!'; - } catch (e) { - return stripIndent` - An error occured while reloading: - ${await this.client.util.haste(e.stack)} - `; - } - } - - public async exec(message: Message): Promise { - await message.util.send(await this.getResponse()); - } - - public async execSlash(message: CommandInteraction): Promise { - await message.reply(await this.getResponse()); - } -} diff --git a/src/commands/owner/setlevel.ts b/src/commands/owner/setlevel.ts deleted file mode 100644 index 6987385..0000000 --- a/src/commands/owner/setlevel.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { ApplicationCommandOptionType } from 'discord-api-types'; -import { CommandInteraction } from 'discord.js'; -import { User } from 'discord.js'; -import { Message } from 'discord.js'; -import { BotCommand } from '../../lib/extensions/BotCommand'; -import { SlashCommandOption } from '../../lib/extensions/Util'; -import { Level } from '../../lib/models'; -import AllowedMentions from '../../lib/utils/AllowedMentions'; - -export default class SetLevelCommand extends BotCommand { - constructor() { - super('setlevel', { - aliases: ['setlevel'], - description: { - content: 'Sets the level of a user', - usage: 'setlevel ', - examples: ['setlevel @Moulberry 69'] - }, - args: [ - { - id: 'user', - type: 'user', - prompt: { - start: 'What user would you like to change the level of?', - retry: - 'Invalid user. What user would you like to change the level of?' - } - }, - { - id: 'level', - type: 'number', - prompt: { - start: 'What level would you like to set?', - retry: 'Invalid user. What level would you like to set?' - } - } - ], - ownerOnly: true, - slashCommandOptions: [ - { - type: ApplicationCommandOptionType.USER, - name: 'user', - description: 'The user to change the level of', - required: true - }, - { - type: ApplicationCommandOptionType.INTEGER, - name: 'level', - description: 'The level to set the user to', - required: true - } - ] - }); - } - - private async setLevel(user: User, level: number): Promise { - const [levelEntry] = await Level.findOrBuild({ - where: { - id: user.id - }, - defaults: { - id: user.id - } - }); - levelEntry.xp = Level.convertLevelToXp(level); - await levelEntry.save(); - return `Successfully set level of <@${user.id}> to \`${level}\` (\`${levelEntry.xp}\` XP)`; - } - - async exec( - message: Message, - { user, level }: { user: User; level: number } - ): Promise { - await message.util.send(await this.setLevel(user, level), { - allowedMentions: AllowedMentions.none() - }); - } - - async execSlash( - message: CommandInteraction, - { - user, - level - }: { user: SlashCommandOption; level: SlashCommandOption } - ): Promise { - await message.reply(await this.setLevel(user.user, level.value), { - allowedMentions: AllowedMentions.none() - }); - } -} diff --git a/src/commands/server-config/prefix.ts b/src/commands/server-config/prefix.ts new file mode 100644 index 0000000..ac85922 --- /dev/null +++ b/src/commands/server-config/prefix.ts @@ -0,0 +1,71 @@ +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { CommandInteraction, Message, Guild as DiscordGuild } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { SlashCommandOption } from '../../lib/extensions/Util'; +import { Guild } from '../../lib/models'; + +export default class PrefixCommand extends BushCommand { + constructor() { + super('prefix', { + aliases: ['prefix'], + category: "server config", + args: [ + { + id: 'prefix' + } + ], + userPermissions: ['MANAGE_GUILD'], + description: { + content: + 'Set the prefix of the current server (resets to default if prefix is not given)', + usage: 'prefix [prefix]', + examples: ['prefix', 'prefix +'] + }, + slashCommandOptions: [ + { + type: ApplicationCommandOptionType.STRING, + name: 'prefix', + description: 'The prefix to set for this server', + required: false + } + ] + }); + } + + async changePrefix(guild: DiscordGuild, prefix?: string): Promise { + if (prefix) { + const row = await Guild.findByPk(guild.id); + row.prefix = prefix; + await row.save(); + } else { + const row = await Guild.findByPk(guild.id); + row.prefix = this.client.config.prefix; + await row.save(); + } + } + + async exec(message: Message, { prefix }: { prefix?: string }): Promise { + await this.changePrefix(message.guild, prefix); + if (prefix) { + await message.util.send(`Sucessfully set prefix to \`${prefix}\``); + } else { + await message.util.send( + `Sucessfully reset prefix to \`${this.client.config.prefix}\`` + ); + } + } + + async execSlash( + message: CommandInteraction, + { prefix }: { prefix?: SlashCommandOption } + ): Promise { + await this.changePrefix(message.guild, prefix?.value); + if (prefix) { + await message.reply(`Sucessfully set prefix to \`${prefix.value}\``); + } else { + await message.reply( + `Sucessfully reset prefix to \`${this.client.config.prefix}\`` + ); + } + } +} -- cgit From cd0f853a2e4732cea5356f9ee3603bb804b0ab1f Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Wed, 26 May 2021 21:53:35 -0400 Subject: made some more changes --- src/commands/dev/eval.ts | 138 ------------- src/commands/dev/evalCommand.ts | 138 +++++++++++++ src/commands/dev/reload.ts | 44 ---- src/commands/dev/reloadCommand.ts | 44 ++++ src/commands/dev/setLevelCommand.ts | 91 +++++++++ src/commands/dev/setlevel.ts | 91 --------- src/commands/info/botInfoCommand.ts | 65 ++++++ src/commands/info/botinfo.ts | 65 ------ src/commands/info/help.ts | 107 ---------- src/commands/info/helpCommand.ts | 107 ++++++++++ src/commands/info/ping.ts | 68 ------- src/commands/info/pingCommand.ts | 68 +++++++ src/commands/info/pronouns.ts | 121 ----------- src/commands/info/pronounsCommand.ts | 121 +++++++++++ src/commands/moderation/ban.ts | 223 -------------------- src/commands/moderation/banCommand.ts | 224 +++++++++++++++++++++ src/commands/moderation/kick.ts | 120 ----------- src/commands/moderation/kickCommand.ts | 121 +++++++++++ src/commands/moderation/modlog.ts | 148 -------------- src/commands/moderation/modlogCommand.ts | 149 ++++++++++++++ src/commands/moderation/role.ts | 181 ----------------- src/commands/moderation/roleCommand.ts | 181 +++++++++++++++++ src/commands/moderation/warn.ts | 67 ------ src/commands/moderation/warnCommand.ts | 68 +++++++ .../moulberry-bush/capePermissionsCommand.ts | 126 ++++++++++++ src/commands/moulberry-bush/capeperms.ts | 126 ------------ src/commands/moulberry-bush/giveawayPingCommand.ts | 68 +++++++ src/commands/moulberry-bush/giveawayping.ts | 68 ------- src/commands/moulberry-bush/level.ts | 62 ------ src/commands/moulberry-bush/levelCommand.ts | 62 ++++++ src/commands/moulberry-bush/rule.ts | 188 ----------------- src/commands/moulberry-bush/ruleCommand.ts | 188 +++++++++++++++++ src/commands/server-config/prefix.ts | 71 ------- src/commands/server-config/prefixCommand.ts | 71 +++++++ 34 files changed, 1892 insertions(+), 1888 deletions(-) delete mode 100644 src/commands/dev/eval.ts create mode 100644 src/commands/dev/evalCommand.ts delete mode 100644 src/commands/dev/reload.ts create mode 100644 src/commands/dev/reloadCommand.ts create mode 100644 src/commands/dev/setLevelCommand.ts delete mode 100644 src/commands/dev/setlevel.ts create mode 100644 src/commands/info/botInfoCommand.ts delete mode 100644 src/commands/info/botinfo.ts delete mode 100644 src/commands/info/help.ts create mode 100644 src/commands/info/helpCommand.ts delete mode 100644 src/commands/info/ping.ts create mode 100644 src/commands/info/pingCommand.ts delete mode 100644 src/commands/info/pronouns.ts create mode 100644 src/commands/info/pronounsCommand.ts delete mode 100644 src/commands/moderation/ban.ts create mode 100644 src/commands/moderation/banCommand.ts delete mode 100644 src/commands/moderation/kick.ts create mode 100644 src/commands/moderation/kickCommand.ts delete mode 100644 src/commands/moderation/modlog.ts create mode 100644 src/commands/moderation/modlogCommand.ts delete mode 100644 src/commands/moderation/role.ts create mode 100644 src/commands/moderation/roleCommand.ts delete mode 100644 src/commands/moderation/warn.ts create mode 100644 src/commands/moderation/warnCommand.ts create mode 100644 src/commands/moulberry-bush/capePermissionsCommand.ts delete mode 100644 src/commands/moulberry-bush/capeperms.ts create mode 100644 src/commands/moulberry-bush/giveawayPingCommand.ts delete mode 100644 src/commands/moulberry-bush/giveawayping.ts delete mode 100644 src/commands/moulberry-bush/level.ts create mode 100644 src/commands/moulberry-bush/levelCommand.ts delete mode 100644 src/commands/moulberry-bush/rule.ts create mode 100644 src/commands/moulberry-bush/ruleCommand.ts delete mode 100644 src/commands/server-config/prefix.ts create mode 100644 src/commands/server-config/prefixCommand.ts (limited to 'src/commands') diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts deleted file mode 100644 index 83e63f6..0000000 --- a/src/commands/dev/eval.ts +++ /dev/null @@ -1,138 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { MessageEmbed, Message } from 'discord.js'; -import { inspect, promisify } from 'util'; -import { exec } from 'child_process'; - -const clean = (text) => { - if (typeof text === 'string') - return text - .replace(/`/g, '`' + String.fromCharCode(8203)) - .replace(/@/g, '@' + String.fromCharCode(8203)); - else return text; -}; - -export default class EvalCommand extends BushCommand { - public constructor() { - super('eval', { - aliases: ['eval', 'ev'], - category: 'dev', - description: { - content: 'Use the command to eval stuff in the bot.', - usage: 'eval [--silent] [--depth #]', - examples: ['eval message.guild.name', 'eval this.client.ownerID'] - }, - args: [ - { - id: 'depth', - match: 'option', - type: 'number', - flag: '--depth', - default: 0 - }, - { - id: 'silent', - match: 'flag', - flag: '--silent' - }, - { - id: 'code', - match: 'rest', - type: 'string', - prompt: { - start: 'What would you like to eval?', - retry: 'Invalid code to eval. What would you like to eval?' - } - } - ], - ownerOnly: true, - clientPermissions: ['EMBED_LINKS'] - }); - } - - public async exec( - message: Message, - { depth, code, silent }: { depth: number; code: string; silent: boolean } - ): Promise { - const embed: MessageEmbed = new MessageEmbed(); - - try { - let output; - const me = message.member, - member = message.member, - bot = this.client, - guild = message.guild, - channel = message.channel, - config = this.client.config, - sh = promisify(exec), - models = this.client.db.models, - got = require('got'); // eslint-disable-line @typescript-eslint/no-var-requires - output = eval(code); - output = await output; - if (typeof output !== 'string') output = inspect(output, { depth }); - output = output.replace( - new RegExp(this.client.token, 'g'), - '[token omitted]' - ); - output = clean(output); - embed - .setTitle('✅ Evaled code successfully') - .addField( - '📥 Input', - code.length > 1012 - ? 'Too large to display. Hastebin: ' + - (await this.client.util.haste(code)) - : '```js\n' + code + '```' - ) - .addField( - '📤 Output', - output.length > 1012 - ? 'Too large to display. Hastebin: ' + - (await this.client.util.haste(output)) - : '```js\n' + output + '```' - ) - .setColor('#66FF00') - .setFooter( - message.author.username, - message.author.displayAvatarURL({ dynamic: true }) - ) - .setTimestamp(); - } catch (e) { - embed - .setTitle('❌ Code was not able to be evaled') - .addField( - '📥 Input', - code.length > 1012 - ? 'Too large to display. Hastebin: ' + - (await this.client.util.haste(code)) - : '```js\n' + code + '```' - ) - .addField( - '📤 Output', - e.length > 1012 - ? 'Too large to display. Hastebin: ' + - (await this.client.util.haste(e)) - : '```js\n' + - e + - '```Full stack:' + - (await this.client.util.haste(e.stack)) - ) - .setColor('#FF0000') - .setFooter( - message.author.username, - message.author.displayAvatarURL({ dynamic: true }) - ) - .setTimestamp(); - } - if (!silent) { - await message.util.send(embed); - } else { - try { - await message.author.send(embed); - await message.react(''); - } catch (e) { - await message.react('❌'); - } - } - } -} diff --git a/src/commands/dev/evalCommand.ts b/src/commands/dev/evalCommand.ts new file mode 100644 index 0000000..83e63f6 --- /dev/null +++ b/src/commands/dev/evalCommand.ts @@ -0,0 +1,138 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { MessageEmbed, Message } from 'discord.js'; +import { inspect, promisify } from 'util'; +import { exec } from 'child_process'; + +const clean = (text) => { + if (typeof text === 'string') + return text + .replace(/`/g, '`' + String.fromCharCode(8203)) + .replace(/@/g, '@' + String.fromCharCode(8203)); + else return text; +}; + +export default class EvalCommand extends BushCommand { + public constructor() { + super('eval', { + aliases: ['eval', 'ev'], + category: 'dev', + description: { + content: 'Use the command to eval stuff in the bot.', + usage: 'eval [--silent] [--depth #]', + examples: ['eval message.guild.name', 'eval this.client.ownerID'] + }, + args: [ + { + id: 'depth', + match: 'option', + type: 'number', + flag: '--depth', + default: 0 + }, + { + id: 'silent', + match: 'flag', + flag: '--silent' + }, + { + id: 'code', + match: 'rest', + type: 'string', + prompt: { + start: 'What would you like to eval?', + retry: 'Invalid code to eval. What would you like to eval?' + } + } + ], + ownerOnly: true, + clientPermissions: ['EMBED_LINKS'] + }); + } + + public async exec( + message: Message, + { depth, code, silent }: { depth: number; code: string; silent: boolean } + ): Promise { + const embed: MessageEmbed = new MessageEmbed(); + + try { + let output; + const me = message.member, + member = message.member, + bot = this.client, + guild = message.guild, + channel = message.channel, + config = this.client.config, + sh = promisify(exec), + models = this.client.db.models, + got = require('got'); // eslint-disable-line @typescript-eslint/no-var-requires + output = eval(code); + output = await output; + if (typeof output !== 'string') output = inspect(output, { depth }); + output = output.replace( + new RegExp(this.client.token, 'g'), + '[token omitted]' + ); + output = clean(output); + embed + .setTitle('✅ Evaled code successfully') + .addField( + '📥 Input', + code.length > 1012 + ? 'Too large to display. Hastebin: ' + + (await this.client.util.haste(code)) + : '```js\n' + code + '```' + ) + .addField( + '📤 Output', + output.length > 1012 + ? 'Too large to display. Hastebin: ' + + (await this.client.util.haste(output)) + : '```js\n' + output + '```' + ) + .setColor('#66FF00') + .setFooter( + message.author.username, + message.author.displayAvatarURL({ dynamic: true }) + ) + .setTimestamp(); + } catch (e) { + embed + .setTitle('❌ Code was not able to be evaled') + .addField( + '📥 Input', + code.length > 1012 + ? 'Too large to display. Hastebin: ' + + (await this.client.util.haste(code)) + : '```js\n' + code + '```' + ) + .addField( + '📤 Output', + e.length > 1012 + ? 'Too large to display. Hastebin: ' + + (await this.client.util.haste(e)) + : '```js\n' + + e + + '```Full stack:' + + (await this.client.util.haste(e.stack)) + ) + .setColor('#FF0000') + .setFooter( + message.author.username, + message.author.displayAvatarURL({ dynamic: true }) + ) + .setTimestamp(); + } + if (!silent) { + await message.util.send(embed); + } else { + try { + await message.author.send(embed); + await message.react(''); + } catch (e) { + await message.react('❌'); + } + } + } +} diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts deleted file mode 100644 index 64e5745..0000000 --- a/src/commands/dev/reload.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { stripIndent } from 'common-tags'; -import { Message } from 'discord.js'; -import { CommandInteraction } from 'discord.js'; - -export default class ReloadCommand extends BushCommand { - constructor() { - super('reload', { - aliases: ['reload'], - category: 'dev', - description: { - content: 'Reloads the bot', - usage: 'reload', - examples: ['reload'] - }, - ownerOnly: true, - typing: true - }); - } - - private async getResponse(): Promise { - try { - await this.client.util.shell('yarn rimraf dist/'); - await this.client.util.shell('yarn tsc'); - this.client.commandHandler.reloadAll(); - this.client.listenerHandler.reloadAll(); - this.client.inhibitorHandler.reloadAll(); - return '🔁 Successfully reloaded!'; - } catch (e) { - return stripIndent` - An error occured while reloading: - ${await this.client.util.haste(e.stack)} - `; - } - } - - public async exec(message: Message): Promise { - await message.util.send(await this.getResponse()); - } - - public async execSlash(message: CommandInteraction): Promise { - await message.reply(await this.getResponse()); - } -} diff --git a/src/commands/dev/reloadCommand.ts b/src/commands/dev/reloadCommand.ts new file mode 100644 index 0000000..64e5745 --- /dev/null +++ b/src/commands/dev/reloadCommand.ts @@ -0,0 +1,44 @@ +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { stripIndent } from 'common-tags'; +import { Message } from 'discord.js'; +import { CommandInteraction } from 'discord.js'; + +export default class ReloadCommand extends BushCommand { + constructor() { + super('reload', { + aliases: ['reload'], + category: 'dev', + description: { + content: 'Reloads the bot', + usage: 'reload', + examples: ['reload'] + }, + ownerOnly: true, + typing: true + }); + } + + private async getResponse(): Promise { + try { + await this.client.util.shell('yarn rimraf dist/'); + await this.client.util.shell('yarn tsc'); + this.client.commandHandler.reloadAll(); + this.client.listenerHandler.reloadAll(); + this.client.inhibitorHandler.reloadAll(); + return '🔁 Successfully reloaded!'; + } catch (e) { + return stripIndent` + An error occured while reloading: + ${await this.client.util.haste(e.stack)} + `; + } + } + + public async exec(message: Message): Promise { + await message.util.send(await this.getResponse()); + } + + public async execSlash(message: CommandInteraction): Promise { + await message.reply(await this.getResponse()); + } +} diff --git a/src/commands/dev/setLevelCommand.ts b/src/commands/dev/setLevelCommand.ts new file mode 100644 index 0000000..d1701c5 --- /dev/null +++ b/src/commands/dev/setLevelCommand.ts @@ -0,0 +1,91 @@ +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { CommandInteraction } from 'discord.js'; +import { User } from 'discord.js'; +import { Message } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { SlashCommandOption } from '../../lib/extensions/Util'; +import { Level } from '../../lib/models'; +import AllowedMentions from '../../lib/utils/AllowedMentions'; + +export default class SetLevelCommand extends BushCommand { + constructor() { + super('setlevel', { + aliases: ['setlevel'], + category: 'dev', + description: { + content: 'Sets the level of a user', + usage: 'setlevel ', + examples: ['setlevel @Moulberry 69'] //nice + }, + args: [ + { + id: 'user', + type: 'user', + prompt: { + start: 'What user would you like to change the level of?', + retry: + 'Invalid user. What user would you like to change the level of?' + } + }, + { + id: 'level', + type: 'number', + prompt: { + start: 'What level would you like to set?', + retry: 'Invalid user. What level would you like to set?' + } + } + ], + ownerOnly: true, + slashCommandOptions: [ + { + type: ApplicationCommandOptionType.USER, + name: 'user', + description: 'The user to change the level of', + required: true + }, + { + type: ApplicationCommandOptionType.INTEGER, + name: 'level', + description: 'The level to set the user to', + required: true + } + ] + }); + } + + private async setLevel(user: User, level: number): Promise { + const [levelEntry] = await Level.findOrBuild({ + where: { + id: user.id + }, + defaults: { + id: user.id + } + }); + levelEntry.xp = Level.convertLevelToXp(level); + await levelEntry.save(); + return `Successfully set level of <@${user.id}> to \`${level}\` (\`${levelEntry.xp}\` XP)`; + } + + async exec( + message: Message, + { user, level }: { user: User; level: number } + ): Promise { + await message.util.send(await this.setLevel(user, level), { + allowedMentions: AllowedMentions.none() + }); + } + + async execSlash( + message: CommandInteraction, + { + user, + level + }: { user: SlashCommandOption; level: SlashCommandOption } + ): Promise { + await message.reply(await this.setLevel(user.user, level.value), { + allowedMentions: AllowedMentions.none() + }); + } +} diff --git a/src/commands/dev/setlevel.ts b/src/commands/dev/setlevel.ts deleted file mode 100644 index d1701c5..0000000 --- a/src/commands/dev/setlevel.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { ApplicationCommandOptionType } from 'discord-api-types'; -import { CommandInteraction } from 'discord.js'; -import { User } from 'discord.js'; -import { Message } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { SlashCommandOption } from '../../lib/extensions/Util'; -import { Level } from '../../lib/models'; -import AllowedMentions from '../../lib/utils/AllowedMentions'; - -export default class SetLevelCommand extends BushCommand { - constructor() { - super('setlevel', { - aliases: ['setlevel'], - category: 'dev', - description: { - content: 'Sets the level of a user', - usage: 'setlevel ', - examples: ['setlevel @Moulberry 69'] //nice - }, - args: [ - { - id: 'user', - type: 'user', - prompt: { - start: 'What user would you like to change the level of?', - retry: - 'Invalid user. What user would you like to change the level of?' - } - }, - { - id: 'level', - type: 'number', - prompt: { - start: 'What level would you like to set?', - retry: 'Invalid user. What level would you like to set?' - } - } - ], - ownerOnly: true, - slashCommandOptions: [ - { - type: ApplicationCommandOptionType.USER, - name: 'user', - description: 'The user to change the level of', - required: true - }, - { - type: ApplicationCommandOptionType.INTEGER, - name: 'level', - description: 'The level to set the user to', - required: true - } - ] - }); - } - - private async setLevel(user: User, level: number): Promise { - const [levelEntry] = await Level.findOrBuild({ - where: { - id: user.id - }, - defaults: { - id: user.id - } - }); - levelEntry.xp = Level.convertLevelToXp(level); - await levelEntry.save(); - return `Successfully set level of <@${user.id}> to \`${level}\` (\`${levelEntry.xp}\` XP)`; - } - - async exec( - message: Message, - { user, level }: { user: User; level: number } - ): Promise { - await message.util.send(await this.setLevel(user, level), { - allowedMentions: AllowedMentions.none() - }); - } - - async execSlash( - message: CommandInteraction, - { - user, - level - }: { user: SlashCommandOption; level: SlashCommandOption } - ): Promise { - await message.reply(await this.setLevel(user.user, level.value), { - allowedMentions: AllowedMentions.none() - }); - } -} diff --git a/src/commands/info/botInfoCommand.ts b/src/commands/info/botInfoCommand.ts new file mode 100644 index 0000000..e6a4fbb --- /dev/null +++ b/src/commands/info/botInfoCommand.ts @@ -0,0 +1,65 @@ +import { MessageEmbed, Message, CommandInteraction } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { duration } from 'moment'; + +export default class BotInfoCommand extends BushCommand { + constructor() { + super('botinfo', { + aliases: ['botinfo'], + description: { + content: 'Shows information about the bot', + usage: 'botinfo', + examples: ['botinfo'] + } + }); + } + + private async generateEmbed(): Promise { + const owners = (await this.client.util.mapIDs(this.client.ownerID)) + .map((u) => u.tag) + .join('\n'); + const currentCommit = ( + await this.client.util.shell('git rev-parse HEAD') + ).stdout.replace('\n', ''); + const repoUrl = ( + await this.client.util.shell('git remote get-url origin') + ).stdout.replace('\n', ''); + const embed = new MessageEmbed() + .setTitle('Bot Info:') + .addFields([ + { + name: 'Owners', + value: owners, + inline: true + }, + { + name: 'Uptime', + value: this.client.util.capitalize( + duration(this.client.uptime, 'milliseconds').humanize() + ) + }, + { + name: 'User count', + value: this.client.users.cache.size, + inline: true + }, + { + name: 'Current commit', + value: `[${currentCommit.substring( + 0, + 7 + )}](${repoUrl}/commit/${currentCommit})` + } + ]) + .setTimestamp(); + return embed; + } + + public async exec(message: Message): Promise { + await message.util.send(await this.generateEmbed()); + } + + public async execSlash(message: CommandInteraction): Promise { + await message.reply(await this.generateEmbed()); + } +} diff --git a/src/commands/info/botinfo.ts b/src/commands/info/botinfo.ts deleted file mode 100644 index e6a4fbb..0000000 --- a/src/commands/info/botinfo.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { MessageEmbed, Message, CommandInteraction } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { duration } from 'moment'; - -export default class BotInfoCommand extends BushCommand { - constructor() { - super('botinfo', { - aliases: ['botinfo'], - description: { - content: 'Shows information about the bot', - usage: 'botinfo', - examples: ['botinfo'] - } - }); - } - - private async generateEmbed(): Promise { - const owners = (await this.client.util.mapIDs(this.client.ownerID)) - .map((u) => u.tag) - .join('\n'); - const currentCommit = ( - await this.client.util.shell('git rev-parse HEAD') - ).stdout.replace('\n', ''); - const repoUrl = ( - await this.client.util.shell('git remote get-url origin') - ).stdout.replace('\n', ''); - const embed = new MessageEmbed() - .setTitle('Bot Info:') - .addFields([ - { - name: 'Owners', - value: owners, - inline: true - }, - { - name: 'Uptime', - value: this.client.util.capitalize( - duration(this.client.uptime, 'milliseconds').humanize() - ) - }, - { - name: 'User count', - value: this.client.users.cache.size, - inline: true - }, - { - name: 'Current commit', - value: `[${currentCommit.substring( - 0, - 7 - )}](${repoUrl}/commit/${currentCommit})` - } - ]) - .setTimestamp(); - return embed; - } - - public async exec(message: Message): Promise { - await message.util.send(await this.generateEmbed()); - } - - public async execSlash(message: CommandInteraction): Promise { - await message.reply(await this.generateEmbed()); - } -} diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts deleted file mode 100644 index 30c2a21..0000000 --- a/src/commands/info/help.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { Message, MessageEmbed } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { stripIndent } from 'common-tags'; -import { ApplicationCommandOptionType } from 'discord-api-types'; -import { CommandInteraction } from 'discord.js'; -import { SlashCommandOption } from '../../lib/extensions/Util'; - -export default class HelpCommand extends BushCommand { - constructor() { - super('help', { - aliases: ['help'], - description: { - content: 'Shows the commands of the bot', - usage: 'help', - examples: ['help'] - }, - clientPermissions: ['EMBED_LINKS'], - args: [ - { - id: 'command', - type: 'commandAlias' - } - ], - slashCommandOptions: [ - { - type: ApplicationCommandOptionType.STRING, - name: 'command', - description: 'The command to get help for', - required: false - } - ] - }); - } - - private generateEmbed(command?: BushCommand): MessageEmbed { - const prefix = this.handler.prefix; - if (!command) { - const embed = new MessageEmbed() - .addField( - 'Commands', - stripIndent`A list of available commands. - For additional info on a command, type \`${prefix}help \` - ` - ) - .setFooter( - `For more information about a command use "${this.client.config.prefix}help "` - ) - .setTimestamp(); - for (const category of this.handler.categories.values()) { - embed.addField( - `${category.id.replace(/(\b\w)/gi, (lc): string => - lc.toUpperCase() - )}`, - `${category - .filter((cmd): boolean => cmd.aliases.length > 0) - .map((cmd): string => `\`${cmd.aliases[0]}\``) - .join(' ')}` - ); - } - return embed; - } else { - const embed = new MessageEmbed() - .setColor([155, 200, 200]) - .setTitle( - `\`${command.description.usage ? command.description.usage : ''}\`` - ) - .addField( - 'Description', - `${command.description.content ? command.description.content : ''} ${ - command.ownerOnly ? '\n__Owner Only__' : '' - }` - ); - - if (command.aliases.length > 1) - embed.addField('Aliases', `\`${command.aliases.join('` `')}\``, true); - if (command.description.examples && command.description.examples.length) - embed.addField( - 'Examples', - `\`${command.description.examples.join('`\n`')}\``, - true - ); - return embed; - } - } - - public async exec( - message: Message, - { command }: { command: BushCommand } - ): Promise { - await message.util.send(this.generateEmbed(command)); - } - - public async execSlash( - message: CommandInteraction, - { command }: { command: SlashCommandOption } - ): Promise { - if (command) { - await message.reply( - this.generateEmbed( - this.handler.findCommand(command.value) as BushCommand - ) - ); - } else { - await message.reply(this.generateEmbed()); - } - } -} diff --git a/src/commands/info/helpCommand.ts b/src/commands/info/helpCommand.ts new file mode 100644 index 0000000..30c2a21 --- /dev/null +++ b/src/commands/info/helpCommand.ts @@ -0,0 +1,107 @@ +import { Message, MessageEmbed } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { stripIndent } from 'common-tags'; +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { CommandInteraction } from 'discord.js'; +import { SlashCommandOption } from '../../lib/extensions/Util'; + +export default class HelpCommand extends BushCommand { + constructor() { + super('help', { + aliases: ['help'], + description: { + content: 'Shows the commands of the bot', + usage: 'help', + examples: ['help'] + }, + clientPermissions: ['EMBED_LINKS'], + args: [ + { + id: 'command', + type: 'commandAlias' + } + ], + slashCommandOptions: [ + { + type: ApplicationCommandOptionType.STRING, + name: 'command', + description: 'The command to get help for', + required: false + } + ] + }); + } + + private generateEmbed(command?: BushCommand): MessageEmbed { + const prefix = this.handler.prefix; + if (!command) { + const embed = new MessageEmbed() + .addField( + 'Commands', + stripIndent`A list of available commands. + For additional info on a command, type \`${prefix}help \` + ` + ) + .setFooter( + `For more information about a command use "${this.client.config.prefix}help "