From 1cafdbdcc80c99c24d7181c9f37f8f2ef1beab0f Mon Sep 17 00:00:00 2001 From: "Jaron (aider)" Date: Sat, 15 Feb 2025 11:57:07 -0600 Subject: [PATCH] feat: Add Channels cache to Client with ObjectCache implementation --- src/services/caches/channels.ts | 10 ++++++++++ src/services/client.ts | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/services/caches/channels.ts diff --git a/src/services/caches/channels.ts b/src/services/caches/channels.ts new file mode 100644 index 0000000..bd731c0 --- /dev/null +++ b/src/services/caches/channels.ts @@ -0,0 +1,10 @@ +import { API } from "../api"; +import { Processor } from "../processor"; +import { Channel } from "../../types/channel"; +import { ObjectCache } from "./cache"; + +export class Channels extends ObjectCache { + constructor(api: API, processor: Processor) { + super(api, processor, 'channels', Channel, ['CHANNEL_CREATE', 'CHANNEL_UPDATE']); + } +} diff --git a/src/services/client.ts b/src/services/client.ts index 9fe5886..e84fbcb 100644 --- a/src/services/client.ts +++ b/src/services/client.ts @@ -6,6 +6,7 @@ import { exists, isNil } from '../utils/index'; import { type DiscordMessage, Message } from '../types/message'; import { Guilds } from './caches/guilds'; import { Messages } from './caches/messages'; +import { Channels } from './caches/channels'; import { Users } from './caches/users'; import { hydrate, hydrator, type Hydrateable, type Hydrated } from './hydrator'; import { EventBus, type Emitter } from './bus'; @@ -23,6 +24,7 @@ export class Client { guilds: Guilds; users: Users; messages: Messages; + channels: Channels; chatCommands: Processor[HandlerType.ChatCommands]; applicationCommands: Processor[HandlerType.ApplicationCommands]; interactions: Processor[HandlerType.Interactions]; @@ -43,6 +45,7 @@ export class Client { this.guilds = new Guilds(this.api, this.processor); this.users = new Users(this.api, this.processor); this.messages = new Messages(this, this.api, this.processor); + this.channels = new Channels(this.api, this.processor); // Save references to command and event handlers this.chatCommands = this.processor[HandlerType.ChatCommands]; this.applicationCommands = this.processor[HandlerType.ApplicationCommands]; @@ -138,4 +141,4 @@ export class Client { off = (event: string, handler: (...args: any[]) => void) => this.bus.off(event, handler); connect = () => this.gateway.connect(); -} \ No newline at end of file +}