From 679a8794177e8e83175b12c3644f3305e8921ef6 Mon Sep 17 00:00:00 2001 From: ITOH Date: Thu, 28 Oct 2021 20:37:13 +0200 Subject: [PATCH] still broken --- src/bot.ts | 1349 ++++++++++++++++++++++---------------------------- src/cache.ts | 218 ++++++-- 2 files changed, 773 insertions(+), 794 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 10ff0a7a1..cdf729ed3 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -31,7 +31,7 @@ import { simplifyUrl, } from "./rest/mod.ts"; import type { RestPayload, RestRateLimitedPath, RestRequest } from "./rest/rest.ts"; -import { DiscordGatewayIntents } from "./types/gateway/gateway_intents.ts"; +import { DiscordGatewayIntents, Intents } from "./types/gateway/gateway_intents.ts"; import { GetGatewayBot } from "./types/gateway/get_gateway_bot.ts"; import { bigintToSnowflake, snowflakeToBigint } from "./util/bigint.ts"; import { Collection } from "./util/collection.ts"; @@ -90,221 +90,14 @@ import { } from "./util/utils.ts"; import { iconBigintToHash, iconHashToBigInt } from "./util/hash.ts"; import { calculateShardId } from "./util/calculate_shard_id.ts"; -import { - handleReady, - handleChannelCreate, - handleChannelDelete, - handleChannelPinsUpdate, - handleChannelUpdate, - handleThreadCreate, - handleThreadUpdate, - handleThreadDelete, - handleThreadListSync, - handleThreadMemberUpdate, - handleThreadMembersUpdate, - handleStageInstanceCreate, - handleStageInstanceUpdate, - handleStageInstanceDelete, - handleGuildBanAdd, - handleGuildBanRemove, - handleGuildCreate, - handleGuildDelete, - handleGuildEmojisUpdate, - handleGuildIntegrationsUpdate, - handleGuildMemberAdd, - handleGuildMemberRemove, - handleGuildMemberUpdate, - handleGuildMembersChunk, - handleGuildRoleCreate, - handleGuildRoleDelete, - handleGuildRoleUpdate, - handleGuildUpdate, - handleInteractionCreate, - handleInviteCreate, - handleMessageCreate, - handleMessageDeleteBulk, - handleMessageDelete, - handleMessageReactionAdd, - handleMessageReactionRemoveAll, - handleMessageReactionRemoveEmoji, - handleMessageReactionRemove, - handleMessageUpdate, - handlePresenceUpdate, - handleTypingStart, - handleUserUpdate, - handleVoiceServerUpdate, - handleVoiceStateUpdate, - handleWebhooksUpdate, - handleIntegrationCreate, - handleIntegrationUpdate, - handleIntegrationDelete, - handleGuildLoaded, -} from "./handlers/mod.ts"; +import * as handlers from "./handlers/mod.ts"; import { DiscordenoInteraction, transformInteraction } from "./transformers/interaction.ts"; import { DiscordenoIntegration, transformIntegration } from "./transformers/integration.ts"; import { Emoji } from "./types/emojis/emoji.ts"; import { transformApplication } from "./transformers/application.ts"; import { transformTeam } from "./transformers/team.ts"; import { DiscordenoInvite, transformInvite } from "./transformers/invite.ts"; -import { - addDiscoverySubcategory, - addReaction, - addReactions, - addRole, - addToThread, - archiveThread, - avatarURL, - ban, - banMember, - batchEditSlashCommandPermissions, - categoryChildren, - channelOverwriteHasPermission, - connectToVoiceChannel, - createChannel, - createEmoji, - createGuild, - createGuildFromTemplate, - createGuildTemplate, - createInvite, - createRole, - createSlashCommand, - createStageInstance, - createWebhook, - deleteChannel, - deleteChannelOverwrite, - deleteEmoji, - deleteGuild, - deleteGuildTemplate, - deleteIntegration, - deleteInvite, - deleteMessage, - deleteMessages, - deleteRole, - deleteSlashCommand, - deleteSlashResponse, - deleteStageInstance, - deleteThread, - deleteWebhook, - deleteWebhookMessage, - deleteWebhookWithToken, - disconnectMember, - editBotNickname, - editBotProfile, - editBotStatus, - editChannel, - editChannelOverwrite, - editDiscovery, - editEmoji, - editGuild, - editGuildTemplate, - editMember, - editMessage, - editRole, - editSlashCommandPermissions, - editSlashResponse, - editThread, - editWebhook, - editWebhookMessage, - editWebhookWithToken, - editWelcomeScreen, - editWidget, - emojiURL, - fetchMembers, - followChannel, - getActiveThreads, - getApplicationInfo, - getArchivedThreads, - getAuditLogs, - getAvailableVoiceRegions, - getBan, - getBans, - getChannel, - getChannelInvites, - getChannels, - getChannelWebhooks, - getDiscoveryCategories, - getEmoji, - getEmojis, - getGatewayBot, - getGuild, - getGuildPreview, - getGuildTemplates, - getIntegrations, - getInvite, - getInvites, - getMember, - getMembers, - getMessage, - getMessages, - getOriginalInteractionResponse, - getPins, - getPruneCount, - getReactions, - getRoles, - getSlashCommand, - getSlashCommandPermission, - getSlashCommandPermissions, - getSlashCommands, - getStageInstance, - getTemplate, - getThreadMembers, - getUser, - getVanityURL, - getVoiceRegions, - getWebhook, - getWebhookMessage, - getWebhooks, - getWebhookWithToken, - getWelcomeScreen, - getWidget, - getWidgetImageURL, - getWidgetSettings, - guildBannerURL, - guildIconURL, - guildSplashURL, - isButton, - isChannelSynced, - isSelectMenu, - isSlashCommand, - joinThread, - kick, - kickMember, - leaveGuild, - leaveThread, - lockThread, - moveMember, - pin, - pinMessage, - pruneMembers, - publishMessage, - removeAllReactions, - removeDiscoverySubcategory, - removeReaction, - removeReactionEmoji, - removeRole, - removeThreadMember, - sendDirectMessage, - sendInteractionResponse, - sendMessage, - sendWebhook, - startPrivateThread, - startThread, - startTyping, - suppressEmbeds, - swapChannels, - syncGuildTemplate, - unarchiveThread, - unban, - unbanMember, - unlockThread, - unpin, - unpinMessage, - updateBotVoiceState, - updateStageInstance, - upsertSlashCommand, - upsertSlashCommands, - validDiscoveryTerm, -} from "./helpers/mod.ts"; +import * as helpers from "./helpers/mod.ts"; import { DiscordenoEmoji, transformEmoji } from "./transformers/emoji.ts"; import { transformActivity } from "./transformers/activity.ts"; import { DiscordenoPresence, transformPresence } from "./transformers/presence.ts"; @@ -313,9 +106,24 @@ import { urlToBase64 } from "./util/url_to_base64.ts"; import { transformAttachment } from "./transformers/attachment.ts"; import { transformEmbed } from "./transformers/embed.ts"; import { transformComponent } from "./transformers/component.ts"; +import { AsyncCache, AsyncCacheHandler, Cache, CacheHandler, createCache, TableNames } from "./cache.ts"; -export function createBot(options: CreateBotOptions) { - return { +type CacheOptions = + | { + isAsync: true; + // deno-lint-ignore no-explicit-any + customTableCreator: (tableName: TableNames) => AsyncCacheHandler; + } + | { + isAsync: false; + // deno-lint-ignore no-explicit-any + customTableCreator?: (tableName: TableNames) => CacheHandler; + }; + +export function createBot( + options: CreateBotOptions +): Bot { + return ({ id: options.botId, applicationId: options.applicationId || options.botId, token: `Bot ${options.token}`, @@ -326,131 +134,133 @@ export function createBot(options: CreateBotOptions) { activeGuildIds: new Set(), constants: createBotConstants(), handlers: createBotGatewayHandlers({}), - cache: { - execute: async function ( - type: - | "FILTER_CATEGORY_CHILDREN_CHANNELS" - | "DELETE_MESSAGES_FROM_CHANNEL" - | "DELETE_ROLE_FROM_MEMBER" - | "BULK_DELETE_MESSAGES" - | "GUILD_MEMBER_CHUNK" - | "GUILD_MEMBER_COUNT_DECREMENT" - | "GUILD_MEMBER_COUNT_INCREMENT" - | "DELETE_MESSAGES_FROM_GUILD" - | "DELETE_CHANNELS_FROM_GUILD" - | "DELETE_GUILD_FROM_MEMBER", - options: Record - ) {}, - executedSlashCommands: new Set(), - fetchAllMembersProcessingRequests: new Collection(), - messages: { - get: async function (id: bigint): Promise { - return {} as any as DiscordenoMessage; - }, - has: async function (id: bigint): Promise { - return false; - }, - set: async function (id: bigint, guild: DiscordenoMessage): Promise { - return; - }, - delete: async function (id: bigint): Promise { - return; - }, - }, - guilds: { - get: async function (id: bigint): Promise { - return {} as any as DiscordenoGuild; - }, - has: async function (id: bigint): Promise { - return false; - }, - set: async function (id: bigint, guild: DiscordenoGuild): Promise { - return; - }, - delete: async function (id: bigint): Promise { - return; - }, - size: async function (): Promise { - return 0; - }, - }, - channels: { - get: async function (id: bigint): Promise { - return {} as any as DiscordenoChannel; - }, - has: async function (id: bigint): Promise { - return false; - }, - set: async function (id: bigint, guild: DiscordenoChannel): Promise { - return; - }, - delete: async function (id: bigint): Promise { - return; - }, - }, - members: { - get: async function (id: bigint): Promise { - return {} as any as DiscordenoMember; - }, - has: async function (id: bigint): Promise { - return false; - }, - set: async function (id: bigint, member: DiscordenoMember): Promise { - return; - }, - delete: async function (id: bigint): Promise { - return; - }, - }, - presence: { - get: async function (id: bigint): Promise { - return {} as any as DiscordenoPresence; - }, - has: async function (id: bigint): Promise { - return false; - }, - set: async function (id: bigint, guild: DiscordenoPresence): Promise { - return; - }, - delete: async function (id: bigint): Promise { - return; - }, - }, - users: { - get: async function (id: bigint): Promise { - return {} as any as DiscordenoUser; - }, - has: async function (id: bigint): Promise { - return false; - }, - set: async function (id: bigint, member: DiscordenoUser): Promise { - return; - }, - }, - dispatchedGuildIds: { - has: async function (id: bigint): Promise { - return false; - }, - set: async function (id: bigint): Promise { - return; - }, - delete: async function (id: bigint): Promise { - return; - }, - }, - dispatchedChannelIds: { - has: async function (id: bigint): Promise { - return false; - }, - set: async function (id: bigint): Promise { - return; - }, - delete: async function (id: bigint): Promise { - return; - }, - }, - }, - }; + // @ts-ignore b quiet + cache: createCache(options?.cache?.isAsync ?? false, options?.cache?.customTableCreator), + // cache: { + // execute: async function ( + // type: + // | "FILTER_CATEGORY_CHILDREN_CHANNELS" + // | "DELETE_MESSAGES_FROM_CHANNEL" + // | "DELETE_ROLE_FROM_MEMBER" + // | "BULK_DELETE_MESSAGES" + // | "GUILD_MEMBER_CHUNK" + // | "GUILD_MEMBER_COUNT_DECREMENT" + // | "GUILD_MEMBER_COUNT_INCREMENT" + // | "DELETE_MESSAGES_FROM_GUILD" + // | "DELETE_CHANNELS_FROM_GUILD" + // | "DELETE_GUILD_FROM_MEMBER", + // options: Record + // ) {}, + // executedSlashCommands: new Set(), + // fetchAllMembersProcessingRequests: new Collection(), + // messages: { + // get: async function (id: bigint): Promise { + // return ({} as any) as DiscordenoMessage; + // }, + // has: async function (id: bigint): Promise { + // return false; + // }, + // set: async function (id: bigint, guild: DiscordenoMessage): Promise { + // return; + // }, + // delete: async function (id: bigint): Promise { + // return; + // }, + // }, + // guilds: { + // get: async function (id: bigint): Promise { + // return ({} as any) as DiscordenoGuild; + // }, + // has: async function (id: bigint): Promise { + // return false; + // }, + // set: async function (id: bigint, guild: DiscordenoGuild): Promise { + // return; + // }, + // delete: async function (id: bigint): Promise { + // return; + // }, + // size: async function (): Promise { + // return 0; + // }, + // }, + // channels: { + // get: async function (id: bigint): Promise { + // return ({} as any) as DiscordenoChannel; + // }, + // has: async function (id: bigint): Promise { + // return false; + // }, + // set: async function (id: bigint, guild: DiscordenoChannel): Promise { + // return; + // }, + // delete: async function (id: bigint): Promise { + // return; + // }, + // }, + // members: { + // get: async function (id: bigint): Promise { + // return ({} as any) as DiscordenoMember; + // }, + // has: async function (id: bigint): Promise { + // return false; + // }, + // set: async function (id: bigint, member: DiscordenoMember): Promise { + // return; + // }, + // delete: async function (id: bigint): Promise { + // return; + // }, + // }, + // presence: { + // get: async function (id: bigint): Promise { + // return ({} as any) as DiscordenoPresence; + // }, + // has: async function (id: bigint): Promise { + // return false; + // }, + // set: async function (id: bigint, guild: DiscordenoPresence): Promise { + // return; + // }, + // delete: async function (id: bigint): Promise { + // return; + // }, + // }, + // users: { + // get: async function (id: bigint): Promise { + // return ({} as any) as DiscordenoUser; + // }, + // has: async function (id: bigint): Promise { + // return false; + // }, + // set: async function (id: bigint, member: DiscordenoUser): Promise { + // return; + // }, + // }, + // dispatchedGuildIds: { + // has: async function (id: bigint): Promise { + // return false; + // }, + // set: async function (id: bigint): Promise { + // return; + // }, + // delete: async function (id: bigint): Promise { + // return; + // }, + // }, + // dispatchedChannelIds: { + // has: async function (id: bigint): Promise { + // return false; + // }, + // set: async function (id: bigint): Promise { + // return; + // }, + // delete: async function (id: bigint): Promise { + // return; + // }, + // }, + // }, + } as unknown) as Bot; } export function createEventHandlers(events: Partial): EventHandlers { @@ -738,7 +548,7 @@ export async function stopBot(bot: Bot) { await delay(5000); } -export interface CreateBotOptions { +export interface CreateBotOptions { token: string; botId: bigint; applicationId?: bigint; @@ -746,339 +556,362 @@ export interface CreateBotOptions { intents: (keyof typeof DiscordGatewayIntents)[]; botGatewayData?: GetGatewayBot; rest?: Omit; + cache: C; } export type UnPromise> = T extends Promise ? K : never; -export type CreatedBot = ReturnType; +// export type CreatedBot = ReturnType; -export type Bot = CreatedBot & { - utils: HelperUtils; - rest: RestManager; - gateway: GatewayManager; - transformers: Transformers; - helpers: Helpers; -}; +// export type Bot = CreatedBot & { +// utils: HelperUtils; +// rest: RestManager; +// gateway: GatewayManager; +// transformers: Transformers; +// helpers: Helpers; +// }; + +export interface Bot { + id: bigint; + applicationId: bigint; + + token: string; + intents: DiscordGatewayIntents; + urlWSS: string; + botGatewayData?: GetGatewayBot; + utils: ReturnType; + transformers: ReturnType; + helpers: ReturnType; + rest: ReturnType; + gateway: ReturnType; + events: EventHandlers; + handlers: ReturnType; + isReady: boolean; + activeGuildIds: Set; + constants: ReturnType; + cache: C; +} export interface Helpers { - addDiscoverySubcategory: typeof addDiscoverySubcategory; - addReaction: typeof addReaction; - addReactions: typeof addReactions; - addRole: typeof addRole; - avatarURL: typeof avatarURL; - ban: typeof ban; - banMember: typeof banMember; - batchEditSlashCommandPermissions: typeof batchEditSlashCommandPermissions; - categoryChildren: typeof categoryChildren; - channelOverwriteHasPermission: typeof channelOverwriteHasPermission; - connectToVoiceChannel: typeof connectToVoiceChannel; - createChannel: typeof createChannel; - createEmoji: typeof createEmoji; - createGuild: typeof createGuild; - createGuildFromTemplate: typeof createGuildFromTemplate; - createGuildTemplate: typeof createGuildTemplate; - createInvite: typeof createInvite; - createRole: typeof createRole; - createSlashCommand: typeof createSlashCommand; - createStageInstance: typeof createStageInstance; - createWebhook: typeof createWebhook; - deleteChannel: typeof deleteChannel; - deleteChannelOverwrite: typeof deleteChannelOverwrite; - deleteEmoji: typeof deleteEmoji; - deleteGuild: typeof deleteGuild; - deleteGuildTemplate: typeof deleteGuildTemplate; - deleteIntegration: typeof deleteIntegration; - deleteInvite: typeof deleteInvite; - deleteMessage: typeof deleteMessage; - deleteMessages: typeof deleteMessages; - deleteRole: typeof deleteRole; - deleteSlashCommand: typeof deleteSlashCommand; - deleteSlashResponse: typeof deleteSlashResponse; - deleteStageInstance: typeof deleteStageInstance; - deleteWebhook: typeof deleteWebhook; - deleteWebhookMessage: typeof deleteWebhookMessage; - deleteWebhookWithToken: typeof deleteWebhookWithToken; - disconnectMember: typeof disconnectMember; - editBotNickname: typeof editBotNickname; - editBotProfile: typeof editBotProfile; - editBotStatus: typeof editBotStatus; - editChannel: typeof editChannel; - editChannelOverwrite: typeof editChannelOverwrite; - editDiscovery: typeof editDiscovery; - editEmoji: typeof editEmoji; - editGuild: typeof editGuild; - editGuildTemplate: typeof editGuildTemplate; - editMember: typeof editMember; - editMessage: typeof editMessage; - editRole: typeof editRole; - editSlashResponse: typeof editSlashResponse; - editSlashCommandPermissions: typeof editSlashCommandPermissions; - editWebhook: typeof editWebhook; - editWebhookMessage: typeof editWebhookMessage; - editWebhookWithToken: typeof editWebhookWithToken; - editWelcomeScreen: typeof editWelcomeScreen; - editWidget: typeof editWidget; - emojiURL: typeof emojiURL; - fetchMembers: typeof fetchMembers; - followChannel: typeof followChannel; - getAuditLogs: typeof getAuditLogs; - getAvailableVoiceRegions: typeof getAvailableVoiceRegions; - getBan: typeof getBan; - getBans: typeof getBans; - getChannel: typeof getChannel; - getChannelInvites: typeof getChannelInvites; - getChannels: typeof getChannels; - getChannelWebhooks: typeof getChannelWebhooks; - getDiscoveryCategories: typeof getDiscoveryCategories; - getEmoji: typeof getEmoji; - getEmojis: typeof getEmojis; - getGatewayBot: typeof getGatewayBot; - getGuild: typeof getGuild; - getGuildPreview: typeof getGuildPreview; - getGuildTemplates: typeof getGuildTemplates; - getIntegrations: typeof getIntegrations; - getInvite: typeof getInvite; - getInvites: typeof getInvites; - getMember: typeof getMember; - getMembers: typeof getMembers; - getMessage: typeof getMessage; - getMessages: typeof getMessages; - getOriginalInteractionResponse: typeof getOriginalInteractionResponse; - getPins: typeof getPins; - getPruneCount: typeof getPruneCount; - getReactions: typeof getReactions; - getRoles: typeof getRoles; - getSlashCommand: typeof getSlashCommand; - getSlashCommandPermission: typeof getSlashCommandPermission; - getSlashCommandPermissions: typeof getSlashCommandPermissions; - getSlashCommands: typeof getSlashCommands; - getStageInstance: typeof getStageInstance; - getTemplate: typeof getTemplate; - getUser: typeof getUser; - getApplicationInfo: typeof getApplicationInfo; - getVanityURL: typeof getVanityURL; - getVoiceRegions: typeof getVoiceRegions; - getWebhook: typeof getWebhook; - getWebhookMessage: typeof getWebhookMessage; - getWebhooks: typeof getWebhooks; - getWebhookWithToken: typeof getWebhookWithToken; - getWelcomeScreen: typeof getWelcomeScreen; - getWidget: typeof getWidget; - getWidgetImageURL: typeof getWidgetImageURL; - getWidgetSettings: typeof getWidgetSettings; - guildBannerURL: typeof guildBannerURL; - guildIconURL: typeof guildIconURL; - guildSplashURL: typeof guildSplashURL; - isButton: typeof isButton; - isSelectMenu: typeof isSelectMenu; - isSlashCommand: typeof isSlashCommand; - isChannelSynced: typeof isChannelSynced; - kick: typeof kick; - kickMember: typeof kickMember; - leaveGuild: typeof leaveGuild; - moveMember: typeof moveMember; - pin: typeof pin; - pinMessage: typeof pinMessage; - pruneMembers: typeof pruneMembers; - publishMessage: typeof publishMessage; - removeAllReactions: typeof removeAllReactions; - removeDiscoverySubcategory: typeof removeDiscoverySubcategory; - removeReaction: typeof removeReaction; - removeReactionEmoji: typeof removeReactionEmoji; - removeRole: typeof removeRole; - sendDirectMessage: typeof sendDirectMessage; - sendInteractionResponse: typeof sendInteractionResponse; - sendMessage: typeof sendMessage; - sendWebhook: typeof sendWebhook; - startTyping: typeof startTyping; - swapChannels: typeof swapChannels; - syncGuildTemplate: typeof syncGuildTemplate; - unban: typeof unban; - unbanMember: typeof unbanMember; - unpin: typeof unpin; - unpinMessage: typeof unpinMessage; - updateBotVoiceState: typeof updateBotVoiceState; - updateStageInstance: typeof updateStageInstance; - upsertSlashCommand: typeof upsertSlashCommand; - upsertSlashCommands: typeof upsertSlashCommands; - validDiscoveryTerm: typeof validDiscoveryTerm; - addToThread: typeof addToThread; - archiveThread: typeof archiveThread; - deleteThread: typeof deleteThread; - editThread: typeof editThread; - getActiveThreads: typeof getActiveThreads; - getArchivedThreads: typeof getArchivedThreads; - getThreadMembers: typeof getThreadMembers; - joinThread: typeof joinThread; - leaveThread: typeof leaveThread; - lockThread: typeof lockThread; - removeThreadMember: typeof removeThreadMember; - startPrivateThread: typeof startPrivateThread; - startThread: typeof startThread; - unarchiveThread: typeof unarchiveThread; - unlockThread: typeof unlockThread; - suppressEmbeds: typeof suppressEmbeds; + addDiscoverySubcategory: typeof helpers.addDiscoverySubcategory; + addReaction: typeof helpers.addReaction; + addReactions: typeof helpers.addReactions; + addRole: typeof helpers.addRole; + avatarURL: typeof helpers.avatarURL; + ban: typeof helpers.ban; + banMember: typeof helpers.banMember; + batchEditSlashCommandPermissions: typeof helpers.batchEditSlashCommandPermissions; + categoryChildren: typeof helpers.categoryChildren; + channelOverwriteHasPermission: typeof helpers.channelOverwriteHasPermission; + connectToVoiceChannel: typeof helpers.connectToVoiceChannel; + createChannel: typeof helpers.createChannel; + createEmoji: typeof helpers.createEmoji; + createGuild: typeof helpers.createGuild; + createGuildFromTemplate: typeof helpers.createGuildFromTemplate; + createGuildTemplate: typeof helpers.createGuildTemplate; + createInvite: typeof helpers.createInvite; + createRole: typeof helpers.createRole; + createSlashCommand: typeof helpers.createSlashCommand; + createStageInstance: typeof helpers.createStageInstance; + createWebhook: typeof helpers.createWebhook; + deleteChannel: typeof helpers.deleteChannel; + deleteChannelOverwrite: typeof helpers.deleteChannelOverwrite; + deleteEmoji: typeof helpers.deleteEmoji; + deleteGuild: typeof helpers.deleteGuild; + deleteGuildTemplate: typeof helpers.deleteGuildTemplate; + deleteIntegration: typeof helpers.deleteIntegration; + deleteInvite: typeof helpers.deleteInvite; + deleteMessage: typeof helpers.deleteMessage; + deleteMessages: typeof helpers.deleteMessages; + deleteRole: typeof helpers.deleteRole; + deleteSlashCommand: typeof helpers.deleteSlashCommand; + deleteSlashResponse: typeof helpers.deleteSlashResponse; + deleteStageInstance: typeof helpers.deleteStageInstance; + deleteWebhook: typeof helpers.deleteWebhook; + deleteWebhookMessage: typeof helpers.deleteWebhookMessage; + deleteWebhookWithToken: typeof helpers.deleteWebhookWithToken; + disconnectMember: typeof helpers.disconnectMember; + editBotNickname: typeof helpers.editBotNickname; + editBotProfile: typeof helpers.editBotProfile; + editBotStatus: typeof helpers.editBotStatus; + editChannel: typeof helpers.editChannel; + editChannelOverwrite: typeof helpers.editChannelOverwrite; + editDiscovery: typeof helpers.editDiscovery; + editEmoji: typeof helpers.editEmoji; + editGuild: typeof helpers.editGuild; + editGuildTemplate: typeof helpers.editGuildTemplate; + editMember: typeof helpers.editMember; + editMessage: typeof helpers.editMessage; + editRole: typeof helpers.editRole; + editSlashResponse: typeof helpers.editSlashResponse; + editSlashCommandPermissions: typeof helpers.editSlashCommandPermissions; + editWebhook: typeof helpers.editWebhook; + editWebhookMessage: typeof helpers.editWebhookMessage; + editWebhookWithToken: typeof helpers.editWebhookWithToken; + editWelcomeScreen: typeof helpers.editWelcomeScreen; + editWidget: typeof helpers.editWidget; + emojiURL: typeof helpers.emojiURL; + fetchMembers: typeof helpers.fetchMembers; + followChannel: typeof helpers.followChannel; + getAuditLogs: typeof helpers.getAuditLogs; + getAvailableVoiceRegions: typeof helpers.getAvailableVoiceRegions; + getBan: typeof helpers.getBan; + getBans: typeof helpers.getBans; + getChannel: typeof helpers.getChannel; + getChannelInvites: typeof helpers.getChannelInvites; + getChannels: typeof helpers.getChannels; + getChannelWebhooks: typeof helpers.getChannelWebhooks; + getDiscoveryCategories: typeof helpers.getDiscoveryCategories; + getEmoji: typeof helpers.getEmoji; + getEmojis: typeof helpers.getEmojis; + getGatewayBot: typeof helpers.getGatewayBot; + getGuild: typeof helpers.getGuild; + getGuildPreview: typeof helpers.getGuildPreview; + getGuildTemplates: typeof helpers.getGuildTemplates; + getIntegrations: typeof helpers.getIntegrations; + getInvite: typeof helpers.getInvite; + getInvites: typeof helpers.getInvites; + getMember: typeof helpers.getMember; + getMembers: typeof helpers.getMembers; + getMessage: typeof helpers.getMessage; + getMessages: typeof helpers.getMessages; + getOriginalInteractionResponse: typeof helpers.getOriginalInteractionResponse; + getPins: typeof helpers.getPins; + getPruneCount: typeof helpers.getPruneCount; + getReactions: typeof helpers.getReactions; + getRoles: typeof helpers.getRoles; + getSlashCommand: typeof helpers.getSlashCommand; + getSlashCommandPermission: typeof helpers.getSlashCommandPermission; + getSlashCommandPermissions: typeof helpers.getSlashCommandPermissions; + getSlashCommands: typeof helpers.getSlashCommands; + getStageInstance: typeof helpers.getStageInstance; + getTemplate: typeof helpers.getTemplate; + getUser: typeof helpers.getUser; + getApplicationInfo: typeof helpers.getApplicationInfo; + getVanityURL: typeof helpers.getVanityURL; + getVoiceRegions: typeof helpers.getVoiceRegions; + getWebhook: typeof helpers.getWebhook; + getWebhookMessage: typeof helpers.getWebhookMessage; + getWebhooks: typeof helpers.getWebhooks; + getWebhookWithToken: typeof helpers.getWebhookWithToken; + getWelcomeScreen: typeof helpers.getWelcomeScreen; + getWidget: typeof helpers.getWidget; + getWidgetImageURL: typeof helpers.getWidgetImageURL; + getWidgetSettings: typeof helpers.getWidgetSettings; + guildBannerURL: typeof helpers.guildBannerURL; + guildIconURL: typeof helpers.guildIconURL; + guildSplashURL: typeof helpers.guildSplashURL; + isButton: typeof helpers.isButton; + isSelectMenu: typeof helpers.isSelectMenu; + isSlashCommand: typeof helpers.isSlashCommand; + isChannelSynced: typeof helpers.isChannelSynced; + kick: typeof helpers.kick; + kickMember: typeof helpers.kickMember; + leaveGuild: typeof helpers.leaveGuild; + moveMember: typeof helpers.moveMember; + pin: typeof helpers.pin; + pinMessage: typeof helpers.pinMessage; + pruneMembers: typeof helpers.pruneMembers; + publishMessage: typeof helpers.publishMessage; + removeAllReactions: typeof helpers.removeAllReactions; + removeDiscoverySubcategory: typeof helpers.removeDiscoverySubcategory; + removeReaction: typeof helpers.removeReaction; + removeReactionEmoji: typeof helpers.removeReactionEmoji; + removeRole: typeof helpers.removeRole; + sendDirectMessage: typeof helpers.sendDirectMessage; + sendInteractionResponse: typeof helpers.sendInteractionResponse; + sendMessage: typeof helpers.sendMessage; + sendWebhook: typeof helpers.sendWebhook; + startTyping: typeof helpers.startTyping; + swapChannels: typeof helpers.swapChannels; + syncGuildTemplate: typeof helpers.syncGuildTemplate; + unban: typeof helpers.unban; + unbanMember: typeof helpers.unbanMember; + unpin: typeof helpers.unpin; + unpinMessage: typeof helpers.unpinMessage; + updateBotVoiceState: typeof helpers.updateBotVoiceState; + updateStageInstance: typeof helpers.updateStageInstance; + upsertSlashCommand: typeof helpers.upsertSlashCommand; + upsertSlashCommands: typeof helpers.upsertSlashCommands; + validDiscoveryTerm: typeof helpers.validDiscoveryTerm; + addToThread: typeof helpers.addToThread; + archiveThread: typeof helpers.archiveThread; + deleteThread: typeof helpers.deleteThread; + editThread: typeof helpers.editThread; + getActiveThreads: typeof helpers.getActiveThreads; + getArchivedThreads: typeof helpers.getArchivedThreads; + getThreadMembers: typeof helpers.getThreadMembers; + joinThread: typeof helpers.joinThread; + leaveThread: typeof helpers.leaveThread; + lockThread: typeof helpers.lockThread; + removeThreadMember: typeof helpers.removeThreadMember; + startPrivateThread: typeof helpers.startPrivateThread; + startThread: typeof helpers.startThread; + unarchiveThread: typeof helpers.unarchiveThread; + unlockThread: typeof helpers.unlockThread; + suppressEmbeds: typeof helpers.suppressEmbeds; } export function createHelpers(options: Partial) { return { - addDiscoverySubcategory: options.addDiscoverySubcategory || addDiscoverySubcategory, - addReaction: options.addReaction || addReaction, - addReactions: options.addReactions || addReactions, - addRole: options.addRole || addRole, - avatarURL: options.avatarURL || avatarURL, - ban: options.ban || ban, - banMember: options.banMember || banMember, - batchEditSlashCommandPermissions: options.batchEditSlashCommandPermissions || batchEditSlashCommandPermissions, - categoryChildren: options.categoryChildren || categoryChildren, - channelOverwriteHasPermission: options.channelOverwriteHasPermission || channelOverwriteHasPermission, - connectToVoiceChannel: options.connectToVoiceChannel || connectToVoiceChannel, - createChannel: options.createChannel || createChannel, - createEmoji: options.createEmoji || createEmoji, - createGuild: options.createGuild || createGuild, - createGuildFromTemplate: options.createGuildFromTemplate || createGuildFromTemplate, - createGuildTemplate: options.createGuildTemplate || createGuildTemplate, - createInvite: options.createInvite || createInvite, - createRole: options.createRole || createRole, - createSlashCommand: options.createSlashCommand || createSlashCommand, - createStageInstance: options.createStageInstance || createStageInstance, - createWebhook: options.createWebhook || createWebhook, - deleteChannel: options.deleteChannel || deleteChannel, - deleteChannelOverwrite: options.deleteChannelOverwrite || deleteChannelOverwrite, - deleteEmoji: options.deleteEmoji || deleteEmoji, - deleteGuild: options.deleteGuild || deleteGuild, - deleteGuildTemplate: options.deleteGuildTemplate || deleteGuildTemplate, - deleteIntegration: options.deleteIntegration || deleteIntegration, - deleteInvite: options.deleteInvite || deleteInvite, - deleteMessage: options.deleteMessage || deleteMessage, - deleteMessages: options.deleteMessages || deleteMessages, - deleteRole: options.deleteRole || deleteRole, - deleteSlashCommand: options.deleteSlashCommand || deleteSlashCommand, - deleteSlashResponse: options.deleteSlashResponse || deleteSlashResponse, - deleteStageInstance: options.deleteStageInstance || deleteStageInstance, - deleteWebhook: options.deleteWebhook || deleteWebhook, - deleteWebhookMessage: options.deleteWebhookMessage || deleteWebhookMessage, - deleteWebhookWithToken: options.deleteWebhookWithToken || deleteWebhookWithToken, - disconnectMember: options.disconnectMember || disconnectMember, - editBotNickname: options.editBotNickname || editBotNickname, - editBotProfile: options.editBotProfile || editBotProfile, - editBotStatus: options.editBotStatus || editBotStatus, - editChannel: options.editChannel || editChannel, - editChannelOverwrite: options.editChannelOverwrite || editChannelOverwrite, - editDiscovery: options.editDiscovery || editDiscovery, - editEmoji: options.editEmoji || editEmoji, - editGuild: options.editGuild || editGuild, - editGuildTemplate: options.editGuildTemplate || editGuildTemplate, - editMember: options.editMember || editMember, - editMessage: options.editMessage || editMessage, - editRole: options.editRole || editRole, - editSlashResponse: options.editSlashResponse || editSlashResponse, - editSlashCommandPermissions: options.editSlashCommandPermissions || editSlashCommandPermissions, - editWebhook: options.editWebhook || editWebhook, - editWebhookMessage: options.editWebhookMessage || editWebhookMessage, - editWebhookWithToken: options.editWebhookWithToken || editWebhookWithToken, - editWelcomeScreen: options.editWelcomeScreen || editWelcomeScreen, - editWidget: options.editWidget || editWidget, - emojiURL: options.emojiURL || emojiURL, - fetchMembers: options.fetchMembers || fetchMembers, - followChannel: options.followChannel || followChannel, - getAuditLogs: options.getAuditLogs || getAuditLogs, - getAvailableVoiceRegions: options.getAvailableVoiceRegions || getAvailableVoiceRegions, - getBan: options.getBan || getBan, - getBans: options.getBans || getBans, - getChannel: options.getChannel || getChannel, - getChannelInvites: options.getChannelInvites || getChannelInvites, - getChannels: options.getChannels || getChannels, - getChannelWebhooks: options.getChannelWebhooks || getChannelWebhooks, - getDiscoveryCategories: options.getDiscoveryCategories || getDiscoveryCategories, - getEmoji: options.getEmoji || getEmoji, - getEmojis: options.getEmojis || getEmojis, - getGatewayBot: options.getGatewayBot || getGatewayBot, - getGuild: options.getGuild || getGuild, - getGuildPreview: options.getGuildPreview || getGuildPreview, - getGuildTemplates: options.getGuildTemplates || getGuildTemplates, - getIntegrations: options.getIntegrations || getIntegrations, - getInvite: options.getInvite || getInvite, - getInvites: options.getInvites || getInvites, - getMember: options.getMember || getMember, - getMembers: options.getMembers || getMembers, - getMessage: options.getMessage || getMessage, - getMessages: options.getMessages || getMessages, - getOriginalInteractionResponse: options.getOriginalInteractionResponse || getOriginalInteractionResponse, - getPins: options.getPins || getPins, - getPruneCount: options.getPruneCount || getPruneCount, - getReactions: options.getReactions || getReactions, - getRoles: options.getRoles || getRoles, - getSlashCommand: options.getSlashCommand || getSlashCommand, - getSlashCommandPermission: options.getSlashCommandPermission || getSlashCommandPermission, - getSlashCommandPermissions: options.getSlashCommandPermissions || getSlashCommandPermissions, - getSlashCommands: options.getSlashCommands || getSlashCommands, - getStageInstance: options.getStageInstance || getStageInstance, - getTemplate: options.getTemplate || getTemplate, - getUser: options.getUser || getUser, - getApplicationInfo: options.getApplicationInfo || getApplicationInfo, - getVanityURL: options.getVanityURL || getVanityURL, - getVoiceRegions: options.getVoiceRegions || getVoiceRegions, - getWebhook: options.getWebhook || getWebhook, - getWebhookMessage: options.getWebhookMessage || getWebhookMessage, - getWebhooks: options.getWebhooks || getWebhooks, - getWebhookWithToken: options.getWebhookWithToken || getWebhookWithToken, - getWelcomeScreen: options.getWelcomeScreen || getWelcomeScreen, - getWidget: options.getWidget || getWidget, - getWidgetImageURL: options.getWidgetImageURL || getWidgetImageURL, - getWidgetSettings: options.getWidgetSettings || getWidgetSettings, - guildBannerURL: options.guildBannerURL || guildBannerURL, - guildIconURL: options.guildIconURL || guildIconURL, - guildSplashURL: options.guildSplashURL || guildSplashURL, - isButton: options.isButton || isButton, - isSelectMenu: options.isSelectMenu || isSelectMenu, - isSlashCommand: options.isSlashCommand || isSlashCommand, - isChannelSynced: options.isChannelSynced || isChannelSynced, - kick: options.kick || kick, - kickMember: options.kickMember || kickMember, - leaveGuild: options.leaveGuild || leaveGuild, - moveMember: options.moveMember || moveMember, - pin: options.pin || pin, - pinMessage: options.pinMessage || pinMessage, - pruneMembers: options.pruneMembers || pruneMembers, - publishMessage: options.publishMessage || publishMessage, - removeAllReactions: options.removeAllReactions || removeAllReactions, - removeDiscoverySubcategory: options.removeDiscoverySubcategory || removeDiscoverySubcategory, - removeReaction: options.removeReaction || removeReaction, - removeReactionEmoji: options.removeReactionEmoji || removeReactionEmoji, - removeRole: options.removeRole || removeRole, - sendDirectMessage: options.sendDirectMessage || sendDirectMessage, - sendInteractionResponse: options.sendInteractionResponse || sendInteractionResponse, - sendMessage: options.sendMessage || sendMessage, - sendWebhook: options.sendWebhook || sendWebhook, - startTyping: options.startTyping || startTyping, - swapChannels: options.swapChannels || swapChannels, - syncGuildTemplate: options.syncGuildTemplate || syncGuildTemplate, - unban: options.unban || unban, - unbanMember: options.unbanMember || unbanMember, - unpin: options.unpin || unpin, - unpinMessage: options.unpinMessage || unpinMessage, - updateBotVoiceState: options.updateBotVoiceState || updateBotVoiceState, - updateStageInstance: options.updateStageInstance || updateStageInstance, - upsertSlashCommand: options.upsertSlashCommand || upsertSlashCommand, - upsertSlashCommands: options.upsertSlashCommands || upsertSlashCommands, - validDiscoveryTerm: options.validDiscoveryTerm || validDiscoveryTerm, - addToThread: options.addToThread || addToThread, - archiveThread: options.archiveThread || archiveThread, - deleteThread: options.deleteThread || deleteThread, - editThread: options.editThread || editThread, - getActiveThreads: options.getActiveThreads || getActiveThreads, - getArchivedThreads: options.getArchivedThreads || getArchivedThreads, - getThreadMembers: options.getThreadMembers || getThreadMembers, - joinThread: options.joinThread || joinThread, - leaveThread: options.leaveThread || leaveThread, - lockThread: options.lockThread || lockThread, - removeThreadMember: options.removeThreadMember || removeThreadMember, - startPrivateThread: options.startPrivateThread || startPrivateThread, - startThread: options.startThread || startThread, - unarchiveThread: options.unarchiveThread || unarchiveThread, - unlockThread: options.unlockThread || unlockThread, - suppressEmbeds: options.suppressEmbeds || suppressEmbeds, + addDiscoverySubcategory: options.addDiscoverySubcategory || helpers.addDiscoverySubcategory, + addReaction: options.addReaction || helpers.addReaction, + addReactions: options.addReactions || helpers.addReactions, + addRole: options.addRole || helpers.addRole, + avatarURL: options.avatarURL || helpers.avatarURL, + ban: options.ban || helpers.ban, + banMember: options.banMember || helpers.banMember, + batchEditSlashCommandPermissions: + options.batchEditSlashCommandPermissions || helpers.batchEditSlashCommandPermissions, + categoryChildren: options.categoryChildren || helpers.categoryChildren, + channelOverwriteHasPermission: options.channelOverwriteHasPermission || helpers.channelOverwriteHasPermission, + connectToVoiceChannel: options.connectToVoiceChannel || helpers.connectToVoiceChannel, + createChannel: options.createChannel || helpers.createChannel, + createEmoji: options.createEmoji || helpers.createEmoji, + createGuild: options.createGuild || helpers.createGuild, + createGuildFromTemplate: options.createGuildFromTemplate || helpers.createGuildFromTemplate, + createGuildTemplate: options.createGuildTemplate || helpers.createGuildTemplate, + createInvite: options.createInvite || helpers.createInvite, + createRole: options.createRole || helpers.createRole, + createSlashCommand: options.createSlashCommand || helpers.createSlashCommand, + createStageInstance: options.createStageInstance || helpers.createStageInstance, + createWebhook: options.createWebhook || helpers.createWebhook, + deleteChannel: options.deleteChannel || helpers.deleteChannel, + deleteChannelOverwrite: options.deleteChannelOverwrite || helpers.deleteChannelOverwrite, + deleteEmoji: options.deleteEmoji || helpers.deleteEmoji, + deleteGuild: options.deleteGuild || helpers.deleteGuild, + deleteGuildTemplate: options.deleteGuildTemplate || helpers.deleteGuildTemplate, + deleteIntegration: options.deleteIntegration || helpers.deleteIntegration, + deleteInvite: options.deleteInvite || helpers.deleteInvite, + deleteMessage: options.deleteMessage || helpers.deleteMessage, + deleteMessages: options.deleteMessages || helpers.deleteMessages, + deleteRole: options.deleteRole || helpers.deleteRole, + deleteSlashCommand: options.deleteSlashCommand || helpers.deleteSlashCommand, + deleteSlashResponse: options.deleteSlashResponse || helpers.deleteSlashResponse, + deleteStageInstance: options.deleteStageInstance || helpers.deleteStageInstance, + deleteWebhook: options.deleteWebhook || helpers.deleteWebhook, + deleteWebhookMessage: options.deleteWebhookMessage || helpers.deleteWebhookMessage, + deleteWebhookWithToken: options.deleteWebhookWithToken || helpers.deleteWebhookWithToken, + disconnectMember: options.disconnectMember || helpers.disconnectMember, + editBotNickname: options.editBotNickname || helpers.editBotNickname, + editBotProfile: options.editBotProfile || helpers.editBotProfile, + editBotStatus: options.editBotStatus || helpers.editBotStatus, + editChannel: options.editChannel || helpers.editChannel, + editChannelOverwrite: options.editChannelOverwrite || helpers.editChannelOverwrite, + editDiscovery: options.editDiscovery || helpers.editDiscovery, + editEmoji: options.editEmoji || helpers.editEmoji, + editGuild: options.editGuild || helpers.editGuild, + editGuildTemplate: options.editGuildTemplate || helpers.editGuildTemplate, + editMember: options.editMember || helpers.editMember, + editMessage: options.editMessage || helpers.editMessage, + editRole: options.editRole || helpers.editRole, + editSlashResponse: options.editSlashResponse || helpers.editSlashResponse, + editSlashCommandPermissions: options.editSlashCommandPermissions || helpers.editSlashCommandPermissions, + editWebhook: options.editWebhook || helpers.editWebhook, + editWebhookMessage: options.editWebhookMessage || helpers.editWebhookMessage, + editWebhookWithToken: options.editWebhookWithToken || helpers.editWebhookWithToken, + editWelcomeScreen: options.editWelcomeScreen || helpers.editWelcomeScreen, + editWidget: options.editWidget || helpers.editWidget, + emojiURL: options.emojiURL || helpers.emojiURL, + fetchMembers: options.fetchMembers || helpers.fetchMembers, + followChannel: options.followChannel || helpers.followChannel, + getAuditLogs: options.getAuditLogs || helpers.getAuditLogs, + getAvailableVoiceRegions: options.getAvailableVoiceRegions || helpers.getAvailableVoiceRegions, + getBan: options.getBan || helpers.getBan, + getBans: options.getBans || helpers.getBans, + getChannel: options.getChannel || helpers.getChannel, + getChannelInvites: options.getChannelInvites || helpers.getChannelInvites, + getChannels: options.getChannels || helpers.getChannels, + getChannelWebhooks: options.getChannelWebhooks || helpers.getChannelWebhooks, + getDiscoveryCategories: options.getDiscoveryCategories || helpers.getDiscoveryCategories, + getEmoji: options.getEmoji || helpers.getEmoji, + getEmojis: options.getEmojis || helpers.getEmojis, + getGatewayBot: options.getGatewayBot || helpers.getGatewayBot, + getGuild: options.getGuild || helpers.getGuild, + getGuildPreview: options.getGuildPreview || helpers.getGuildPreview, + getGuildTemplates: options.getGuildTemplates || helpers.getGuildTemplates, + getIntegrations: options.getIntegrations || helpers.getIntegrations, + getInvite: options.getInvite || helpers.getInvite, + getInvites: options.getInvites || helpers.getInvites, + getMember: options.getMember || helpers.getMember, + getMembers: options.getMembers || helpers.getMembers, + getMessage: options.getMessage || helpers.getMessage, + getMessages: options.getMessages || helpers.getMessages, + getOriginalInteractionResponse: options.getOriginalInteractionResponse || helpers.getOriginalInteractionResponse, + getPins: options.getPins || helpers.getPins, + getPruneCount: options.getPruneCount || helpers.getPruneCount, + getReactions: options.getReactions || helpers.getReactions, + getRoles: options.getRoles || helpers.getRoles, + getSlashCommand: options.getSlashCommand || helpers.getSlashCommand, + getSlashCommandPermission: options.getSlashCommandPermission || helpers.getSlashCommandPermission, + getSlashCommandPermissions: options.getSlashCommandPermissions || helpers.getSlashCommandPermissions, + getSlashCommands: options.getSlashCommands || helpers.getSlashCommands, + getStageInstance: options.getStageInstance || helpers.getStageInstance, + getTemplate: options.getTemplate || helpers.getTemplate, + getUser: options.getUser || helpers.getUser, + getApplicationInfo: options.getApplicationInfo || helpers.getApplicationInfo, + getVanityURL: options.getVanityURL || helpers.getVanityURL, + getVoiceRegions: options.getVoiceRegions || helpers.getVoiceRegions, + getWebhook: options.getWebhook || helpers.getWebhook, + getWebhookMessage: options.getWebhookMessage || helpers.getWebhookMessage, + getWebhooks: options.getWebhooks || helpers.getWebhooks, + getWebhookWithToken: options.getWebhookWithToken || helpers.getWebhookWithToken, + getWelcomeScreen: options.getWelcomeScreen || helpers.getWelcomeScreen, + getWidget: options.getWidget || helpers.getWidget, + getWidgetImageURL: options.getWidgetImageURL || helpers.getWidgetImageURL, + getWidgetSettings: options.getWidgetSettings || helpers.getWidgetSettings, + guildBannerURL: options.guildBannerURL || helpers.guildBannerURL, + guildIconURL: options.guildIconURL || helpers.guildIconURL, + guildSplashURL: options.guildSplashURL || helpers.guildSplashURL, + isButton: options.isButton || helpers.isButton, + isSelectMenu: options.isSelectMenu || helpers.isSelectMenu, + isSlashCommand: options.isSlashCommand || helpers.isSlashCommand, + isChannelSynced: options.isChannelSynced || helpers.isChannelSynced, + kick: options.kick || helpers.kick, + kickMember: options.kickMember || helpers.kickMember, + leaveGuild: options.leaveGuild || helpers.leaveGuild, + moveMember: options.moveMember || helpers.moveMember, + pin: options.pin || helpers.pin, + pinMessage: options.pinMessage || helpers.pinMessage, + pruneMembers: options.pruneMembers || helpers.pruneMembers, + publishMessage: options.publishMessage || helpers.publishMessage, + removeAllReactions: options.removeAllReactions || helpers.removeAllReactions, + removeDiscoverySubcategory: options.removeDiscoverySubcategory || helpers.removeDiscoverySubcategory, + removeReaction: options.removeReaction || helpers.removeReaction, + removeReactionEmoji: options.removeReactionEmoji || helpers.removeReactionEmoji, + removeRole: options.removeRole || helpers.removeRole, + sendDirectMessage: options.sendDirectMessage || helpers.sendDirectMessage, + sendInteractionResponse: options.sendInteractionResponse || helpers.sendInteractionResponse, + sendMessage: options.sendMessage || helpers.sendMessage, + sendWebhook: options.sendWebhook || helpers.sendWebhook, + startTyping: options.startTyping || helpers.startTyping, + swapChannels: options.swapChannels || helpers.swapChannels, + syncGuildTemplate: options.syncGuildTemplate || helpers.syncGuildTemplate, + unban: options.unban || helpers.unban, + unbanMember: options.unbanMember || helpers.unbanMember, + unpin: options.unpin || helpers.unpin, + unpinMessage: options.unpinMessage || helpers.unpinMessage, + updateBotVoiceState: options.updateBotVoiceState || helpers.updateBotVoiceState, + updateStageInstance: options.updateStageInstance || helpers.updateStageInstance, + upsertSlashCommand: options.upsertSlashCommand || helpers.upsertSlashCommand, + upsertSlashCommands: options.upsertSlashCommands || helpers.upsertSlashCommands, + validDiscoveryTerm: options.validDiscoveryTerm || helpers.validDiscoveryTerm, + addToThread: options.addToThread || helpers.addToThread, + archiveThread: options.archiveThread || helpers.archiveThread, + deleteThread: options.deleteThread || helpers.deleteThread, + editThread: options.editThread || helpers.editThread, + getActiveThreads: options.getActiveThreads || helpers.getActiveThreads, + getArchivedThreads: options.getArchivedThreads || helpers.getArchivedThreads, + getThreadMembers: options.getThreadMembers || helpers.getThreadMembers, + joinThread: options.joinThread || helpers.joinThread, + leaveThread: options.leaveThread || helpers.leaveThread, + lockThread: options.lockThread || helpers.lockThread, + removeThreadMember: options.removeThreadMember || helpers.removeThreadMember, + startPrivateThread: options.startPrivateThread || helpers.startPrivateThread, + startThread: options.startThread || helpers.startThread, + unarchiveThread: options.unarchiveThread || helpers.unarchiveThread, + unlockThread: options.unlockThread || helpers.unlockThread, + suppressEmbeds: options.suppressEmbeds || helpers.suppressEmbeds, }; } @@ -1407,55 +1240,55 @@ export function createBotConstants() { } export interface BotGatewayHandlerOptions { - READY: typeof handleReady; - CHANNEL_CREATE: typeof handleChannelCreate; - CHANNEL_DELETE: typeof handleChannelDelete; - CHANNEL_PINS_UPDATE: typeof handleChannelPinsUpdate; - CHANNEL_UPDATE: typeof handleChannelUpdate; - THREAD_CREATE: typeof handleThreadCreate; - THREAD_UPDATE: typeof handleThreadUpdate; - THREAD_DELETE: typeof handleThreadDelete; - THREAD_LIST_SYNC: typeof handleThreadListSync; - THREAD_MEMBER_UPDATE: typeof handleThreadMemberUpdate; - THREAD_MEMBERS_UPDATE: typeof handleThreadMembersUpdate; - STAGE_INSTANCE_CREATE: typeof handleStageInstanceCreate; - STAGE_INSTANCE_UPDATE: typeof handleStageInstanceUpdate; - STAGE_INSTANCE_DELETE: typeof handleStageInstanceDelete; - GUILD_BAN_ADD: typeof handleGuildBanAdd; - GUILD_BAN_REMOVE: typeof handleGuildBanRemove; - GUILD_CREATE: typeof handleGuildCreate; - GUILD_LOADED_DD: typeof handleGuildLoaded; - GUILD_DELETE: typeof handleGuildDelete; - GUILD_EMOJIS_UPDATE: typeof handleGuildEmojisUpdate; - GUILD_INTEGRATIONS_UPDATE: typeof handleGuildIntegrationsUpdate; - GUILD_MEMBER_ADD: typeof handleGuildMemberAdd; - GUILD_MEMBER_REMOVE: typeof handleGuildMemberRemove; - GUILD_MEMBER_UPDATE: typeof handleGuildMemberUpdate; - GUILD_MEMBERS_CHUNK: typeof handleGuildMembersChunk; - GUILD_ROLE_CREATE: typeof handleGuildRoleCreate; - GUILD_ROLE_DELETE: typeof handleGuildRoleDelete; - GUILD_ROLE_UPDATE: typeof handleGuildRoleUpdate; - GUILD_UPDATE: typeof handleGuildUpdate; - INTERACTION_CREATE: typeof handleInteractionCreate; - INVITE_CREATE: typeof handleInviteCreate; - INVITE_DELETE: typeof handleInviteCreate; - MESSAGE_CREATE: typeof handleMessageCreate; - MESSAGE_DELETE_BULK: typeof handleMessageDeleteBulk; - MESSAGE_DELETE: typeof handleMessageDelete; - MESSAGE_REACTION_ADD: typeof handleMessageReactionAdd; - MESSAGE_REACTION_REMOVE_ALL: typeof handleMessageReactionRemoveAll; - MESSAGE_REACTION_REMOVE_EMOJI: typeof handleMessageReactionRemoveEmoji; - MESSAGE_REACTION_REMOVE: typeof handleMessageReactionRemove; - MESSAGE_UPDATE: typeof handleMessageUpdate; - PRESENCE_UPDATE: typeof handlePresenceUpdate; - TYPING_START: typeof handleTypingStart; - USER_UPDATE: typeof handleUserUpdate; - VOICE_SERVER_UPDATE: typeof handleVoiceServerUpdate; - VOICE_STATE_UPDATE: typeof handleVoiceStateUpdate; - WEBHOOKS_UPDATE: typeof handleWebhooksUpdate; - INTEGRATION_CREATE: typeof handleIntegrationCreate; - INTEGRATION_UPDATE: typeof handleIntegrationUpdate; - INTEGRATION_DELETE: typeof handleIntegrationDelete; + READY: typeof handlers.handleReady; + CHANNEL_CREATE: typeof handlers.handleChannelCreate; + CHANNEL_DELETE: typeof handlers.handleChannelDelete; + CHANNEL_PINS_UPDATE: typeof handlers.handleChannelPinsUpdate; + CHANNEL_UPDATE: typeof handlers.handleChannelUpdate; + THREAD_CREATE: typeof handlers.handleThreadCreate; + THREAD_UPDATE: typeof handlers.handleThreadUpdate; + THREAD_DELETE: typeof handlers.handleThreadDelete; + THREAD_LIST_SYNC: typeof handlers.handleThreadListSync; + THREAD_MEMBER_UPDATE: typeof handlers.handleThreadMemberUpdate; + THREAD_MEMBERS_UPDATE: typeof handlers.handleThreadMembersUpdate; + STAGE_INSTANCE_CREATE: typeof handlers.handleStageInstanceCreate; + STAGE_INSTANCE_UPDATE: typeof handlers.handleStageInstanceUpdate; + STAGE_INSTANCE_DELETE: typeof handlers.handleStageInstanceDelete; + GUILD_BAN_ADD: typeof handlers.handleGuildBanAdd; + GUILD_BAN_REMOVE: typeof handlers.handleGuildBanRemove; + GUILD_CREATE: typeof handlers.handleGuildCreate; + GUILD_LOADED_DD: typeof handlers.handleGuildLoaded; + GUILD_DELETE: typeof handlers.handleGuildDelete; + GUILD_EMOJIS_UPDATE: typeof handlers.handleGuildEmojisUpdate; + GUILD_INTEGRATIONS_UPDATE: typeof handlers.handleGuildIntegrationsUpdate; + GUILD_MEMBER_ADD: typeof handlers.handleGuildMemberAdd; + GUILD_MEMBER_REMOVE: typeof handlers.handleGuildMemberRemove; + GUILD_MEMBER_UPDATE: typeof handlers.handleGuildMemberUpdate; + GUILD_MEMBERS_CHUNK: typeof handlers.handleGuildMembersChunk; + GUILD_ROLE_CREATE: typeof handlers.handleGuildRoleCreate; + GUILD_ROLE_DELETE: typeof handlers.handleGuildRoleDelete; + GUILD_ROLE_UPDATE: typeof handlers.handleGuildRoleUpdate; + GUILD_UPDATE: typeof handlers.handleGuildUpdate; + INTERACTION_CREATE: typeof handlers.handleInteractionCreate; + INVITE_CREATE: typeof handlers.handleInviteCreate; + INVITE_DELETE: typeof handlers.handleInviteCreate; + MESSAGE_CREATE: typeof handlers.handleMessageCreate; + MESSAGE_DELETE_BULK: typeof handlers.handleMessageDeleteBulk; + MESSAGE_DELETE: typeof handlers.handleMessageDelete; + MESSAGE_REACTION_ADD: typeof handlers.handleMessageReactionAdd; + MESSAGE_REACTION_REMOVE_ALL: typeof handlers.handleMessageReactionRemoveAll; + MESSAGE_REACTION_REMOVE_EMOJI: typeof handlers.handleMessageReactionRemoveEmoji; + MESSAGE_REACTION_REMOVE: typeof handlers.handleMessageReactionRemove; + MESSAGE_UPDATE: typeof handlers.handleMessageUpdate; + PRESENCE_UPDATE: typeof handlers.handlePresenceUpdate; + TYPING_START: typeof handlers.handleTypingStart; + USER_UPDATE: typeof handlers.handleUserUpdate; + VOICE_SERVER_UPDATE: typeof handlers.handleVoiceServerUpdate; + VOICE_STATE_UPDATE: typeof handlers.handleVoiceStateUpdate; + WEBHOOKS_UPDATE: typeof handlers.handleWebhooksUpdate; + INTEGRATION_CREATE: typeof handlers.handleIntegrationCreate; + INTEGRATION_UPDATE: typeof handlers.handleIntegrationUpdate; + INTEGRATION_DELETE: typeof handlers.handleIntegrationDelete; } export function createBotGatewayHandlers( @@ -1463,64 +1296,64 @@ export function createBotGatewayHandlers( ): Record any> { return { // misc - READY: options.READY ?? handleReady, + READY: options.READY ?? handlers.handleReady, // channels - CHANNEL_CREATE: options.CHANNEL_CREATE ?? handleChannelCreate, - CHANNEL_DELETE: options.CHANNEL_DELETE ?? handleChannelDelete, - CHANNEL_PINS_UPDATE: options.CHANNEL_PINS_UPDATE ?? handleChannelPinsUpdate, - CHANNEL_UPDATE: options.CHANNEL_UPDATE ?? handleChannelUpdate, - // THREAD_CREATE: options.THREAD_CREATE ?? handleThreadCreate, - // THREAD_UPDATE: options.THREAD_UPDATE ?? handleThreadUpdate, - // THREAD_DELETE: options.THREAD_DELETE ?? handleThreadDelete, - // THREAD_LIST_SYNC: options.THREAD_LIST_SYNC ?? handleThreadListSync, - // THREAD_MEMBER_UPDATE: options.THREAD_MEMBER_UPDATE ?? handleThreadMemberUpdate, - // THREAD_MEMBERS_UPDATE: options.THREAD_MEMBERS_UPDATE ?? handleThreadMembersUpdate, - STAGE_INSTANCE_CREATE: options.STAGE_INSTANCE_CREATE ?? handleStageInstanceCreate, - STAGE_INSTANCE_UPDATE: options.STAGE_INSTANCE_UPDATE ?? handleStageInstanceUpdate, - STAGE_INSTANCE_DELETE: options.STAGE_INSTANCE_DELETE ?? handleStageInstanceDelete, + CHANNEL_CREATE: options.CHANNEL_CREATE ?? handlers.handleChannelCreate, + CHANNEL_DELETE: options.CHANNEL_DELETE ?? handlers.handleChannelDelete, + CHANNEL_PINS_UPDATE: options.CHANNEL_PINS_UPDATE ?? handlers.handleChannelPinsUpdate, + CHANNEL_UPDATE: options.CHANNEL_UPDATE ?? handlers.handleChannelUpdate, + // THREAD_CREATE: options.THREAD_CREATE ?? handlers.handleThreadCreate, + // THREAD_UPDATE: options.THREAD_UPDATE ?? handlers.handleThreadUpdate, + // THREAD_DELETE: options.THREAD_DELETE ?? handlers.handleThreadDelete, + // THREAD_LIST_SYNC: options.THREAD_LIST_SYNC ?? handlers.handleThreadListSync, + // THREAD_MEMBER_UPDATE: options.THREAD_MEMBER_UPDATE ?? handlers.handleThreadMemberUpdate, + // THREAD_MEMBERS_UPDATE: options.THREAD_MEMBERS_UPDATE ?? handlers.handleThreadMembersUpdate, + STAGE_INSTANCE_CREATE: options.STAGE_INSTANCE_CREATE ?? handlers.handleStageInstanceCreate, + STAGE_INSTANCE_UPDATE: options.STAGE_INSTANCE_UPDATE ?? handlers.handleStageInstanceUpdate, + STAGE_INSTANCE_DELETE: options.STAGE_INSTANCE_DELETE ?? handlers.handleStageInstanceDelete, // guilds - GUILD_BAN_ADD: options.GUILD_BAN_ADD ?? handleGuildBanAdd, - GUILD_BAN_REMOVE: options.GUILD_BAN_REMOVE ?? handleGuildBanRemove, - GUILD_CREATE: options.GUILD_CREATE ?? handleGuildCreate, - GUILD_LOADED_DD: options.GUILD_LOADED_DD ?? handleGuildLoaded, - GUILD_DELETE: options.GUILD_DELETE ?? handleGuildDelete, - GUILD_EMOJIS_UPDATE: options.GUILD_EMOJIS_UPDATE ?? handleGuildEmojisUpdate, - GUILD_INTEGRATIONS_UPDATE: options.GUILD_INTEGRATIONS_UPDATE ?? handleGuildIntegrationsUpdate, - GUILD_MEMBER_ADD: options.GUILD_MEMBER_ADD ?? handleGuildMemberAdd, - GUILD_MEMBER_REMOVE: options.GUILD_MEMBER_REMOVE ?? handleGuildMemberRemove, - GUILD_MEMBER_UPDATE: options.GUILD_MEMBER_UPDATE ?? handleGuildMemberUpdate, - GUILD_MEMBERS_CHUNK: options.GUILD_MEMBERS_CHUNK ?? handleGuildMembersChunk, - GUILD_ROLE_CREATE: options.GUILD_ROLE_CREATE ?? handleGuildRoleCreate, - GUILD_ROLE_DELETE: options.GUILD_ROLE_DELETE ?? handleGuildRoleDelete, - GUILD_ROLE_UPDATE: options.GUILD_ROLE_UPDATE ?? handleGuildRoleUpdate, - GUILD_UPDATE: options.GUILD_UPDATE ?? handleGuildUpdate, + GUILD_BAN_ADD: options.GUILD_BAN_ADD ?? handlers.handleGuildBanAdd, + GUILD_BAN_REMOVE: options.GUILD_BAN_REMOVE ?? handlers.handleGuildBanRemove, + GUILD_CREATE: options.GUILD_CREATE ?? handlers.handleGuildCreate, + GUILD_LOADED_DD: options.GUILD_LOADED_DD ?? handlers.handleGuildLoaded, + GUILD_DELETE: options.GUILD_DELETE ?? handlers.handleGuildDelete, + GUILD_EMOJIS_UPDATE: options.GUILD_EMOJIS_UPDATE ?? handlers.handleGuildEmojisUpdate, + GUILD_INTEGRATIONS_UPDATE: options.GUILD_INTEGRATIONS_UPDATE ?? handlers.handleGuildIntegrationsUpdate, + GUILD_MEMBER_ADD: options.GUILD_MEMBER_ADD ?? handlers.handleGuildMemberAdd, + GUILD_MEMBER_REMOVE: options.GUILD_MEMBER_REMOVE ?? handlers.handleGuildMemberRemove, + GUILD_MEMBER_UPDATE: options.GUILD_MEMBER_UPDATE ?? handlers.handleGuildMemberUpdate, + GUILD_MEMBERS_CHUNK: options.GUILD_MEMBERS_CHUNK ?? handlers.handleGuildMembersChunk, + GUILD_ROLE_CREATE: options.GUILD_ROLE_CREATE ?? handlers.handleGuildRoleCreate, + GUILD_ROLE_DELETE: options.GUILD_ROLE_DELETE ?? handlers.handleGuildRoleDelete, + GUILD_ROLE_UPDATE: options.GUILD_ROLE_UPDATE ?? handlers.handleGuildRoleUpdate, + GUILD_UPDATE: options.GUILD_UPDATE ?? handlers.handleGuildUpdate, // interactions - INTERACTION_CREATE: options.INTERACTION_CREATE ?? handleInteractionCreate, + INTERACTION_CREATE: options.INTERACTION_CREATE ?? handlers.handleInteractionCreate, // invites - INVITE_CREATE: options.INVITE_CREATE ?? handleInviteCreate, - INVITE_DELETE: options.INVITE_DELETE ?? handleInviteCreate, + INVITE_CREATE: options.INVITE_CREATE ?? handlers.handleInviteCreate, + INVITE_DELETE: options.INVITE_DELETE ?? handlers.handleInviteCreate, // messages - MESSAGE_CREATE: options.MESSAGE_CREATE ?? handleMessageCreate, - MESSAGE_DELETE_BULK: options.MESSAGE_DELETE_BULK ?? handleMessageDeleteBulk, - MESSAGE_DELETE: options.MESSAGE_DELETE ?? handleMessageDelete, - MESSAGE_REACTION_ADD: options.MESSAGE_REACTION_ADD ?? handleMessageReactionAdd, - MESSAGE_REACTION_REMOVE_ALL: options.MESSAGE_REACTION_REMOVE_ALL ?? handleMessageReactionRemoveAll, - MESSAGE_REACTION_REMOVE_EMOJI: options.MESSAGE_REACTION_REMOVE_EMOJI ?? handleMessageReactionRemoveEmoji, - MESSAGE_REACTION_REMOVE: options.MESSAGE_REACTION_REMOVE ?? handleMessageReactionRemove, - MESSAGE_UPDATE: options.MESSAGE_UPDATE ?? handleMessageUpdate, + MESSAGE_CREATE: options.MESSAGE_CREATE ?? handlers.handleMessageCreate, + MESSAGE_DELETE_BULK: options.MESSAGE_DELETE_BULK ?? handlers.handleMessageDeleteBulk, + MESSAGE_DELETE: options.MESSAGE_DELETE ?? handlers.handleMessageDelete, + MESSAGE_REACTION_ADD: options.MESSAGE_REACTION_ADD ?? handlers.handleMessageReactionAdd, + MESSAGE_REACTION_REMOVE_ALL: options.MESSAGE_REACTION_REMOVE_ALL ?? handlers.handleMessageReactionRemoveAll, + MESSAGE_REACTION_REMOVE_EMOJI: options.MESSAGE_REACTION_REMOVE_EMOJI ?? handlers.handleMessageReactionRemoveEmoji, + MESSAGE_REACTION_REMOVE: options.MESSAGE_REACTION_REMOVE ?? handlers.handleMessageReactionRemove, + MESSAGE_UPDATE: options.MESSAGE_UPDATE ?? handlers.handleMessageUpdate, // presence - PRESENCE_UPDATE: options.PRESENCE_UPDATE ?? handlePresenceUpdate, - TYPING_START: options.TYPING_START ?? handleTypingStart, - USER_UPDATE: options.USER_UPDATE ?? handleUserUpdate, + PRESENCE_UPDATE: options.PRESENCE_UPDATE ?? handlers.handlePresenceUpdate, + TYPING_START: options.TYPING_START ?? handlers.handleTypingStart, + USER_UPDATE: options.USER_UPDATE ?? handlers.handleUserUpdate, // voice - VOICE_SERVER_UPDATE: options.VOICE_SERVER_UPDATE ?? handleVoiceServerUpdate, - VOICE_STATE_UPDATE: options.VOICE_STATE_UPDATE ?? handleVoiceStateUpdate, + VOICE_SERVER_UPDATE: options.VOICE_SERVER_UPDATE ?? handlers.handleVoiceServerUpdate, + VOICE_STATE_UPDATE: options.VOICE_STATE_UPDATE ?? handlers.handleVoiceStateUpdate, // webhooks - WEBHOOKS_UPDATE: options.WEBHOOKS_UPDATE ?? handleWebhooksUpdate, + WEBHOOKS_UPDATE: options.WEBHOOKS_UPDATE ?? handlers.handleWebhooksUpdate, // integrations - INTEGRATION_CREATE: options.INTEGRATION_CREATE ?? handleIntegrationCreate, - INTEGRATION_UPDATE: options.INTEGRATION_UPDATE ?? handleIntegrationUpdate, - INTEGRATION_DELETE: options.INTEGRATION_DELETE ?? handleIntegrationDelete, + INTEGRATION_CREATE: options.INTEGRATION_CREATE ?? handlers.handleIntegrationCreate, + INTEGRATION_UPDATE: options.INTEGRATION_UPDATE ?? handlers.handleIntegrationUpdate, + INTEGRATION_DELETE: options.INTEGRATION_DELETE ?? handlers.handleIntegrationDelete, }; } diff --git a/src/cache.ts b/src/cache.ts index b548a58e8..897a04897 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -1,45 +1,191 @@ import { Bot } from "./bot.ts"; import type { DiscordenoChannel } from "./transformers/channel.ts"; import type { DiscordenoGuild } from "./transformers/guild.ts"; -import type { DiscordenoMember } from "./transformers/member.ts"; +import type { DiscordenoMember, DiscordenoUser } from "./transformers/member.ts"; import type { DiscordenoMessage } from "./transformers/message.ts"; +import { PresenceUpdate } from "./types/activity/presence_update.ts"; +import { Channel } from "./types/channels/channel.ts"; +import { Message } from "./types/messages/message.ts"; +import { Collection } from "./util/collection.ts"; -function messageSweeper(bot: Bot, message: DiscordenoMessage) { - // DM messages aren't needed - if (!message.guildId) return true; +export function createCache( + isAsync: true, + // deno-lint-ignore no-explicit-any + tableCreator: (tableName: TableNames) => AsyncCacheHandler +): AsyncCache; +export function createCache( + isAsync: false, + // deno-lint-ignore no-explicit-any + tableCreator?: (tableName: TableNames) => CacheHandler +): Cache; +export function createCache( + isAsync: boolean, + tableCreator?: ( + tableName: TableNames + // deno-lint-ignore no-explicit-any + ) => CacheHandler | AsyncCacheHandler +): Omit | Omit { + if (isAsync) { + if (!tableCreator) { + throw new Error("Async cache requires a tableCreator to be passed."); + } - // Only delete messages older than 10 minutes - return Date.now() - message.timestamp > 600000; -} - -function memberSweeper(bot: Bot, member: DiscordenoMember) { - // Don't sweep the bot else strange things will happen - if (member.id === bot.id) return false; - - // Only sweep members who were not active the last 30 minutes - return Date.now() - member.cachedAt > 1800000; -} - -async function guildSweeper(bot: Bot, guild: DiscordenoGuild) { - // Reset activity for next interval - if (await bot.cache.activeGuildIds.delete(guild.id)) return false; - - // This is inactive guild. Not a single thing has happened for atleast 30 minutes. - // Not a reaction, not a message, not any event! - await bot.cache.dispatchedGuildIds.set(guild.id); - - return true; -} - -async function channelSweeper(bot: Bot, channel: DiscordenoChannel, key: bigint) { - // If this is in a guild and the guild was dispatched, then we can dispatch the channel - if (channel.guildId && (await bot.cache.dispatchedGuildIds.has(channel.guildId))) { - await bot.cache.dispatchedChannelIds.set(channel.id); - return true; + return { + guilds: tableCreator("guilds"), + users: tableCreator("users"), + channels: tableCreator("channels"), + messages: tableCreator("messages"), + presences: tableCreator("presences"), + // threads: tableCreator("threads"), + unavailableGuilds: tableCreator("unavailableGuilds"), + executedSlashCommands: new Set(), + } as AsyncCache; } + if (!tableCreator) tableCreator = createTable; - // THE KEY DM CHANNELS ARE STORED BY IS THE USER ID. If the user is not cached, we dont need to cache their dm channel. - if (!channel.guildId && !(await bot.cache.members.has(key))) return true; - - return false; + return { + guilds: tableCreator("guilds"), + users: tableCreator("users"), + channels: tableCreator("channels"), + messages: tableCreator("messages"), + presences: tableCreator("presences"), + // threads: tableCreator("threads"), + unavailableGuilds: tableCreator("unavailableGuilds"), + executedSlashCommands: new Set(), + } as Cache; } + +export interface Cache { + guilds: CacheHandler; + users: CacheHandler; + channels: CacheHandler; + messages: CacheHandler; + presences: CacheHandler; + // threads: CacheHandler; + unavailableGuilds: CacheHandler; + executedSlashCommands: Set; + execute: CacheExecutor; +} + +export interface CachedUnavailableGuild { + shardId: number; + since: number; + dispatched?: true; +} + +export interface AsyncCache { + guilds: AsyncCacheHandler; + users: AsyncCacheHandler; + channels: AsyncCacheHandler; + messages: AsyncCacheHandler; + presences: AsyncCacheHandler; + // threads: AsyncCacheHandler; + unavailableGuilds: AsyncCacheHandler; + executedSlashCommands: Set; + execute: CacheExecutor; +} + +function createTable(_table: TableNames): CacheHandler { + const table = new Collection(); + return { + clear: () => table.clear(), + delete: (key) => table.delete(key), + has: (key) => table.has(key), + size: () => table.size, + set: (key, data) => !!table.set(key, data), + get: (key) => table.get(key), + forEach: (callback) => table.forEach(callback), + filter: (callback) => table.filter(callback), + }; +} + +export interface CacheHandler { + /** Completely empty this table. */ + clear(): void; + /** Delete the data related to this key from table. */ + delete(key: BigInt): boolean; + /** Check if there is data assigned to this key. */ + has(key: BigInt): boolean; + /** Check how many items are stored in this table. */ + size(): number; + /** Store new data to this table. */ + set(key: BigInt, data: T): boolean; + /** Get a stored item from the table. */ + get(key: BigInt): T | undefined; + // TODO: maybe its possible to stringify the function and send it to the custom cache handler :thinking: + /** + * Loop over each entry and execute callback function. + * @important This function NOT optimised and will force load everything when using custom cache. + */ + forEach(callback: (value: T, key: BigInt) => unknown): void; + // TODO: maybe its possible to stringify the function and send it to the custom cache handler :thinking: + /** + * Loop over each entry and execute callback function. + * @important This function NOT optimised and will force load everything when using custom cache. + */ + filter(callback: (value: T, key: BigInt) => boolean): Collection; +} + +export type AsyncCacheHandler = { + [K in keyof CacheHandler]: (...args: Parameters[K]>) => Promise[K]>>; +}; + +export interface CacheExecutor { + (type: "DELETE_MESSAGES_FROM_CHANNEL", options: { channelId: bigint }): Promise; +} + +export function createExecute(cache: Cache | AsyncCache): CacheExecutor { + return async (type, options) => { + if (type === "DELETE_MESSAGES_FROM_CHANNEL") { + await cache.messages.forEach(async (message) => { + if (BigInt(message.channelId) === options.channelId) { + await cache.messages.delete(BigInt(message.id)); + } + }); + + return undefined; + } + }; +} + +export type TableNames = "channels" | "users" | "guilds" | "messages" | "presences" | "threads" | "unavailableGuilds"; + +// function messageSweeper(bot: Bot, message: DiscordenoMessage) { +// // DM messages aren't needed +// if (!message.guildId) return true; + +// // Only delete messages older than 10 minutes +// return Date.now() - message.timestamp > 600000; +// } + +// function memberSweeper(bot: Bot, member: DiscordenoMember) { +// // Don't sweep the bot else strange things will happen +// if (member.id === bot.id) return false; + +// // Only sweep members who were not active the last 30 minutes +// return Date.now() - member.cachedAt > 1800000; +// } + +// async function guildSweeper(bot: Bot, guild: DiscordenoGuild) { +// // Reset activity for next interval +// if (await bot.cache.activeGuildIds.delete(guild.id)) return false; + +// // This is inactive guild. Not a single thing has happened for atleast 30 minutes. +// // Not a reaction, not a message, not any event! +// await bot.cache.dispatchedGuildIds.set(guild.id); + +// return true; +// } + +// async function channelSweeper(bot: Bot, channel: DiscordenoChannel, key: bigint) { +// // If this is in a guild and the guild was dispatched, then we can dispatch the channel +// if (channel.guildId && (await bot.cache.dispatchedGuildIds.has(channel.guildId))) { +// await bot.cache.dispatchedChannelIds.set(channel.id); +// return true; +// } + +// // THE KEY DM CHANNELS ARE STORED BY IS THE USER ID. If the user is not cached, we dont need to cache their dm channel. +// if (!channel.guildId && !(await bot.cache.members.has(key))) return true; + +// return false; +// }