diff --git a/lib/rest/endpoints.ts b/lib/rest/endpoints.ts index ffeb69f5..13032821 100644 --- a/lib/rest/endpoints.ts +++ b/lib/rest/endpoints.ts @@ -31,6 +31,7 @@ export const MEMBER_NICKNAME = (guildID: string, memberID: string) => `/servers/ export const GUILD_MEMBER = (guildID: string, memberID: string) => `/servers/${guildID}/members/${memberID}`; export const GUILD_MEMBER_PERMISSION = (guildID: string, memberID: string) => `/servers/${guildID}/members/${memberID}/permissions`; export const GUILD_MEMBER_XP = (guildID: string, memberID: string) => `/servers/${guildID}/members/${memberID}/xp`; +export const GUILD_MEMBER_BULK_XP = (guildID: string) => `/servers/${guildID}/xp`; export const GUILD_MEMBERS = (guildID: string) => `/servers/${guildID}/members`; export const GUILD_MEMBER_SOCIALS = (guildID: string, memberID: string, type: string) => `/servers/${guildID}/members/${memberID}/social-links/${type}`; @@ -92,3 +93,6 @@ export const CHANNEL_EVENT_EVENT_SERIES_ENTITY = (channelID: string, seriesID: s export const GUILD_WEBHOOKS = (guildID: string)=> `/servers/${guildID}/webhooks`; export const GUILD_WEBHOOK = (guildID: string, webhookID: string)=> `/servers/${guildID}/webhooks/${webhookID}`; + +export const GUILD_CATEGORY_CREATE = (guildID: string) => `/servers/${guildID}/categories`; +export const GUILD_CATEGORY = (guildID: string, categoryID: number) => `/servers/${guildID}/categories/${categoryID}`; diff --git a/lib/routes/Guilds.ts b/lib/routes/Guilds.ts index dc64c7b5..53df649a 100644 --- a/lib/routes/Guilds.ts +++ b/lib/routes/Guilds.ts @@ -40,7 +40,17 @@ import { GETGuildSubscriptionResponse, GETGuildMemberPermissionResponse, Permissions, - PATCHGuildRoleUpdateResponse + PATCHGuildRoleUpdateResponse, + POSTBulkAwardXPBody, + POSTBulkAwardXPResponse, + PUTBulkSetXPBody, + PUTBulkSetXPResponse, + POSTCreateCategoryBody, + POSTCreateCategoryResponse, + GETReadCategoryResponse, + PATCHUpdateCategoryBody, + PATCHUpdateCategoryResponse, + DELETEDeleteCategoryResponse } from "../Constants"; import { AnyChannel, CreateChannelOptions, EditChannelOptions } from "../types/channel"; import { EditWebhookOptions } from "../types/webhooks"; @@ -49,6 +59,7 @@ import { BannedMember } from "../structures/BannedMember"; import { GuildRole } from "../structures/GuildRole"; import { GuildGroup } from "../structures/GuildGroup"; import { GuildSubscription } from "../structures/GuildSubscription"; +import { GuildCategory } from "../structures/GuildCategory"; export class Guilds { #manager: RESTManager; @@ -550,4 +561,80 @@ export class Guilds { json: options }).then(data => this.#manager.client.util.updateRole(data.role)); } + + /** + * Bulk Award XP Members + * @param guildID ID of the guild + * @param options Members to award XP + */ + async bulkAwardXP(guildID: string, options: POSTBulkAwardXPBody): Promise { + return this.#manager.authRequest({ + method: "POST", + path: endpoints.GUILD_MEMBER_BULK_XP(guildID), + json: options + }).then(data => data); + } + + /** + * Bulk Set XP Members + * @param guildID ID of the guild + * @param options Members to set XP + */ + async bulkSetXP(guildID: string, options: PUTBulkSetXPBody): Promise { + return this.#manager.authRequest({ + method: "PUT", + path: endpoints.GUILD_MEMBER_BULK_XP(guildID), + json: options + }).then(data => data); + } + + /** + * Create a guild category. + * @param guildID ID of the guild to create a category in. + * @param options Options to create a category. + */ + async createCategory(guildID: string, options: POSTCreateCategoryBody): Promise { + return this.#manager.authRequest({ + method: "POST", + path: endpoints.GUILD_CATEGORY_CREATE(guildID), + json: options + }).then(data => this.#manager.client.util.updateGuildCategory(data.category)); + } + /** + * Read a guild category. + * @param guildID ID of the guild to create a category in. + * @param categoryID ID of the category you want to read. + */ + async readCategory(guildID: string, categoryID: number): Promise { + return this.#manager.authRequest({ + method: "GET", + path: endpoints.GUILD_CATEGORY(guildID, categoryID) + }).then(data => this.#manager.client.util.updateGuildCategory(data.category)); + } + + /** + * Update a guild category. + * @param guildID ID of the guild to create a category in. + * @param categoryID ID of the category you want to read. + * @param options Options to update a category. + */ + async updateCategory(guildID: string, categoryID: number, options: PATCHUpdateCategoryBody): Promise { + return this.#manager.authRequest({ + method: "PATCH", + path: endpoints.GUILD_CATEGORY(guildID, categoryID), + json: options + }).then(data => this.#manager.client.util.updateGuildCategory(data.category)); + } + + /** + * Delete a guild category. + * @param guildID ID of the guild to create a category in. + * @param categoryID ID of the category you want to read. + */ + async deleteCategory(guildID: string, categoryID: number): Promise { + return this.#manager.authRequest({ + method: "DELETE", + path: endpoints.GUILD_CATEGORY(guildID, categoryID) + }).then(data => this.#manager.client.util.updateGuildCategory(data.category)); + } } diff --git a/lib/structures/Client.ts b/lib/structures/Client.ts index bded8206..59d70227 100644 --- a/lib/structures/Client.ts +++ b/lib/structures/Client.ts @@ -26,6 +26,7 @@ import { Announcement } from "./Announcement"; import { GuildRole } from "./GuildRole"; import { GuildGroup } from "./GuildGroup"; import { GuildSubscription } from "./GuildSubscription"; +import { GuildCategory } from "./GuildCategory"; import { WSManager } from "../gateway/WSManager"; import { GatewayHandler } from "../gateway/GatewayHandler"; import { RESTManager } from "../rest/RESTManager"; @@ -56,7 +57,13 @@ import { PATCHGuildGroupBody, POSTGuildRoleBody, PATCHGuildRoleBody, - Permissions + Permissions, + POSTBulkAwardXPBody, + POSTBulkAwardXPResponse, + PUTBulkSetXPBody, + PUTBulkSetXPResponse, + POSTCreateCategoryBody, + PATCHUpdateCategoryBody } from "../Constants"; import { AnyChannel, @@ -1249,4 +1256,57 @@ export class Client extends TypedEmitter { async unpinMessage(channelID: string, messageID: string): Promise { return this.rest.channels.unpinMessage(channelID, messageID); } + + /** + * Bulk XP Awards Members. + * @param guildID ID of the guild. + * @param options Bulk XP options. + */ + async bulkAwardXPMembers(guildID: string, options: POSTBulkAwardXPBody): Promise { + return this.rest.guilds.bulkAwardXP(guildID, options); + } + + /** + * Bulk XP Set Members. + * @param guildID ID of the guild. + * @param options Bulk XP options. + */ + async bulkSetMembersXP(guildID: string, options: PUTBulkSetXPBody): Promise { + return this.rest.guilds.bulkSetXP(guildID, options); + } + + /** + * Create a guild category + * @param guildID ID of the guild. + * @param options Create options. + */ + async createGuildCategory(guildID: string, options: POSTCreateCategoryBody): Promise { + return this.rest.guilds.createCategory(guildID, options); + } + /** + * Read a guild category. + * @param guildID ID of the guild to create a category in. + * @param categoryID ID of the category you want to read. + */ + async getGuildCategory(guildID: string, categoryID: number): Promise { + return this.rest.guilds.readCategory(guildID, categoryID); + } + /** + * Update a guild category. + * @param guildID ID of the guild to create a category in. + * @param categoryID ID of the category you want to read. + * @param options Options to update a category. + */ + async updateGuildCategory(guildID: string, categoryID: number, options: PATCHUpdateCategoryBody): Promise { + return this.rest.guilds.updateCategory(guildID, categoryID, options); + } + + /** + * Delete a guild category. + * @param guildID ID of the guild to create a category in. + * @param categoryID ID of the category you want to read. + */ + async deleteGuildCategory(guildID: string, categoryID: number): Promise { + return this.rest.guilds.deleteCategory(guildID, categoryID); + } } diff --git a/lib/structures/Guild.ts b/lib/structures/Guild.ts index e619e3ce..d332b60a 100644 --- a/lib/structures/Guild.ts +++ b/lib/structures/Guild.ts @@ -9,12 +9,17 @@ import { GuildSubscription } from "./GuildSubscription"; import { GuildChannel } from "./GuildChannel"; import { GuildGroup } from "./GuildGroup"; import { GuildRole } from "./GuildRole"; +import { GuildCategory } from "./GuildCategory"; import { APIGuild, APIGuildChannel, APIGuildGroup, APIGuildMember, - APIGuildRole + APIGuildRole, + POSTBulkAwardXPBody, + POSTBulkAwardXPResponse, + POSTCreateCategoryBody, + PATCHUpdateCategoryBody } from "../Constants"; import TypedCollection from "../util/TypedCollection"; import { JSONGuild } from "../types/json"; @@ -183,4 +188,53 @@ export class Guild extends Base { async getSubscriptions(): Promise> { return this.client.rest.guilds.getSubscriptions(this.id as string); } + + /** Bulk Award XP Members + * @param options Members to award XP and amount of XP to award. + */ + async bulkAwardXPMembers(options: POSTBulkAwardXPBody): Promise { + return this.client.rest.guilds.bulkAwardXP(this.id as string, options); + } + + /** Bulk SEt XP Members + * @param options Members to set XP and amount of XP to set. + */ + async bulkSetXPMembers(options: POSTBulkAwardXPBody): Promise { + return this.client.rest.guilds.bulkSetXP(this.id as string, options); + } + + /** + * Create a guild category + * @param guildID ID of the guild. + * @param options Create options. + */ + async createCategory(options: POSTCreateCategoryBody): Promise { + return this.client.rest.guilds.createCategory(this.id as string, options); + } + /** + * Read a guild category. + * @param guildID ID of the guild to create a category in. + * @param categoryID ID of the category you want to read. + */ + async getCategory(categoryID: number): Promise { + return this.client.rest.guilds.readCategory(this.id as string, categoryID); + } + /** + * Update a guild category. + * @param guildID ID of the guild to create a category in. + * @param categoryID ID of the category you want to read. + * @param options Options to update a category. + */ + async updateCategory(categoryID: number, options: PATCHUpdateCategoryBody): Promise { + return this.client.rest.guilds.updateCategory(this.id as string, categoryID, options); + } + + /** + * Delete a guild category. + * @param guildID ID of the guild to create a category in. + * @param categoryID ID of the category you want to read. + */ + async deleteCategory(categoryID: number): Promise { + return this.client.rest.guilds.deleteCategory(this.id as string, categoryID); + } } diff --git a/lib/structures/GuildCategory.ts b/lib/structures/GuildCategory.ts new file mode 100644 index 00000000..6752633b --- /dev/null +++ b/lib/structures/GuildCategory.ts @@ -0,0 +1,86 @@ +/** @module GuildCategory */ + +import { Client } from "./Client"; +import { Base } from "./Base"; +import { JSONGuildCategory } from "../types/json"; +import { PATCHUpdateCategoryBody } from "../Constants"; +import { APIGuildCategory } from "guildedapi-types.ts/v1"; + +/** Class representing a guild group. */ +export class GuildCategory extends Base { + /** Type of the subscription */ + override id: number; + /** The ID of the server */ + serverId: string; + /** The ID of the group */ + groupId: string; + /** The ISO 8601 timestamp that the category was created at */ + createdAt: Date; + /** The ISO 8601 timestamp that the category was updated at, if relevant */ + updatedAt?: Date | null; + /** Name of the category (min length 1; max length 100) */ + name: string; + + constructor(data: APIGuildCategory, client: Client) { + super(data.id, client); + this.id = data.id; + this.serverId = data.serverId; + this.groupId = data.groupId; + this.createdAt = new Date(data.createdAt); + this.updatedAt = data.updatedAt ?? null; + this.name = data.name; + this.update(data); + } + + override toJSON(): JSONGuildCategory { + return { + ...super.toJSON(), + id: this.id, + serverId: this.serverId, + groupId: this.groupId, + createdAt: this.createdAt, + updatedAt: this.updatedAt ?? null, + name: this.name + }; + } + + protected override update(data: APIGuildCategory): void { + if (data.id !== undefined) { + this.id = data.id; + } + if (data.serverId !== undefined) { + this.serverId = data.serverId; + } + if (data.groupId !== undefined) { + this.groupId = data.groupId; + } + if (data.createdAt !== undefined) { + this.createdAt = new Date(data.createdAt); + } + if (data.updatedAt !== undefined) { + this.updatedAt = data.updatedAt ?? null; + } + if (data.name !== undefined) { + this.name = data.name; + } + } + + /** + * Update a guild category. + * @param guildID ID of the guild to create a category in. + * @param categoryID ID of the category you want to read. + * @param options Options to update a category. + */ + async updateCategory(options: PATCHUpdateCategoryBody): Promise { + return this.client.rest.guilds.updateCategory(this.serverId as string, this.id as number, options); + } + + /** + * Delete a guild category. + * @param guildID ID of the guild to create a category in. + * @param categoryID ID of the category you want to read. + */ + async deleteCategory(): Promise { + return this.client.rest.guilds.deleteCategory(this.serverId as string, this.id as number); + } +} diff --git a/lib/types/json.d.ts b/lib/types/json.d.ts index 25cfa859..83832f3b 100644 --- a/lib/types/json.d.ts +++ b/lib/types/json.d.ts @@ -512,3 +512,18 @@ export interface JSONGuildSubscription extends JSONBase { createdAt: Date; } +export interface JSONGuildCategory extends JSONBase { + /** Type of the subscription */ + id: number; + /** ID of the guild */ + serverId: string; + /** ID of the group */ + groupId: string; + /** The ISO 8601 timestamp that the group was created at */ + createdAt: Date; + /** The ISO 8601 timestamp that the category was updated at, if relevant */ + updatedAt: Date | null; + /** Name of the category (min length 1; max length 100) */ + name: string; +} + diff --git a/lib/util/Util.ts b/lib/util/Util.ts index be3dca9b..b7fea197 100644 --- a/lib/util/Util.ts +++ b/lib/util/Util.ts @@ -11,6 +11,7 @@ import { User } from "../structures/User"; import { GuildRole } from "../structures/GuildRole"; import { GuildGroup } from "../structures/GuildGroup"; import { GuildSubscription } from "../structures/GuildSubscription"; +import { GuildCategory } from "../structures/GuildCategory"; import { APIForumTopic, APIForumTopicSummary, @@ -20,7 +21,8 @@ import { APIGuildMember, APIGuildRole, APIGuildSubscription, - APIUser + APIUser, + APIGuildCategory } from "guildedapi-types.ts/v1"; export class Util { @@ -101,6 +103,10 @@ export class Util { updateGuildSubscription(data: APIGuildSubscription): GuildSubscription { return new GuildSubscription(data, this.#client); } + + updateGuildCategory(data: APIGuildCategory): GuildCategory { + return new GuildCategory(data, this.#client); + } } export function is(input: unknown): input is T { diff --git a/package.json b/package.json index ea418f57..4268ad9d 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "typescript": "^4.9.4" }, "dependencies": { - "guildedapi-types.ts": "0.3.34", + "guildedapi-types.ts": "0.3.36", "undici": "^5.14.0", "ws": "^8.11.0" },