-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PATCH] Updating cmd and cmd perm cache
- Loading branch information
Showing
23 changed files
with
149 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/BaseClient/ClientHelperModules/cache/discord/commands.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as Discord from 'discord.js'; | ||
|
||
/** | ||
* Interface for managing commands for a Discord guild. | ||
*/ | ||
export interface Commands { | ||
/** | ||
* Retrieves the commands for a given guild and command ID. | ||
* @param guild The Discord guild to retrieves for. | ||
* @param commandId The ID of the command to retrieves for. | ||
* @returns A Promise that resolves to an array of ApplicationCommands, | ||
* or undefined if no commands are found. | ||
*/ | ||
get: (guild: Discord.Guild, commandId: string) => Promise<Discord.ApplicationCommand | undefined>; | ||
|
||
/** | ||
* Sets the command s for a given guild and command ID. | ||
* @param guildId The ID of the guild to sets for. | ||
* @param commandId The ID of the command to sets for. | ||
* @param command An array of ApplicationCommands to set. | ||
*/ | ||
set: (guildId: string, commandId: string, command: Discord.ApplicationCommand) => void; | ||
|
||
/** | ||
* Deletes the commands for a given guild and command ID. | ||
* @param guildId The ID of the guild to deletes for. | ||
* @param commandId The ID of the command to deletes for. | ||
*/ | ||
delete: (guildId: string, commandId: string) => void; | ||
|
||
/** | ||
* A cache of commands, keyed by guild ID and then by command ID. | ||
*/ | ||
cache: Map<string, Map<string, Discord.ApplicationCommand>>; | ||
} | ||
|
||
const self: Commands = { | ||
get: async (guild, commandId) => { | ||
const cached = self.cache.get(guild.id)?.get(commandId); | ||
if (cached) return cached; | ||
|
||
const requestHandler = (await import('../../requestHandler.js')).request; | ||
const fetched = await requestHandler.commands.getGuildCommands(guild); | ||
if ('message' in fetched) return undefined; | ||
|
||
return fetched?.find((f) => f.id === commandId); | ||
}, | ||
set: (guildId, commandId, command) => { | ||
if (!self.cache.get(guildId)) self.cache.set(guildId, new Map()); | ||
self.cache.get(guildId)?.set(commandId, command); | ||
}, | ||
delete: (guildId, commandId) => { | ||
if (self.cache.get(guildId)?.size === 1) self.cache.delete(guildId); | ||
else self.cache.get(guildId)?.delete(commandId); | ||
}, | ||
cache: new Map(), | ||
}; | ||
|
||
export default self; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.