diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-06-21 15:33:36 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-06-21 15:33:36 -0400 |
commit | 6eb42974bdd4da4f9a6d77c8fde4c19f9f0a351b (patch) | |
tree | 6b0490f7f17d5d663f0f764589328e8acb79dd22 /src/commands | |
parent | 5c3da90f441c321f55ae735d6002f4da91f2481e (diff) | |
download | tanzanite-6eb42974bdd4da4f9a6d77c8fde4c19f9f0a351b.tar.gz tanzanite-6eb42974bdd4da4f9a6d77c8fde4c19f9f0a351b.tar.bz2 tanzanite-6eb42974bdd4da4f9a6d77c8fde4c19f9f0a351b.zip |
fix(db): made it work now
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/config/prefix.ts | 41 | ||||
-rw-r--r-- | src/commands/dev/eval.ts | 14 | ||||
-rw-r--r-- | src/commands/dev/reload.ts | 4 | ||||
-rw-r--r-- | src/commands/dev/setLevel.ts | 7 | ||||
-rw-r--r-- | src/commands/dev/superUser.ts | 73 | ||||
-rw-r--r-- | src/commands/info/botInfo.ts | 4 | ||||
-rw-r--r-- | src/commands/info/help.ts | 4 | ||||
-rw-r--r-- | src/commands/info/ping.ts | 4 | ||||
-rw-r--r-- | src/commands/info/pronouns.ts | 4 | ||||
-rw-r--r-- | src/commands/moderation/ban.ts | 4 | ||||
-rw-r--r-- | src/commands/moderation/kick.ts | 4 | ||||
-rw-r--r-- | src/commands/moulberry-bush/capePerms.ts | 4 | ||||
-rw-r--r-- | src/commands/moulberry-bush/level.ts | 4 | ||||
-rw-r--r-- | src/commands/moulberry-bush/rule.ts | 4 |
14 files changed, 116 insertions, 59 deletions
diff --git a/src/commands/config/prefix.ts b/src/commands/config/prefix.ts index 3bb717b..1326426 100644 --- a/src/commands/config/prefix.ts +++ b/src/commands/config/prefix.ts @@ -1,7 +1,6 @@ -import { Guild as DiscordGuild, Message } from 'discord.js'; -import { SlashCommandOption } from '../../lib/extensions/BushClientUtil'; +import { Message } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; +import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; import { Guild } from '../../lib/models'; export default class PrefixCommand extends BushCommand { @@ -11,7 +10,8 @@ export default class PrefixCommand extends BushCommand { category: 'config', args: [ { - id: 'prefix' + id: 'prefix', + type: 'string' } ], userPermissions: ['MANAGE_GUILD'], @@ -32,39 +32,18 @@ export default class PrefixCommand extends BushCommand { }); } - async changePrefix(guild: DiscordGuild, prefix?: string): Promise<void> { - let row = await Guild.findByPk(guild.id); + async exec(message: Message | BushSlashMessage, { prefix }: { prefix?: string }): Promise<void> { + let row = await Guild.findByPk(message.guild.id); if (!row) { row = Guild.build({ - id: guild.id + id: message.guild.id }); } - // this.client.console.debug(row); + await row.update({ prefix: prefix || this.client.config.prefix }); if (prefix) { - row.prefix = prefix; - await row.save(); + await message.util.send(`${this.client.util.emojis.success} changed prefix from \`${prefix}\``); } 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<void> { - 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: BushInteractionMessage, { prefix }: { prefix?: SlashCommandOption<string> }): Promise<void> { - 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}\``); + await message.util.send(`${this.client.util.emojis.success} reset prefix to \`${this.client.config.prefix}\``); } } } diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts index 8bf88ff..d2fe432 100644 --- a/src/commands/dev/eval.ts +++ b/src/commands/dev/eval.ts @@ -5,7 +5,7 @@ import { CommandInteraction, MessageEmbed, MessageEmbedOptions, Util } from 'dis import { transpile } from 'typescript'; import { inspect, promisify } from 'util'; import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; +import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; import { BushMessage } from '../../lib/extensions/BushMessage'; const clean = (text) => { @@ -123,7 +123,7 @@ export default class EvalCommand extends BushCommand { } public async exec( - message: BushMessage | BushInteractionMessage, + message: BushMessage | BushSlashMessage, args: { sel_depth: number; code: string; @@ -138,7 +138,7 @@ export default class EvalCommand extends BushCommand { 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.`); if (message.util.isSlash) { - await (message as BushInteractionMessage).interaction.defer({ ephemeral: args.silent }); + await (message as BushSlashMessage).interaction.defer({ ephemeral: args.silent }); } const code: { js?: string | null; ts?: string | null; lang?: 'js' | 'ts' } = {}; @@ -181,7 +181,13 @@ export default class EvalCommand extends BushCommand { channel = message.channel, config = this.client.config, members = message.guild.members, - roles = message.guild.roles; + roles = message.guild.roles, + { Ban } = await import('../../lib/models/Ban'), + { Global } = await import('../../lib/models/Global'), + { Guild } = await import('../../lib/models/Guild'), + { Level } = await import('../../lib/models/Level'), + { Modlog } = await import('../../lib/models/Modlog'), + { StickyRole } = await import('../../lib/models/StickyRole'); if (code[code.lang].replace(/ /g, '').includes('9+10' || '10+9')) { output = 21; } else { diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts index 9aee9a7..94e31b0 100644 --- a/src/commands/dev/reload.ts +++ b/src/commands/dev/reload.ts @@ -2,7 +2,7 @@ import { stripIndent } from 'common-tags'; import { Message } from 'discord.js'; import { SlashCommandOption } from '../../lib/extensions/BushClientUtil'; import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; +import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; export default class ReloadCommand extends BushCommand { constructor() { @@ -55,7 +55,7 @@ export default class ReloadCommand extends BushCommand { await message.util.send(await this.getResponse(fast)); } - public async execSlash(message: BushInteractionMessage, { fast }: { fast: SlashCommandOption<boolean> }): Promise<void> { + public async execSlash(message: BushSlashMessage, { fast }: { fast: SlashCommandOption<boolean> }): Promise<void> { await message.interaction.reply(await this.getResponse(fast?.value)); } } diff --git a/src/commands/dev/setLevel.ts b/src/commands/dev/setLevel.ts index 58c01dd..ca555db 100644 --- a/src/commands/dev/setLevel.ts +++ b/src/commands/dev/setLevel.ts @@ -1,7 +1,7 @@ import { Message, User } from 'discord.js'; import { SlashCommandOption } from '../../lib/extensions/BushClientUtil'; import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; +import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; import { Level } from '../../lib/models'; import AllowedMentions from '../../lib/utils/AllowedMentions'; @@ -61,8 +61,7 @@ export default class SetLevelCommand extends BushCommand { id: user.id } }); - levelEntry.xp = Level.convertLevelToXp(level); - await levelEntry.save(); + await levelEntry.update({ xp: Level.convertLevelToXp(level) }); return `Successfully set level of <@${user.id}> to \`${level}\` (\`${levelEntry.xp}\` XP)`; } @@ -74,7 +73,7 @@ export default class SetLevelCommand extends BushCommand { } async execSlash( - message: BushInteractionMessage, + message: BushSlashMessage, { user, level }: { user: SlashCommandOption<void>; level: SlashCommandOption<number> } ): Promise<void> { await message.interaction.reply({ diff --git a/src/commands/dev/superUser.ts b/src/commands/dev/superUser.ts new file mode 100644 index 0000000..c3ed0b0 --- /dev/null +++ b/src/commands/dev/superUser.ts @@ -0,0 +1,73 @@ +import { Constants } from 'discord-akairo'; +import { User } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushMessage } from '../../lib/extensions/BushMessage'; +import { Global } from '../../lib/models/Global'; + +export default class SuperUserCommand extends BushCommand { + public constructor() { + super('superuser', { + aliases: ['superuser', 'su'], + category: 'dev', + description: { + content: 'A command to manage superusers.', + usage: 'superuser <add/remove> <user>', + examples: ['superuser add IRONM00N'] + }, + clientPermissions: ['SEND_MESSAGES'], + ownerOnly: true + }); + } + *args(): unknown { + const action = yield { + id: 'action', + type: ['add', 'remove'], + match: Constants.ArgumentMatches.PHRASE, + prompt: { + start: 'Would you like to `add` or `remove` a user from the superuser list?', + retry: '{error} Choose if you would like to `add` or `remove` a user.', + required: true + } + }; + const user = yield { + id: 'user', + type: Constants.ArgumentTypes.USER, + match: Constants.ArgumentMatches.REST_CONTENT, + prompt: { + start: `Who would you like to ${action || 'add/remove'} from the superuser list?`, + retry: `Choose a valid user to ${action || 'add/remove'} from the superuser list.`, + required: true + } + }; + return { action, user }; + } + public async exec(message: BushMessage, args: { action: 'add' | 'remove'; user: User }): 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 superUsers = (await Global.findByPk(this.client.config.dev ? 'development' : 'production')).superUsers; + let success; + if (args.action === 'add') { + if (superUsers.includes(args.user.id)) { + return message.util.reply(`${this.client.util.emojis.warn} \`${args.user.tag}\` is already a superuser.`); + } + success = await this.client.util.insertOrRemoveFromGlobal('add', 'superUsers', args.user.id).catch(() => false); + } else { + if (!superUsers.includes(args.user.id)) { + return message.util.reply(`${this.client.util.emojis.warn} \`${args.user.tag}\` is not superuser.`); + } + success = await this.client.util.insertOrRemoveFromGlobal('remove', 'superUsers', args.user.id).catch(() => false); + } + if (success) { + const responses = [args.action == 'remove' ? `` : 'made', args.action == 'remove' ? 'is no longer' : '']; + return message.util.reply( + `${this.client.util.emojis.success} ${responses[0]} \`${args.user.tag}\` ${responses[1]} a superuser.` + ); + } else { + const response = [args.action == 'remove' ? `removing` : 'making', args.action == 'remove' ? `from` : 'to']; + return message.util.reply( + `${this.client.util.emojis.error} There was an error ${response[0]} \`${args.user.tag}\` ${response[1]} the superuser list.` + ); + } + } +} diff --git a/src/commands/info/botInfo.ts b/src/commands/info/botInfo.ts index 406ea2d..120527d 100644 --- a/src/commands/info/botInfo.ts +++ b/src/commands/info/botInfo.ts @@ -1,7 +1,7 @@ import { Message, MessageEmbed } from 'discord.js'; import { duration } from 'moment'; import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; +import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; export default class BotInfoCommand extends BushCommand { constructor() { @@ -51,7 +51,7 @@ export default class BotInfoCommand extends BushCommand { await message.util.send({ embeds: [await this.generateEmbed()] }); } - public async execSlash(message: BushInteractionMessage): Promise<void> { + public async execSlash(message: BushSlashMessage): Promise<void> { await message.interaction.reply({ embeds: [await this.generateEmbed()] }); } } diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index 2ffac1b..0efc6b3 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -1,6 +1,6 @@ import { MessageActionRow, MessageButton, MessageEmbed } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; +import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; import { BushMessage } from '../../lib/extensions/BushMessage'; export default class HelpCommand extends BushCommand { @@ -44,7 +44,7 @@ export default class HelpCommand extends BushCommand { } public async exec( - message: BushMessage | BushInteractionMessage, + message: BushMessage | BushSlashMessage, args: { command: BushCommand | string; showHidden?: boolean } ): Promise<unknown> { const prefix = this.client.config.dev ? 'dev ' : message.util.parsed.prefix; diff --git a/src/commands/info/ping.ts b/src/commands/info/ping.ts index fb93c50..e80cfb3 100644 --- a/src/commands/info/ping.ts +++ b/src/commands/info/ping.ts @@ -1,6 +1,6 @@ import { Message, MessageEmbed } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; +import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; export default class PingCommand extends BushCommand { constructor() { @@ -34,7 +34,7 @@ export default class PingCommand extends BushCommand { }); } - public async execSlash(message: BushInteractionMessage): Promise<void> { + public async execSlash(message: BushSlashMessage): Promise<void> { const timestamp1 = message.interaction.createdTimestamp; await message.interaction.reply('Pong!'); const timestamp2 = await message.interaction.fetchReply().then((m) => (m as Message).createdTimestamp); diff --git a/src/commands/info/pronouns.ts b/src/commands/info/pronouns.ts index 83aa5ca..79baeef 100644 --- a/src/commands/info/pronouns.ts +++ b/src/commands/info/pronouns.ts @@ -2,7 +2,7 @@ import { CommandInteraction, Message, MessageEmbed, User } from 'discord.js'; import got, { HTTPError } from 'got'; import { SlashCommandOption } from '../../lib/extensions/BushClientUtil'; import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; +import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; export const pronounMapping = { unspecified: 'Unspecified', @@ -107,7 +107,7 @@ export default class PronounsCommand extends BushCommand { const u = user || message.author; await this.sendResponse(message, u, u.id === message.author.id); } - async execSlash(message: BushInteractionMessage, { user }: { user?: SlashCommandOption<void> }): Promise<void> { + async execSlash(message: BushSlashMessage, { user }: { user?: SlashCommandOption<void> }): Promise<void> { const u = user?.user || message.author; await this.sendResponse(message.interaction, u, u.id === message.author.id); } diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index a493071..692691e 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -2,7 +2,7 @@ import { CommandInteraction, Message, User } from 'discord.js'; import moment from 'moment'; import { SlashCommandOption } from '../../lib/extensions/BushClientUtil'; import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; +import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; import { Ban, Guild, Modlog, ModlogType } from '../../lib/models'; const durationAliases: Record<string, string[]> = { @@ -168,7 +168,7 @@ export default class BanCommand extends BushCommand { } async execSlash( - message: BushInteractionMessage, + message: BushSlashMessage, { user, reason, diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts index b97fe91..d00ae55 100644 --- a/src/commands/moderation/kick.ts +++ b/src/commands/moderation/kick.ts @@ -1,6 +1,6 @@ import { CommandInteraction, GuildMember, Message } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; +import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; import { Guild, Modlog, ModlogType } from '../../lib/models'; export default class KickCommand extends BushCommand { @@ -100,7 +100,7 @@ export default class KickCommand extends BushCommand { } } - async execSlash(message: BushInteractionMessage, { user, reason }: { user: GuildMember; reason?: string }): Promise<void> { + async execSlash(message: BushSlashMessage, { user, reason }: { user: GuildMember; reason?: string }): Promise<void> { for await (const response of this.genResponses(message.interaction, user, reason)) { await message.interaction.reply(response); } diff --git a/src/commands/moulberry-bush/capePerms.ts b/src/commands/moulberry-bush/capePerms.ts index 1592175..3e4563a 100644 --- a/src/commands/moulberry-bush/capePerms.ts +++ b/src/commands/moulberry-bush/capePerms.ts @@ -2,7 +2,7 @@ import { Message, MessageEmbed } from 'discord.js'; import got from 'got'; import { SlashCommandOption } from '../../lib/extensions/BushClientUtil'; import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; +import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; interface Capeperms { success: boolean; @@ -109,7 +109,7 @@ export default class CapePermissionsCommand extends BushCommand { await message.reply(await this.getResponse(user)); } - public async execSlash(message: BushInteractionMessage, { user }: { user: SlashCommandOption<string> }): Promise<void> { + public async execSlash(message: BushSlashMessage, { user }: { user: SlashCommandOption<string> }): Promise<void> { await message.reply(await this.getResponse(user.value)); } } diff --git a/src/commands/moulberry-bush/level.ts b/src/commands/moulberry-bush/level.ts index 64d6dad..f822555 100644 --- a/src/commands/moulberry-bush/level.ts +++ b/src/commands/moulberry-bush/level.ts @@ -1,6 +1,6 @@ import { CommandInteractionOption, Message, User } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; +import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; import { Level } from '../../lib/models'; /* import canvas from 'canvas'; @@ -148,7 +148,7 @@ export default class LevelCommand extends BushCommand { // ); await message.reply(await this.getResponse(user || message.author)); } - async execSlash(message: BushInteractionMessage, { user }: { user?: CommandInteractionOption }): Promise<void> { + async execSlash(message: BushSlashMessage, { user }: { user?: CommandInteractionOption }): Promise<void> { // await message.reply( // new MessageAttachment( // await this.getImage(user?.user || message.user), diff --git a/src/commands/moulberry-bush/rule.ts b/src/commands/moulberry-bush/rule.ts index 16cda5e..e9b09eb 100644 --- a/src/commands/moulberry-bush/rule.ts +++ b/src/commands/moulberry-bush/rule.ts @@ -2,7 +2,7 @@ import { Argument } from 'discord-akairo'; import { CommandInteraction, Message, MessageEmbed, User } from 'discord.js'; import { SlashCommandOption } from '../../lib/extensions/BushClientUtil'; import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; +import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; export default class RuleCommand extends BushCommand { private rules = [ @@ -157,7 +157,7 @@ export default class RuleCommand extends BushCommand { } public async execSlash( - message: BushInteractionMessage, + message: BushSlashMessage, { rule, user }: { rule?: SlashCommandOption<number>; user?: SlashCommandOption<void> } ): Promise<void> { const response = this.getResponse(message.interaction, rule?.value, user?.user); |