diff options
author | TymanWasTaken <tyman@tyman.tech> | 2021-05-16 22:03:18 -0400 |
---|---|---|
committer | TymanWasTaken <tyman@tyman.tech> | 2021-05-16 22:03:18 -0400 |
commit | 759e93bec4e9e2eb86db7434007345c24b0a0252 (patch) | |
tree | 193c47e5dfc6bcce0f4923ea0d2f8f7ce2e5894a /src | |
parent | 284e1d1d693486f6c50cdb8b38f01cdf74eb63d2 (diff) | |
download | tanzanite-759e93bec4e9e2eb86db7434007345c24b0a0252.tar.gz tanzanite-759e93bec4e9e2eb86db7434007345c24b0a0252.tar.bz2 tanzanite-759e93bec4e9e2eb86db7434007345c24b0a0252.zip |
fix logging for slash command syncing v2, delete BotMessage and BotGuild because useless, add prefix slash command
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/admin/prefix.ts | 47 | ||||
-rw-r--r-- | src/commands/info/botinfo.ts | 5 | ||||
-rw-r--r-- | src/commands/info/help.ts | 3 | ||||
-rw-r--r-- | src/commands/info/ping.ts | 3 | ||||
-rw-r--r-- | src/commands/moderation/ban.ts | 4 | ||||
-rw-r--r-- | src/commands/moderation/kick.ts | 5 | ||||
-rw-r--r-- | src/commands/moderation/warn.ts | 5 | ||||
-rw-r--r-- | src/commands/moulberry-bush/level.ts | 3 | ||||
-rw-r--r-- | src/commands/owner/eval.ts | 3 | ||||
-rw-r--r-- | src/commands/owner/reload.ts | 4 | ||||
-rw-r--r-- | src/lib/extensions/BotClient.ts | 4 | ||||
-rw-r--r-- | src/lib/extensions/BotGuild.ts | 38 | ||||
-rw-r--r-- | src/lib/extensions/BotMessage.ts | 50 | ||||
-rw-r--r-- | src/listeners/client/syncslashcommands.ts | 8 | ||||
-rw-r--r-- | src/listeners/guild/syncunban.ts | 5 |
15 files changed, 60 insertions, 127 deletions
diff --git a/src/commands/admin/prefix.ts b/src/commands/admin/prefix.ts index 3948a7e..32af649 100644 --- a/src/commands/admin/prefix.ts +++ b/src/commands/admin/prefix.ts @@ -1,5 +1,7 @@ +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { CommandInteraction, Message } from 'discord.js'; import { BotCommand } from '../../lib/extensions/BotCommand'; -import { BotMessage } from '../../lib/extensions/BotMessage'; +import { Guild } from '../../lib/models'; export default class PrefixCommand extends BotCommand { constructor() { @@ -16,21 +18,50 @@ export default class PrefixCommand extends BotCommand { '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 exec( - message: BotMessage, - { prefix }: { prefix?: string } - ): Promise<void> { + async exec(message: Message, { prefix }: { prefix?: string }): Promise<void> { if (prefix) { - await message.settings.setPrefix(prefix); + const row = await Guild.findByPk(message.guild.id); + row.prefix = prefix; + await row.save(); await message.util.send(`Sucessfully set prefix to \`${prefix}\``); } else { - await message.settings.setPrefix(this.client.config.prefix); + const row = await Guild.findByPk(message.guild.id); + row.prefix = this.client.config.prefix; + await row.save(); await message.util.send( `Sucessfully reset prefix to \`${this.client.config.prefix}\`` ); } } + + async execSlash(message: CommandInteraction): Promise<void> { + const prefix = message.options.find((o) => o.name === 'prefix')?.value as + | string + | undefined; + + if (prefix) { + const row = await Guild.findByPk(message.guild.id); + row.prefix = prefix; + await row.save(); + await message.reply(`Sucessfully set prefix to \`${prefix}\``); + } else { + const row = await Guild.findByPk(message.guild.id); + row.prefix = this.client.config.prefix; + await row.save(); + await message.reply( + `Sucessfully reset prefix to \`${this.client.config.prefix}\`` + ); + } + } } diff --git a/src/commands/info/botinfo.ts b/src/commands/info/botinfo.ts index 27e14c4..306c142 100644 --- a/src/commands/info/botinfo.ts +++ b/src/commands/info/botinfo.ts @@ -1,7 +1,6 @@ -import { MessageEmbed } from 'discord.js'; +import { MessageEmbed, Message } from 'discord.js'; import { BotCommand } from '../../lib/extensions/BotCommand'; import { duration } from 'moment'; -import { BotMessage } from '../../lib/extensions/BotMessage'; export default class BotInfoCommand extends BotCommand { constructor() { @@ -15,7 +14,7 @@ export default class BotInfoCommand extends BotCommand { }); } - public async exec(message: BotMessage): Promise<void> { + public async exec(message: Message): Promise<void> { const owners = (await this.client.util.mapIDs(this.client.ownerID)) .map((u) => u.tag) .join('\n'); diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index 4aa45e0..73dcdbb 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -1,7 +1,6 @@ import { Message, MessageEmbed } from 'discord.js'; import { BotCommand } from '../../lib/extensions/BotCommand'; import { stripIndent } from 'common-tags'; -import { BotMessage } from '../../lib/extensions/BotMessage'; export default class HelpCommand extends BotCommand { constructor() { @@ -23,7 +22,7 @@ export default class HelpCommand extends BotCommand { } public async exec( - message: BotMessage, + message: Message, { command }: { command: BotCommand } ): Promise<Message> { const prefix = this.handler.prefix; diff --git a/src/commands/info/ping.ts b/src/commands/info/ping.ts index 7f8ab6b..e51867f 100644 --- a/src/commands/info/ping.ts +++ b/src/commands/info/ping.ts @@ -2,7 +2,6 @@ import { CommandInteraction } from 'discord.js'; import { Message } from 'discord.js'; import { MessageEmbed } from 'discord.js'; import { BotCommand } from '../../lib/extensions/BotCommand'; -import { BotMessage } from '../../lib/extensions/BotMessage'; export default class PingCommand extends BotCommand { constructor() { @@ -16,7 +15,7 @@ export default class PingCommand extends BotCommand { }); } - public async exec(message: BotMessage): Promise<void> { + public async exec(message: Message): Promise<void> { const sentMessage = await message.util.send('Pong!'); const timestamp: number = message.editedTimestamp ? message.editedTimestamp diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index 7ce36d3..3858290 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -1,9 +1,9 @@ import { User } from 'discord.js'; import { Guild } from '../../lib/models'; import { BotCommand } from '../../lib/extensions/BotCommand'; -import { BotMessage } from '../../lib/extensions/BotMessage'; import { Ban, Modlog, ModlogType } from '../../lib/models'; import moment from 'moment'; +import { Message } from 'discord.js'; const durationAliases: Record<string, string[]> = { weeks: ['w', 'weeks', 'week', 'wk', 'wks'], @@ -51,7 +51,7 @@ export default class PrefixCommand extends BotCommand { }); } async exec( - message: BotMessage, + message: Message, { user, reason, time }: { user: User; reason?: string; time?: string } ): Promise<void> { const duration = moment.duration(); diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts index 23fc092..7b04d5a 100644 --- a/src/commands/moderation/kick.ts +++ b/src/commands/moderation/kick.ts @@ -1,7 +1,6 @@ import { BotCommand } from '../../lib/extensions/BotCommand'; -import { BotMessage } from '../../lib/extensions/BotMessage'; import { Guild, Modlog, ModlogType } from '../../lib/models'; -import { GuildMember } from 'discord.js'; +import { GuildMember, Message } from 'discord.js'; export default class PrefixCommand extends BotCommand { constructor() { @@ -30,7 +29,7 @@ export default class PrefixCommand extends BotCommand { }); } async exec( - message: BotMessage, + message: Message, { user, reason }: { user: GuildMember; reason?: string } ): Promise<void> { let modlogEnry: Modlog; diff --git a/src/commands/moderation/warn.ts b/src/commands/moderation/warn.ts index 98ba4bd..41e0032 100644 --- a/src/commands/moderation/warn.ts +++ b/src/commands/moderation/warn.ts @@ -1,6 +1,5 @@ -import { GuildMember } from 'discord.js'; +import { GuildMember, Message } from 'discord.js'; import { BotCommand } from '../../lib/extensions/BotCommand'; -import { BotMessage } from '../../lib/extensions/BotMessage'; import { Guild, Modlog, ModlogType } from '../../lib/models'; export default class WarnCommand extends BotCommand { @@ -26,7 +25,7 @@ export default class WarnCommand extends BotCommand { }); } public async exec( - message: BotMessage, + message: Message, { member, reason }: { member: GuildMember; reason: string } ): Promise<void> { // Create guild entry so postgres doesn't get mad when I try and add a modlog entry diff --git a/src/commands/moulberry-bush/level.ts b/src/commands/moulberry-bush/level.ts index a70ebf1..0eb0044 100644 --- a/src/commands/moulberry-bush/level.ts +++ b/src/commands/moulberry-bush/level.ts @@ -1,3 +1,4 @@ +import { ApplicationCommandOptionType } from 'discord-api-types'; import { Message } from 'discord.js'; import { CommandInteraction } from 'discord.js'; import { User } from 'discord.js'; @@ -27,7 +28,7 @@ export default class LevelCommand extends BotCommand { ], slashCommandOptions: [ { - type: 6, + type: ApplicationCommandOptionType.USER, name: 'user', description: 'The user to get the level of', required: false diff --git a/src/commands/owner/eval.ts b/src/commands/owner/eval.ts index f1ada89..44326b2 100644 --- a/src/commands/owner/eval.ts +++ b/src/commands/owner/eval.ts @@ -3,7 +3,6 @@ import { BotCommand } from '../../lib/extensions/BotCommand'; import { MessageEmbed, Message } from 'discord.js'; import { inspect, promisify } from 'util'; import { exec } from 'child_process'; -import { BotMessage } from '../../lib/extensions/BotMessage'; const clean = (text) => { if (typeof text === 'string') @@ -52,7 +51,7 @@ export default class EvalCommand extends BotCommand { } public async exec( - message: BotMessage, + message: Message, { depth, code, silent }: { depth: number; code: string; silent: boolean } ): Promise<void> { const embed: MessageEmbed = new MessageEmbed(); diff --git a/src/commands/owner/reload.ts b/src/commands/owner/reload.ts index 2311424..6fdd74c 100644 --- a/src/commands/owner/reload.ts +++ b/src/commands/owner/reload.ts @@ -1,6 +1,6 @@ import { BotCommand } from '../../lib/extensions/BotCommand'; import { stripIndent } from 'common-tags'; -import { BotMessage } from '../../lib/extensions/BotMessage'; +import { Message } from 'discord.js'; export default class ReloadCommand extends BotCommand { constructor() { @@ -16,7 +16,7 @@ export default class ReloadCommand extends BotCommand { }); } - public async exec(message: BotMessage): Promise<void> { + public async exec(message: Message): Promise<void> { try { await this.client.util.shell('yarn rimraf dist/'); await this.client.util.shell('yarn tsc'); diff --git a/src/lib/extensions/BotClient.ts b/src/lib/extensions/BotClient.ts index 76b1a1b..bd14fd2 100644 --- a/src/lib/extensions/BotClient.ts +++ b/src/lib/extensions/BotClient.ts @@ -8,8 +8,6 @@ import { Guild } from 'discord.js'; import * as path from 'path'; import { Sequelize } from 'sequelize'; import * as Models from '../models'; -import { BotGuild } from './BotGuild'; -import { BotMessage } from './BotMessage'; import { Util } from './Util'; import * as Tasks from '../../tasks'; import { exit } from 'process'; @@ -96,8 +94,6 @@ export class BotClient extends AkairoClient { logging: false } ); - BotGuild.install(); - BotMessage.install(); this.logger = new Logger(this); } diff --git a/src/lib/extensions/BotGuild.ts b/src/lib/extensions/BotGuild.ts deleted file mode 100644 index bc88ad0..0000000 --- a/src/lib/extensions/BotGuild.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Guild, Structures } from 'discord.js'; -import { BotClient } from './BotClient'; -import { Guild as GuildModel } from '../models'; - -export class GuildSettings { - private guild: BotGuild; - constructor(guild: BotGuild) { - this.guild = guild; - } - public async getPrefix(): Promise<string> { - return await GuildModel.findByPk(this.guild.id).then( - (gm) => gm?.prefix || this.guild.client.config.prefix - ); - } - public async setPrefix(value: string): Promise<void> { - let entry = await GuildModel.findByPk(this.guild.id); - if (!entry) { - entry = GuildModel.build({ - id: this.guild.id, - prefix: value - }); - } else { - entry.prefix = value; - } - await entry.save(); - } -} - -export class BotGuild extends Guild { - constructor(client: BotClient, data: Record<string, unknown>) { - super(client, data); - } - static install(): void { - Structures.extend('Guild', () => BotGuild); - } - public settings = new GuildSettings(this); - public client: BotClient; -} diff --git a/src/lib/extensions/BotMessage.ts b/src/lib/extensions/BotMessage.ts deleted file mode 100644 index 70d4478..0000000 --- a/src/lib/extensions/BotMessage.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { - TextChannel, - NewsChannel, - DMChannel, - Message, - Structures -} from 'discord.js'; -import { BotClient } from './BotClient'; -import { Guild as GuildModel } from '../models'; -import { BotGuild } from './BotGuild'; - -export class GuildSettings { - private message: BotMessage; - constructor(message: BotMessage) { - this.message = message; - } - public async getPrefix(): Promise<string> { - return await GuildModel.findByPk(this.message.guild.id).then( - (gm) => gm?.prefix || this.message.client.config.prefix - ); - } - public async setPrefix(value: string): Promise<void> { - let entry = await GuildModel.findByPk(this.message.guild.id); - if (!entry) { - entry = GuildModel.build({ - id: this.message.guild.id, - prefix: value - }); - } else { - entry.prefix = value; - } - await entry.save(); - } -} - -export class BotMessage extends Message { - constructor( - client: BotClient, - data: Record<string, unknown>, - channel: TextChannel | DMChannel | NewsChannel - ) { - super(client, data, channel); - } - public guild: BotGuild; - public client: BotClient; - static install(): void { - Structures.extend('Message', () => BotMessage); - } - public settings = new GuildSettings(this); -} diff --git a/src/listeners/client/syncslashcommands.ts b/src/listeners/client/syncslashcommands.ts index 2388104..eb65b97 100644 --- a/src/listeners/client/syncslashcommands.ts +++ b/src/listeners/client/syncslashcommands.ts @@ -19,7 +19,7 @@ export default class CreateSlashCommands extends BotListener { ) { await this.client.application.commands.delete(registeredCommand.id); this.client.logger.verbose( - `{red Deleted slash command ${registeredCommand.name}}` + chalk`{red Deleted slash command ${registeredCommand.name}}` ); } } @@ -38,13 +38,13 @@ export default class CreateSlashCommands extends BotListener { if (slashdata.description !== found.description) { await this.client.application.commands.edit(found.id, slashdata); this.client.logger.verbose( - `{orange Edited slash command ${botCommand.id}}` + chalk`{orange Edited slash command ${botCommand.id}}` ); } } else { await this.client.application.commands.create(slashdata); this.client.logger.verbose( - `{green Created slash command ${botCommand.id}}` + chalk`{green Created slash command ${botCommand.id}}` ); } } @@ -54,7 +54,7 @@ export default class CreateSlashCommands extends BotListener { } catch (e) { console.log(chalk.red(e)); return this.client.logger.error( - '{red Slash commands not registered, see above error.}' + chalk`{red Slash commands not registered, see above error.}` ); } } diff --git a/src/listeners/guild/syncunban.ts b/src/listeners/guild/syncunban.ts index 63267bd..14f8820 100644 --- a/src/listeners/guild/syncunban.ts +++ b/src/listeners/guild/syncunban.ts @@ -1,5 +1,4 @@ -import { User } from 'discord.js'; -import { BotGuild } from '../../lib/extensions/BotGuild'; +import { User, Guild } from 'discord.js'; import { BotListener } from '../../lib/extensions/BotListener'; import { Ban } from '../../lib/models'; @@ -11,7 +10,7 @@ export default class CommandBlockedListener extends BotListener { }); } - public async exec(guild: BotGuild, user: User): Promise<void> { + public async exec(guild: Guild, user: User): Promise<void> { const bans = await Ban.findAll({ where: { user: user.id, |