From 72f2ba3c88a12f14944e8709e05f106a898f89d7 Mon Sep 17 00:00:00 2001 From: zaida04 Date: Sun, 13 Aug 2023 19:08:30 -0400 Subject: [PATCH] fix: add category manager to client and shortcut methods --- .../lib/managers/global/CategoryManager.ts | 2 +- .../guilded.js/lib/structures/Category.ts | 43 +++++++++++++++++++ packages/guilded.js/lib/structures/Client.ts | 6 +++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/packages/guilded.js/lib/managers/global/CategoryManager.ts b/packages/guilded.js/lib/managers/global/CategoryManager.ts index ced327c7..6d06b5fd 100644 --- a/packages/guilded.js/lib/managers/global/CategoryManager.ts +++ b/packages/guilded.js/lib/managers/global/CategoryManager.ts @@ -6,7 +6,7 @@ import { CacheableStructManager } from "./CacheableStructManager"; /** * Manager for interacting with Catregories on Guilded. */ -export class CategoryManager extends CacheableStructManager { +export class GlobalCategoryManager extends CacheableStructManager { /** * Create a new category * diff --git a/packages/guilded.js/lib/structures/Category.ts b/packages/guilded.js/lib/structures/Category.ts index 3624d369..6db04c4a 100644 --- a/packages/guilded.js/lib/structures/Category.ts +++ b/packages/guilded.js/lib/structures/Category.ts @@ -1,17 +1,23 @@ import type { CategoryPayload } from "@guildedjs/api"; +import type { GlobalCategoryManager } from "../managers/global/CategoryManager"; import { parseToStamp } from "../util"; import { Base } from "./Base"; import type { Client } from "./Client"; export class Category extends Base { + /** The ID of the server this category is in. */ serverId: string; + /** The name of this category. */ name!: string; + /** The timestamp of when this category was created. */ _createdAt: number; + /** The ID of the group this category is in. */ groupId: string; + /** The timestamp of when this category was last updated. */ _updatedAt!: number | null; constructor(client: Client, data: CategoryPayload) { @@ -29,4 +35,41 @@ export class Category extends Base { return this; } + + /** + * Gets the creation date of this category. + * + * @returns The creation date of this category. + */ + get createdAt(): Date { + return new Date(this._createdAt); + } + + /** + * Gets the last time this category was updated. + * + * @returns The last time this category was updated. + */ + get updatedAt(): Date | null { + return this._updatedAt ? new Date(this._updatedAt) : null; + } + + /** + * Updates this webhook with new options + * + * @param options The new options for this webhook + * @returns A promise that resolves with the updated webhook + */ + update(options: Parameters[2]): Promise { + return this.client.categories.update(this.serverId, this.id, options); + } + + /** + * Delete this category. + * + * @returns A Promise that resolves with the updated category. + */ + async delete(): Promise { + return this.client.categories.delete(this.serverId, this.id); + } } diff --git a/packages/guilded.js/lib/structures/Client.ts b/packages/guilded.js/lib/structures/Client.ts index ce04ebbe..2f8dd104 100644 --- a/packages/guilded.js/lib/structures/Client.ts +++ b/packages/guilded.js/lib/structures/Client.ts @@ -6,6 +6,7 @@ import type TypedEmitter from "typed-emitter"; import type { CacheStructure } from "../cache"; import { ClientGatewayHandler } from "../gateway/ClientGatewayHandler"; import { GlobalCalendarManager } from "../managers/global/CalendarManager"; +import { GlobalCategoryManager } from "../managers/global/CategoryManager"; import { GlobalChannelManager } from "../managers/global/ChannelManager"; import { GlobalDocManager } from "../managers/global/DocManager"; import { GlobalForumTopicManager } from "../managers/global/ForumManager"; @@ -123,6 +124,11 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter