refactor: only cache commands from own user (#6161)

This commit is contained in:
Tiemen
2021-07-23 21:19:17 +02:00
committed by GitHub
parent 4f8ca2936a
commit 4886ae23ab
6 changed files with 26 additions and 36 deletions

View File

@@ -3,18 +3,13 @@
const { Events } = require('../../../util/Constants');
module.exports = (client, { d: data }) => {
let command;
const commandManager = data.guild_id ? client.guilds.cache.get(data.guild_id)?.commands : client.application.commands;
if (!commandManager) return;
if (data.guild_id) {
const guild = client.guilds.cache.get(data.guild_id);
if (!guild) return;
command = guild.commands._add(data);
} else {
command = client.application.commands._add(data);
}
const command = commandManager._add(data, data.application_id === client.application.id);
/**
* Emitted when an application command is created.
* Emitted when a guild application command is created.
* @event Client#applicationCommandCreate
* @param {ApplicationCommand} command The command which was created
*/

View File

@@ -3,20 +3,15 @@
const { Events } = require('../../../util/Constants');
module.exports = (client, { d: data }) => {
let command;
const commandManager = data.guild_id ? client.guilds.cache.get(data.guild_id)?.commands : client.application.commands;
if (!commandManager) return;
if (data.guild_id) {
const guild = client.guilds.cache.get(data.guild_id);
if (!guild) return;
command = guild.commands._add(data);
guild.commands.cache.delete(data.id);
} else {
command = client.application.commands._add(data);
client.application.commands.cache.delete(data.id);
}
const isOwn = data.application_id === client.application.id;
const command = commandManager._add(data, isOwn);
if (isOwn) commandManager.cache.delete(data.id);
/**
* Emitted when an application command is deleted.
* Emitted when a guild application command is deleted.
* @event Client#applicationCommandDelete
* @param {ApplicationCommand} command The command which was deleted
*/

View File

@@ -3,21 +3,14 @@
const { Events } = require('../../../util/Constants');
module.exports = (client, { d: data }) => {
let oldCommand;
let newCommand;
const commandManager = data.guild_id ? client.guilds.cache.get(data.guild_id)?.commands : client.application.commands;
if (!commandManager) return;
if (data.guild_id) {
const guild = client.guilds.cache.get(data.guild_id);
if (!guild) return;
oldCommand = guild.commands.cache.get(data.id)?._clone() ?? null;
newCommand = guild.commands._add(data);
} else {
oldCommand = client.application.commands.cache.get(data.id)?._clone() ?? null;
newCommand = client.application.commands._add(data);
}
const oldCommand = commandManager.cache.get(data.id)?._clone() ?? null;
const newCommand = commandManager._add(data, data.application_id === client.application.id);
/**
* Emitted when an application command is updated.
* Emitted when a guild application command is updated.
* @event Client#applicationCommandUpdate
* @param {?ApplicationCommand} oldCommand The command before the update
* @param {ApplicationCommand} newCommand The command after the update