Bugfix to lockdown replying multiple times without edit

This commit is contained in:
Erik 2023-12-12 03:24:01 +02:00
parent c875ac2e2f
commit 720738d7ab
7 changed files with 19 additions and 26 deletions

View File

@ -1,2 +0,0 @@
[*]
end_of_line = lf

View File

@ -248,7 +248,6 @@
"warn", "warn",
"before" "before"
], ],
"padding-line-between-statements": "warn",
"padded-blocks": [ "padded-blocks": [
"warn", "warn",
{ {

View File

@ -6,7 +6,7 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"start": "yarn build && node --enable-source-maps build/index.js", "start": "yarn build && node --enable-source-maps build/index.js",
"dev": "nodemon --signal SIGINT --delay 5 -e js --trace-warnings --unhandled-rejections=strict build/index.js", "dev": "nodemon --delay 5 -e js --trace-warnings --unhandled-rejections=strict build/index.js",
"debug": "node --trace-warnings --inspect index.js", "debug": "node --trace-warnings --inspect index.js",
"update": "git pull && cd api && yarn update", "update": "git pull && cd api && yarn update",
"test": "jest --detectOpenHandles", "test": "jest --detectOpenHandles",
@ -18,7 +18,7 @@
"type": "git", "type": "git",
"url": "git+https://github.com/Navy-gif/New-GBot.git" "url": "git+https://github.com/Navy-gif/New-GBot.git"
}, },
"author": "Navy.gif & Nolan", "author": "Navy.gif",
"license": "ISC", "license": "ISC",
"bugs": { "bugs": {
"url": "https://github.com/Navy-gif/New-GBot/issues" "url": "https://github.com/Navy-gif/New-GBot/issues"

View File

@ -7,7 +7,6 @@ import InvokerWrapper from '../../wrappers/InvokerWrapper.js';
class LockdownCommand extends ModerationCommand class LockdownCommand extends ModerationCommand
{ {
constructor (client: DiscordClient) constructor (client: DiscordClient)
{ {
super(client, { super(client, {
@ -30,23 +29,21 @@ class LockdownCommand extends ModerationCommand
clientPermissions: [ 'ManageChannels', 'ManageRoles' ], clientPermissions: [ 'ManageChannels', 'ManageRoles' ],
skipOptions: [ 'users', 'points', 'expiration', 'force', 'silent' ] skipOptions: [ 'users', 'points', 'expiration', 'force', 'silent' ]
}); });
} }
async execute (invoker: InvokerWrapper, { channels, ...args }: CommandParams) async execute (invoker: InvokerWrapper, { channels, ...args }: CommandParams)
{ {
if (!channels) if (!channels)
throw new CommandError(invoker, { index: 'MODERATION_MISSING_CHANNELS' }); throw new CommandError(invoker, { index: 'MODERATION_MISSING_CHANNELS' });
await invoker.reply({ content: 'Working...', emoji: 'loading' }); await invoker.reply({ content: 'Working...', emoji: 'loading' });
return this.client.moderation.handleInfraction(Lockdown, invoker, { const content = await this.client.moderation.handleInfraction(Lockdown, invoker, {
targets: channels?.asChannels as TextChannel[], targets: channels?.asChannels as TextChannel[],
args args
}); });
if (typeof content === 'string')
await invoker.reply({ content, edit: true });
} }
} }
export default LockdownCommand; export default LockdownCommand;

View File

@ -31,16 +31,16 @@ class UnlockdownCommand extends ModerationCommand
async execute (invoker: InvokerWrapper, { channels, ...args }: CommandParams) async execute (invoker: InvokerWrapper, { channels, ...args }: CommandParams)
{ {
if (!channels) if (!channels)
throw new CommandError(invoker, { index: 'MODERATION_MISSING_CHANNELS' }); throw new CommandError(invoker, { index: 'MODERATION_MISSING_CHANNELS' });
await invoker.reply({ content: 'Working...', emoji: 'loading' }); await invoker.reply({ content: 'Working...', emoji: 'loading' });
return this.client.moderation.handleInfraction(Unlockdown, invoker, { const content = await this.client.moderation.handleInfraction(Unlockdown, invoker, {
targets: channels?.asChannels as TextChannel[], targets: channels?.asChannels as TextChannel[],
args args
}); });
if (typeof content === 'string')
await invoker.reply({ content, edit: true });
} }
} }

View File

@ -54,7 +54,7 @@ class CommandHandler extends Observer
} }
// //
async messageCreate (message: ExtendedMessage) private async messageCreate (message: ExtendedMessage)
{ {
if (!this.client.ready if (!this.client.ready
|| message.webhookId || message.webhookId
@ -103,7 +103,7 @@ class CommandHandler extends Observer
await this._executeCommand(invoker, result.options ?? {}); await this._executeCommand(invoker, result.options ?? {});
} }
async interactionCreate (interaction: InteractionWrapper) private async interactionCreate (interaction: InteractionWrapper)
{ {
if (!interaction.isCommand() if (!interaction.isCommand()
&& !interaction.isContextMenu()) && !interaction.isContextMenu())
@ -144,7 +144,7 @@ class CommandHandler extends Observer
} }
} }
async _parseResult (invoker: InvokerWrapper<true, true>, response: ParseResult) private async _parseResult (invoker: InvokerWrapper<true, true>, response: ParseResult)
{ {
// Ensure option dependencies // Ensure option dependencies
outer: outer:
@ -215,7 +215,7 @@ class CommandHandler extends Observer
} }
} }
async _handleInhibitors (invoker: InvokerWrapper<true, true>) private async _handleInhibitors (invoker: InvokerWrapper<true, true>)
{ {
const inhibitors = this.client.registry.components.filter<Inhibitor>((comp): comp is Inhibitor => comp.type === 'inhibitor' && !comp.disabled); const inhibitors = this.client.registry.components.filter<Inhibitor>((comp): comp is Inhibitor => comp.type === 'inhibitor' && !comp.disabled);
if (!inhibitors.size) if (!inhibitors.size)
@ -236,7 +236,7 @@ class CommandHandler extends Observer
return errors.sort((a, b) => b.inhibitor.priority - a.inhibitor.priority); return errors.sort((a, b) => b.inhibitor.priority - a.inhibitor.priority);
} }
async _executeCommand (invoker: InvokerWrapper<true, true>, options: { [key: string]: CommandOption }) private async _executeCommand (invoker: InvokerWrapper<true, true>, options: { [key: string]: CommandOption })
{ {
let response = null; let response = null;
if (this.client.developmentMode && !this.client.developers.includes(invoker.user.id)) if (this.client.developmentMode && !this.client.developers.includes(invoker.user.id))
@ -295,7 +295,7 @@ class CommandHandler extends Observer
return invoker.reply({ index: 'O_COMMANDHANDLER_COMMAND_NORESPONSE', ephemeral: !invoker.replied }); return invoker.reply({ index: 'O_COMMANDHANDLER_COMMAND_NORESPONSE', ephemeral: !invoker.replied });
} }
async _parseInteraction (invoker: InvokerWrapper<true, true>, command: Command): Promise<ParseResult> private async _parseInteraction (invoker: InvokerWrapper<true, true>, command: Command): Promise<ParseResult>
{ {
const { subcommand, guild } = invoker; const { subcommand, guild } = invoker;
const interaction = invoker.target as InteractionWrapper; const interaction = invoker.target as InteractionWrapper;
@ -354,7 +354,7 @@ class CommandHandler extends Observer
} }
// eslint-disable-next-line max-lines-per-function // eslint-disable-next-line max-lines-per-function
async _parseMessage (invoker: InvokerWrapper<true, true>, params: (string | null)[]): Promise<ParseResult> private async _parseMessage (invoker: InvokerWrapper<true, true>, params: (string | null)[]): Promise<ParseResult>
{ {
const { command, guild } = invoker; const { command, guild } = invoker;
const message = invoker.target as MessageWrapper; const message = invoker.target as MessageWrapper;
@ -599,7 +599,7 @@ class CommandHandler extends Observer
return { options: args, verbose: true }; return { options: args, verbose: true };
} }
async _getCommand (message: MessageWrapper) private async _getCommand (message: MessageWrapper)
{ {
if (!this.#mentionPattern) if (!this.#mentionPattern)
this.#mentionPattern = new RegExp(`^(<@!?${this.client.user!.id}>)`, 'iu'); this.#mentionPattern = new RegExp(`^(<@!?${this.client.user!.id}>)`, 'iu');
@ -634,13 +634,13 @@ class CommandHandler extends Observer
} }
_matchCommand (commandName: string) private _matchCommand (commandName: string)
{ {
const [ command ] = this.client.resolver.components<Command>(commandName, 'command', true); const [ command ] = this.client.resolver.components<Command>(commandName, 'command', true);
return command || null; return command || null;
} }
_generateError (invoker: InvokerWrapper<true, true>, info: ErrorParams) private _generateError (invoker: InvokerWrapper<true, true>, info: ErrorParams)
{ {
const messages: {[key: string]: () => object} = { const messages: {[key: string]: () => object} = {
command: () => command: () =>

View File

@ -222,8 +222,7 @@ class InvokerWrapper<InGuild extends boolean = boolean, HasCommand extends boole
}); });
} }
async reply (content: string | ReplyOptions = {}, opts: ReplyOptions = {}) async reply (content: string | ReplyOptions = {}, opts: ReplyOptions = {}) : Promise<Message>
: Promise<Message>
{ {
let options = opts; let options = opts;
if (typeof content === 'object') if (typeof content === 'object')