diff --git a/lib/Constants.ts b/lib/Constants.ts index d38238d7..25b3d71d 100644 --- a/lib/Constants.ts +++ b/lib/Constants.ts @@ -13,7 +13,8 @@ export const RESTMethods = [ ] as const; export type RESTMethod = typeof RESTMethods[number]; -export type UserTypes = "bot" | "user"; +export type UserTypes = "app" | "user"; +export type RawUserTypes = "bot" | "user"; export * from "guildedapi-types.ts/v1"; // marks api typings as non-external (for docs). diff --git a/lib/gateway/WSManager.ts b/lib/gateway/WSManager.ts index 095e7dc7..896e4589 100644 --- a/lib/gateway/WSManager.ts +++ b/lib/gateway/WSManager.ts @@ -7,8 +7,8 @@ import GatewayError from "./GatewayError"; import { Client } from "../structures/Client"; -import { APIBotUser, GatewayOPCodes } from "../Constants"; -import { WebsocketEvents, AnyPacket, WelcomePacket } from "../types"; +import { GatewayOPCodes } from "../Constants"; +import { WebsocketEvents, AnyPacket, WelcomePacket, RawAppUser } from "../types"; import { config as pkgconfig } from "../../pkgconfig"; import { is } from "../util/Util"; import TypedEmitter from "../types/TypedEmitter"; @@ -261,7 +261,7 @@ export class WSManager extends TypedEmitter { this.heartbeat(), packet.d["heartbeatIntervalMs" as keyof object] as number ); - this.emit("GATEWAY_WELCOME", packet.d["user" as keyof object] as APIBotUser); + this.emit("GATEWAY_WELCOME", packet.d["user" as keyof object] as RawAppUser); this.emit("GATEWAY_WELCOME_PACKET", packet as WelcomePacket); this.connected = true; break; diff --git a/lib/gateway/events/CalendarHandler.ts b/lib/gateway/events/CalendarHandler.ts index 4724f020..4c576e98 100644 --- a/lib/gateway/events/CalendarHandler.ts +++ b/lib/gateway/events/CalendarHandler.ts @@ -25,7 +25,7 @@ import { } from "../../Constants"; import { CalendarChannel } from "../../structures/CalendarChannel"; import { CalendarReactionInfo } from "../../structures/CalendarReactionInfo"; -import { CalendarEventComment } from "../../structures/CalendarEventComment"; +import { CalendarComment } from "../../structures/CalendarComment"; /** Internal component, emitting calendar events. */ export class CalendarHandler extends GatewayEventHandler { @@ -114,14 +114,14 @@ export class CalendarHandler extends GatewayEventHandler { ); const CalendarEventComponent = channel?.scheduledEvents.get(Number(data.calendarEventComment.calendarEventId)); - const CalendarComment = + const calendarComment = CalendarEventComponent?.comments.update(data.calendarEventComment) - ?? new CalendarEventComment( + ?? new CalendarComment( data.calendarEventComment, this.client, { guildID: data.serverId } ); - this.client.emit("calendarCommentCreate", CalendarComment); + this.client.emit("calendarCommentCreate", calendarComment); } async calendarCommentUpdate(data: GatewayEvent_CalendarEventCommentUpdated): Promise { @@ -145,14 +145,14 @@ export class CalendarHandler extends GatewayEventHandler { channel?.scheduledEvents.get(Number(data.calendarEventComment.calendarEventId)); const CachedComment = CalendarEventComponent?.comments.get(data.calendarEventComment.id)?.toJSON() ?? null; - const CalendarComment = + const calendarComment = CalendarEventComponent?.comments.update(data.calendarEventComment) - ?? new CalendarEventComment( + ?? new CalendarComment( data.calendarEventComment, this.client, { guildID: data.serverId } ); - this.client.emit("calendarCommentUpdate", CalendarComment, CachedComment); + this.client.emit("calendarCommentUpdate", calendarComment, CachedComment); } async calendarCommentDelete(data: GatewayEvent_CalendarEventCommentDeleted): Promise { @@ -174,15 +174,15 @@ export class CalendarHandler extends GatewayEventHandler { ); const CalendarEventComponent = channel?.scheduledEvents.get(Number(data.calendarEventComment.calendarEventId)); - const CalendarComment = + const calendarComment = CalendarEventComponent?.comments.update(data.calendarEventComment) - ?? new CalendarEventComment( + ?? new CalendarComment( data.calendarEventComment, this.client, { guildID: data.serverId } ); CalendarEventComponent?.comments.delete(data.calendarEventComment.id); - this.client.emit("calendarCommentDelete", CalendarComment); + this.client.emit("calendarCommentDelete", calendarComment); } async calendarCommentReactionAdd(data: GatewayEvent_CalendarEventCommentReactionCreated): Promise { diff --git a/lib/gateway/events/GuildHandler.ts b/lib/gateway/events/GuildHandler.ts index bf46eb66..dda1e470 100644 --- a/lib/gateway/events/GuildHandler.ts +++ b/lib/gateway/events/GuildHandler.ts @@ -7,7 +7,7 @@ import { GatewayEventHandler } from "./GatewayEventHandler"; -import { BannedMember, Guild, GuildRole, Member } from "../../index"; +import { BannedMember, Guild, Role, Member } from "../../index"; import { GuildCreateInfo, GuildDeleteInfo } from "../../types"; import { @@ -32,8 +32,8 @@ import { } from "../../Constants"; import { MemberUpdateInfo } from "../../structures/MemberUpdateInfo"; import { MemberRemoveInfo } from "../../structures/MemberRemoveInfo"; -import { GuildGroup } from "../../structures/GuildGroup"; -import { GuildCategory } from "../../structures/GuildCategory"; +import { Group } from "../../structures/Group"; +import { Category } from "../../structures/Category"; /** Internal component, emitting guild events. */ export class GuildHandler extends GatewayEventHandler { @@ -112,7 +112,7 @@ export class GuildHandler extends GatewayEventHandler { } guildGroupCreate(data: GatewayEvent_GroupCreated): void { - const GuildGroupComponent = new GuildGroup(data.group, this.client); + const GuildGroupComponent = new Group(data.group, this.client); this.client.guilds.get(data.serverId)?.groups.add(GuildGroupComponent); this.client.emit("guildGroupCreate", GuildGroupComponent); } @@ -121,24 +121,24 @@ export class GuildHandler extends GatewayEventHandler { const guild = this.client.guilds.get(data.serverId); const CachedGroup = guild?.groups.get(data.group.id)?.toJSON() ?? null; const GuildGroupComponent = - guild?.groups.update(new GuildGroup(data.group, this.client)) - ?? new GuildGroup(data.group, this.client); + guild?.groups.update(new Group(data.group, this.client)) + ?? new Group(data.group, this.client); this.client.emit("guildGroupUpdate", GuildGroupComponent, CachedGroup); } guildGroupDelete(data: GatewayEvent_GroupDeleted): void { const guild = this.client.guilds.get(data.serverId); const GuildGroupComponent = - guild?.groups.update(new GuildGroup(data.group, this.client)) - ?? new GuildGroup(data.group, this.client); + guild?.groups.update(new Group(data.group, this.client)) + ?? new Group(data.group, this.client); this.client.emit("guildGroupDelete", GuildGroupComponent); } guildRoleCreate(data: GatewayEvent_RoleCreated): void { const guild = this.client.guilds.get(data.serverId); const role = - guild?.roles.add(new GuildRole(data.role, this.client)) - ?? new GuildRole(data.role, this.client); + guild?.roles.add(new Role(data.role, this.client)) + ?? new Role(data.role, this.client); this.client.emit("guildRoleCreate", role); } @@ -146,32 +146,32 @@ export class GuildHandler extends GatewayEventHandler { const guild = this.client.guilds.get(data.serverId); const cachedRole = guild?.roles.get(data.role.id)?.toJSON() ?? null; const role = - guild?.roles.update(new GuildRole(data.role, this.client)) - ?? new GuildRole(data.role, this.client); + guild?.roles.update(new Role(data.role, this.client)) + ?? new Role(data.role, this.client); this.client.emit("guildRoleUpdate", role, cachedRole); } guildRoleDelete(data: GatewayEvent_RoleDeleted): void { const guild = this.client.guilds.get(data.serverId); const role = - guild?.roles.update(new GuildRole(data.role, this.client)) - ?? new GuildRole(data.role, this.client); + guild?.roles.update(new Role(data.role, this.client)) + ?? new Role(data.role, this.client); guild?.roles.delete(data.role.id); this.client.emit("guildRoleDelete", role); } guildCategoryCreate(data: GatewayEvent_CategoryCreated): void { - const category = new GuildCategory(data.category, this.client); + const category = new Category(data.category, this.client); this.client.emit("guildCategoryCreate", category); } guildCategoryUpdate(data: GatewayEvent_CategoryCreated): void { - const category = new GuildCategory(data.category, this.client); + const category = new Category(data.category, this.client); this.client.emit("guildCategoryUpdate", category); } guildCategoryDelete(data: GatewayEvent_CategoryCreated): void { - const category = new GuildCategory(data.category, this.client); + const category = new Category(data.category, this.client); this.client.emit("guildCategoryDelete", category); } } diff --git a/lib/index.ts b/lib/index.ts index bc5ec90b..c147e38f 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -50,7 +50,7 @@ export * from "./structures/ListItem"; export * from "./structures/Webhook"; export * from "./structures/DocComment"; export * from "./structures/SocialLink"; -export * from "./structures/CalendarEventComment"; +export * from "./structures/CalendarComment"; export * from "./structures/ReactionInfo"; export * from "./structures/MessageReactionInfo"; @@ -60,10 +60,10 @@ export * from "./structures/DocReactionInfo"; export * from "./structures/MemberRemoveInfo"; export * from "./structures/MemberUpdateInfo"; export * from "./structures/CalendarReactionInfo"; -export * from "./structures/GuildRole"; -export * from "./structures/GuildGroup"; -export * from "./structures/GuildCategory"; -export * from "./structures/GuildSubscription"; +export * from "./structures/Role"; +export * from "./structures/Group"; +export * from "./structures/Category"; +export * from "./structures/Subscription"; export * from "./structures/Permission"; export * from "./util/Collection"; diff --git a/lib/routes/Channels.ts b/lib/routes/Channels.ts index e69cd1ff..8dfdec37 100644 --- a/lib/routes/Channels.ts +++ b/lib/routes/Channels.ts @@ -15,7 +15,6 @@ import { Message } from "../structures/Message"; import { ForumThreadComment } from "../structures/ForumThreadComment"; import { ListItem } from "../structures/ListItem"; import { - APIListItem, ChannelReactionTypeBulkDeleteSupported, ChannelReactionTypes, ChannelSubcategoryReactionTypes, @@ -104,18 +103,20 @@ import { CreateForumCommentOptions, EditForumCommentOptions, EditDocOptions, - CreateDocOptions + CreateDocOptions, + RawMessage, + RawListItem } from "../types"; import { DocChannel } from "../structures/DocChannel"; import { ForumChannel } from "../structures/ForumChannel"; import { CalendarChannel } from "../structures/CalendarChannel"; import { TextChannel } from "../structures/TextChannel"; -import { CalendarEventComment } from "../structures/CalendarEventComment"; +import { CalendarComment } from "../structures/CalendarComment"; import { DocComment } from "../structures/DocComment"; import { Announcement } from "../structures/Announcement"; import { AnnouncementComment } from "../structures/AnnouncementComment"; import { Permission } from "../structures/Permission"; -import { APIChatMessage, PUTChannelMessageResponse } from "guildedapi-types.ts/v1"; +import { PUTChannelMessageResponse } from "guildedapi-types.ts/v1"; export class Channels { #manager: RESTManager; @@ -362,12 +363,12 @@ export class Channels { * @param eventID ID of an event containing the comment to get. * @param commentID ID of the comment to get. */ - async getCalendarEventComment(channelID: string, eventID: number, commentID: number): Promise { + async getCalendarEventComment(channelID: string, eventID: number, commentID: number): Promise { return this.#manager.authRequest({ method: "GET", path: endpoints.CHANNEL_EVENT_COMMENT(channelID, eventID, commentID) }).then(data => - new CalendarEventComment(data.calendarEventComment, this.#manager.client) + new CalendarComment(data.calendarEventComment, this.#manager.client) ); } @@ -376,13 +377,13 @@ export class Channels { * @param channelID ID of a "Calendar" channel. * @param eventID ID of the event containing comments. */ - async getCalendarEventComments(channelID: string, eventID: number): Promise> { + async getCalendarEventComments(channelID: string, eventID: number): Promise> { return this.#manager.authRequest({ method: "GET", path: endpoints.CHANNEL_EVENT_COMMENTS(channelID, eventID) }).then(data => data.calendarEventComments.map(d => - new CalendarEventComment(d, this.#manager.client) + new CalendarComment(d, this.#manager.client) ) ); } @@ -445,7 +446,7 @@ export class Channels { path: endpoints.LIST_ITEMS(channelID) }).then(data => data.listItems.map(d => - new ListItem(d as APIListItem, this.#manager.client)) as never + new ListItem(d as RawListItem, this.#manager.client)) as never ); } @@ -501,7 +502,7 @@ export class Channels { } }).then(data => this.#manager.client.util.updateMessage( - data.message as APIChatMessage, + data.message as RawMessage, params ) ); @@ -1067,14 +1068,14 @@ export class Channels { channelID: string, eventID: number, options: CreateCalendarCommentOptions - ): Promise { + ): Promise { if (typeof options !== "object") throw new Error("comment options should be an object."); return this.#manager.authRequest({ method: "POST", path: endpoints.CHANNEL_EVENT_COMMENTS(channelID, eventID), json: options }).then(data => - new CalendarEventComment(data.calendarEventComment, this.#manager.client) + new CalendarComment(data.calendarEventComment, this.#manager.client) ); } @@ -1089,14 +1090,14 @@ export class Channels { eventID: number, commentID: number, options: EditCalendarCommentOptions - ): Promise { + ): Promise { if (typeof options !== "object") throw new Error("comment options should be an object."); return this.#manager.authRequest({ method: "PATCH", path: endpoints.CHANNEL_EVENT_COMMENT(channelID, eventID, commentID), json: options }).then(data => - new CalendarEventComment(data.calendarEventComment, this.#manager.client) + new CalendarComment(data.calendarEventComment, this.#manager.client) ); } diff --git a/lib/routes/Guilds.ts b/lib/routes/Guilds.ts index de3003c1..a7bfc524 100644 --- a/lib/routes/Guilds.ts +++ b/lib/routes/Guilds.ts @@ -13,7 +13,6 @@ import { Member } from "../structures/Member"; import { Channel } from "../structures/Channel"; import { APIChannelCategories, - APIGuildMember, DELETEDeleteCategoryResponse, GETChannelCategoryRoleManyPermissionResponse, GETChannelCategoryRolePermissionResponse, @@ -75,13 +74,14 @@ import { WebhookExecuteOptions, WebhookMessageDetails, BulkXPOptions, - EditMemberOptions + EditMemberOptions, + RawMember } from "../types"; 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"; +import { Role } from "../structures/Role"; +import { Group } from "../structures/Group"; +import { Subscription } from "../structures/Subscription"; +import { Category } from "../structures/Category"; import { Permission } from "../structures/Permission"; import { GETGuildMemberRolesResponse } from "guildedapi-types.ts/v1"; import { POSTExecuteWebhookResponse } from "guildedapi-types.ts/typings/REST/v1/Webhooks"; @@ -159,7 +159,7 @@ export class Guilds { this.#manager.client.util.updateMember( guildID, d.user.id, - d as APIGuildMember + d as RawMember ) ) ); @@ -506,7 +506,7 @@ export class Guilds { * Get every guild roles from a guild. * @param guildID ID of the guild where roles are. */ - async getRoles(guildID: string): Promise> { + async getRoles(guildID: string): Promise> { return this.#manager.authRequest({ method: "GET", path: endpoints.GUILD_ROLES(guildID) @@ -522,7 +522,7 @@ export class Guilds { * @param guildID ID of the guild where the role is. * @param roleID ID of the role to get. */ - async getRole(guildID: string, roleID: number): Promise { + async getRole(guildID: string, roleID: number): Promise { return this.#manager.authRequest({ method: "GET", path: endpoints.GUILD_ROLE(guildID, roleID) @@ -534,7 +534,7 @@ export class Guilds { * @param guildID ID of the server you want to create the role in. * @param options Create options */ - async createRole(guildID: string, options: POSTGuildRoleBody): Promise { + async createRole(guildID: string, options: POSTGuildRoleBody): Promise { return this.#manager.authRequest({ method: "POST", path: endpoints.GUILD_ROLES(guildID), @@ -548,7 +548,7 @@ export class Guilds { * @param roleID ID of the role to edit * @param options Edit options */ - async editRole(guildID: string, roleID: number, options: PATCHGuildRoleBody): Promise { + async editRole(guildID: string, roleID: number, options: PATCHGuildRoleBody): Promise { return this.#manager.authRequest({ method: "PATCH", path: endpoints.GUILD_ROLE(guildID, roleID), @@ -572,7 +572,7 @@ export class Guilds { * Get guild groups. * @param guildID ID of the guild. */ - async getGroups(guildID: string): Promise> { + async getGroups(guildID: string): Promise> { return this.#manager.authRequest({ method: "GET", path: endpoints.GUILD_GROUPS(guildID) @@ -588,7 +588,7 @@ export class Guilds { * @param guildID ID of the guild. * @param groupID ID of the group to get. */ - async getGroup(guildID: string, groupID: string): Promise { + async getGroup(guildID: string, groupID: string): Promise { return this.#manager.authRequest({ method: "GET", path: endpoints.GUILD_GROUP(guildID, groupID) @@ -600,7 +600,7 @@ export class Guilds { * @param guildID The ID of the guild to create a group in. * @param options Create options */ - async createGroup(guildID: string, options: POSTGuildGroupBody): Promise { + async createGroup(guildID: string, options: POSTGuildGroupBody): Promise { return this.#manager.authRequest({ method: "POST", path: endpoints.GUILD_GROUPS(guildID), @@ -614,7 +614,7 @@ export class Guilds { * @param groupID The ID of the group to edit. * @param options Edit options */ - async editGroup(guildID: string, groupID: string, options: PATCHGuildGroupBody): Promise { + async editGroup(guildID: string, groupID: string, options: PATCHGuildGroupBody): Promise { return this.#manager.authRequest({ method: "POST", path: endpoints.GUILD_GROUP(guildID, groupID), @@ -639,7 +639,7 @@ export class Guilds { * Get guild subscriptions. * @param guildID ID of the guild. */ - async getSubscriptions(guildID: string): Promise> { + async getSubscriptions(guildID: string): Promise> { return this.#manager.authRequest({ method: "GET", path: endpoints.GUILD_SUBSCRIPTIONS(guildID) @@ -655,7 +655,7 @@ export class Guilds { * @param guildID ID of the guild. * @param subscriptionID ID of the subscription to get. */ - async getSubscription(guildID: string, subscriptionID: string): Promise { + async getSubscription(guildID: string, subscriptionID: string): Promise { return this.#manager.authRequest({ method: "GET", path: endpoints.GUILD_SUBSCRIPTION(guildID, subscriptionID) @@ -682,7 +682,7 @@ export class Guilds { * @param roleID ID of the role. * @param options Permission to edit. */ - async editRolePermission(guildID: string, roleID: number, options: PATCHGuildRolePermissionUpdateBody): Promise { + async editRolePermission(guildID: string, roleID: number, options: PATCHGuildRolePermissionUpdateBody): Promise { return this.#manager.authRequest({ method: "PATCH", path: endpoints.GUILD_ROLE_UPDATE_PERMISSION(guildID, roleID), @@ -721,7 +721,7 @@ export class Guilds { * @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 { + async createCategory(guildID: string, options: POSTCreateCategoryBody): Promise { return this.#manager.authRequest({ method: "POST", path: endpoints.GUILD_CATEGORY_CREATE(guildID), @@ -734,7 +734,7 @@ export class Guilds { * @param guildID ID of the guild to create a category in. * @param categoryID ID of the category you want to read. */ - async getCategory(guildID: string, categoryID: number): Promise { + async getCategory(guildID: string, categoryID: number): Promise { return this.#manager.authRequest({ method: "GET", path: endpoints.GUILD_CATEGORY(guildID, categoryID) @@ -747,7 +747,7 @@ export class Guilds { * @param categoryID ID of the category you want to read. * @param options Options to update a category. */ - async editCategory(guildID: string, categoryID: number, options: PATCHUpdateCategoryBody): Promise { + async editCategory(guildID: string, categoryID: number, options: PATCHUpdateCategoryBody): Promise { return this.#manager.authRequest({ method: "PATCH", path: endpoints.GUILD_CATEGORY(guildID, categoryID), @@ -760,7 +760,7 @@ export class Guilds { * @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 { + async deleteCategory(guildID: string, categoryID: number): Promise { return this.#manager.authRequest({ method: "DELETE", path: endpoints.GUILD_CATEGORY(guildID, categoryID) diff --git a/lib/structures/Announcement.ts b/lib/structures/Announcement.ts index c3473598..8660f909 100644 --- a/lib/structures/Announcement.ts +++ b/lib/structures/Announcement.ts @@ -8,14 +8,8 @@ import { Client } from "./Client"; import { Base } from "./Base"; import { AnnouncementComment } from "./AnnouncementComment"; -import { - APIAnnouncement, - APIAnnouncementComment, - APIMentions, - PATCHChannelAnnouncementBody, - POSTChannelAnnouncementBody -} from "../Constants"; -import { JSONAnnouncement } from "../types"; +import { PATCHChannelAnnouncementBody, POSTChannelAnnouncementBody } from "../Constants"; +import { JSONAnnouncement, RawAnnouncement, RawAnnouncementComment, RawMentions } from "../types"; import TypedCollection from "../util/TypedCollection"; /** Represents a channel announcement. */ @@ -31,17 +25,17 @@ export class Announcement extends Base { /** The announcement's content */ content: string; /** Mentions. */ - mentions: APIMentions | null; + mentions: RawMentions | null; /** The announcement's title. */ title: string; /** Cached announcement's comments */ - comments: TypedCollection; + comments: TypedCollection; /** * @param data raw data. * @param client client. */ - constructor(data: APIAnnouncement, client: Client) { + constructor(data: RawAnnouncement, client: Client) { super(data.id, client); this.guildID = data.serverId; this.channelID = data.channelId; @@ -71,7 +65,7 @@ export class Announcement extends Base { }; } - protected override update(data: APIAnnouncement): void { + protected override update(data: RawAnnouncement): void { if (data.channelId !== undefined) { this.channelID = data.channelId; } diff --git a/lib/structures/AnnouncementChannel.ts b/lib/structures/AnnouncementChannel.ts index 31c9612a..aa571121 100644 --- a/lib/structures/AnnouncementChannel.ts +++ b/lib/structures/AnnouncementChannel.ts @@ -9,19 +9,18 @@ import { Client } from "./Client"; import { GuildChannel } from "./GuildChannel"; import { Announcement } from "./Announcement"; -import type { APIAnnouncement, APIGuildChannel } from "../Constants"; import TypedCollection from "../util/TypedCollection"; -import { JSONAnnouncementChannel } from "../types"; +import { JSONAnnouncementChannel, RawAnnouncement, RawChannel } from "../types"; /** Represents a guild announcement channel. */ export class AnnouncementChannel extends GuildChannel { /** Cached announcements. */ - announcements: TypedCollection; + announcements: TypedCollection; /** * @param data raw data * @param client client */ - constructor(data: APIGuildChannel, client: Client){ + constructor(data: RawChannel, client: Client){ super(data, client); this.announcements = new TypedCollection( Announcement, diff --git a/lib/structures/AnnouncementComment.ts b/lib/structures/AnnouncementComment.ts index cbbf0b58..9dc85d85 100644 --- a/lib/structures/AnnouncementComment.ts +++ b/lib/structures/AnnouncementComment.ts @@ -9,8 +9,8 @@ import { Client } from "./Client"; import { Base } from "./Base"; import { Member } from "./Member"; -import { APIAnnouncementComment, APIMentions, PATCHChannelAnnouncementCommentBody, POSTChannelAnnouncementCommentBody } from "../Constants"; -import { ConstructorCalendarEventCommentOptions, JSONAnnouncementComment } from "../types"; +import { PATCHChannelAnnouncementCommentBody, POSTChannelAnnouncementCommentBody } from "../Constants"; +import { ConstructorCalendarCommentOptions, JSONAnnouncementComment, RawAnnouncementComment, RawMentions } from "../types"; /** AnnouncementComment represents a comment from an Announcement channel. */ export class AnnouncementComment extends Base { @@ -27,7 +27,7 @@ export class AnnouncementComment extends Base { /** ID of the parent announcement. */ announcementID: string; /** Mentions */ - mentions: APIMentions | null; + mentions: RawMentions | null; /** ID of the guild, if received. */ guildID: string | null; /** @@ -36,9 +36,9 @@ export class AnnouncementComment extends Base { * @param options Optional parameters that can be added */ constructor( - data: APIAnnouncementComment, + data: RawAnnouncementComment, client: Client, - options?: ConstructorCalendarEventCommentOptions + options?: ConstructorCalendarCommentOptions ) { super(data.id, client); this.content = data.content; @@ -66,7 +66,7 @@ export class AnnouncementComment extends Base { }; } - protected override update(data: APIAnnouncementComment): void { + protected override update(data: RawAnnouncementComment): void { if (data.announcementId !== undefined) { this.announcementID = data.announcementId; } diff --git a/lib/structures/BannedMember.ts b/lib/structures/BannedMember.ts index 8cb33f57..9d7b296b 100644 --- a/lib/structures/BannedMember.ts +++ b/lib/structures/BannedMember.ts @@ -10,8 +10,7 @@ import { User } from "./User"; import { Guild } from "./Guild"; import { Base } from "./Base"; import { Member } from "./Member"; -import { APIGuildMemberBan, APIUser } from "../Constants"; -import { JSONBannedMember } from "../types"; +import { JSONBannedMember, RawMemberBan, RawUser } from "../types"; /** BannedMember represents a banned guild member. */ export class BannedMember extends Base { @@ -35,7 +34,7 @@ export class BannedMember extends Base { * @param data raw data. * @param client client. */ - constructor(guildID: string, data: APIGuildMemberBan, client: Client){ + constructor(guildID: string, data: RawMemberBan, client: Client){ super(data.user.id, client); this.guildID = guildID; this.ban = { @@ -43,7 +42,7 @@ export class BannedMember extends Base { createdAt: data.createdAt ? new Date(data.createdAt) : null, bannedBy: data.createdBy }; - this.user = client.users.update(data.user as Partial) ?? new User(data.user as APIUser, client); + this.user = client.users.update(data.user as Partial) ?? new User(data.user as RawUser, client); this.member = client.getGuild(guildID)?.members.get(data.user.id) ?? null; this.update(data); } @@ -56,7 +55,7 @@ export class BannedMember extends Base { }; } - protected override update(data: APIGuildMemberBan): void { + protected override update(data: RawMemberBan): void { if (data.createdAt !== undefined) { this.ban.createdAt = new Date(data.createdAt); } @@ -66,8 +65,8 @@ export class BannedMember extends Base { if (data.reason !== undefined) { this.ban.reason = data.reason; } - if (data.user !== undefined && this.client.users.update(data.user as Partial)) { - this.user = this.client.users.update(data.user as Partial); + if (data.user !== undefined && this.client.users.update(data.user as Partial)) { + this.user = this.client.users.update(data.user as Partial); } } diff --git a/lib/structures/CalendarChannel.ts b/lib/structures/CalendarChannel.ts index 782cb9ab..489c56bc 100644 --- a/lib/structures/CalendarChannel.ts +++ b/lib/structures/CalendarChannel.ts @@ -9,19 +9,25 @@ import { Client } from "./Client"; import { CalendarEvent } from "./CalendarEvent"; import { GuildChannel } from "./GuildChannel"; -import type { APICalendarEvent, APIGuildChannel, POSTCalendarEventBody } from "../Constants"; +import type { POSTCalendarEventBody } from "../Constants"; import TypedCollection from "../util/TypedCollection"; -import { JSONCalendarChannel, CreateCalendarEventOptions, EditCalendarEventOptions } from "../types"; +import { + JSONCalendarChannel, + CreateCalendarEventOptions, + EditCalendarEventOptions, + RawCalendarEvent, + RawChannel +} from "../types"; /** Represents a calendar channel. */ export class CalendarChannel extends GuildChannel { /** Cached scheduled events. */ - scheduledEvents: TypedCollection; + scheduledEvents: TypedCollection; /** * @param data raw data * @param client client */ - constructor(data: APIGuildChannel, client: Client){ + constructor(data: RawChannel, client: Client){ super(data, client); this.scheduledEvents = new TypedCollection( CalendarEvent, diff --git a/lib/structures/CalendarEventComment.ts b/lib/structures/CalendarComment.ts similarity index 90% rename from lib/structures/CalendarEventComment.ts rename to lib/structures/CalendarComment.ts index 701659b1..3dfbfd07 100644 --- a/lib/structures/CalendarEventComment.ts +++ b/lib/structures/CalendarComment.ts @@ -9,13 +9,19 @@ import { Client } from "./Client"; import { Base } from "./Base"; import { Member } from "./Member"; -import { APICalendarEventComment } from "../Constants"; -import { CreateCalendarCommentOptions, EditCalendarCommentOptions, JSONCalendarEventComment, ConstructorCalendarEventCommentOptions } from "../types"; + +import { + CreateCalendarCommentOptions, + EditCalendarCommentOptions, + JSONCalendarEventComment, + ConstructorCalendarCommentOptions, + RawCalendarComment +} from "../types"; /** CalendarEventComment represents an event comment coming from a calendar channel. */ -export class CalendarEventComment extends Base { +export class CalendarComment extends Base { /** Raw data */ - data: APICalendarEventComment; + data: RawCalendarComment; /** This property isn't always provided by the Guilded API, the value can be null, * which disable the ability to get member through this class. */ guildID: string | null; @@ -37,9 +43,9 @@ export class CalendarEventComment extends Base { * @param options Additional properties that can be added. */ constructor( - data: APICalendarEventComment, + data: RawCalendarComment, client: Client, - options?: ConstructorCalendarEventCommentOptions + options?: ConstructorCalendarCommentOptions ) { super(data.id, client); this.data = data; @@ -66,7 +72,7 @@ export class CalendarEventComment extends Base { }; } - protected override update(data: APICalendarEventComment): void { + protected override update(data: RawCalendarComment): void { if (data.calendarEventId !== undefined) { this.eventID = Number(data.calendarEventId); } @@ -104,7 +110,7 @@ export class CalendarEventComment extends Base { /** Create a comment in the same event as this one. * @param options Create options. */ - async createCalendarComment(options: CreateCalendarCommentOptions): Promise { + async createCalendarComment(options: CreateCalendarCommentOptions): Promise { return this.client.rest.channels.createCalendarComment( this.channelID, this.eventID, @@ -139,7 +145,7 @@ export class CalendarEventComment extends Base { } /** Edit this comment */ - async edit(options: EditCalendarCommentOptions): Promise{ + async edit(options: EditCalendarCommentOptions): Promise{ return this.client.rest.channels.editCalendarComment( this.channelID, this.eventID, diff --git a/lib/structures/CalendarEvent.ts b/lib/structures/CalendarEvent.ts index 7df30590..16fd9f97 100644 --- a/lib/structures/CalendarEvent.ts +++ b/lib/structures/CalendarEvent.ts @@ -11,15 +11,21 @@ import { Base } from "./Base"; import { User } from "./User"; import { CalendarEventRSVP } from "./CalendarRSVP"; -import { CalendarEventComment } from "./CalendarEventComment"; -import { APICalendarEvent, APICalendarEventComment, APICalendarEventRSVP, APIMentions } from "../Constants"; -import { EditCalendarEventOptions, JSONCalendarEvent } from "../types"; +import { CalendarComment } from "./CalendarComment"; +import { + EditCalendarEventOptions, + JSONCalendarEvent, + RawCalendarEvent, + RawCalendarComment, + RawCalendarRSVP, + RawMentions +} from "../types"; import TypedCollection from "../util/TypedCollection"; /** CalendarEvent represents an event coming from a calendar channel. */ export class CalendarEvent extends Base { /** Raw data */ - data: APICalendarEvent; + data: RawCalendarEvent; /** Guild/server ID */ guildID: string; /** ID of the channel the event was created on. */ @@ -43,23 +49,23 @@ export class CalendarEvent extends Base { /** If true, this event is private. */ isPrivate: boolean; /** Mentions in this calendar event. */ - mentions: APIMentions | null; + mentions: RawMentions | null; /** When the event was created. */ createdAt: Date | null; /** ID of the owner of this event. */ ownerID: string; /** Details about event cancellation (if canceled) */ - cancellation: APICalendarEvent["cancellation"] | null; + cancellation: RawCalendarEvent["cancellation"] | null; /** Cached RSVPS. */ - rsvps: TypedCollection; + rsvps: TypedCollection; /** Cached Comments */ - comments: TypedCollection; + comments: TypedCollection; /** * @param data raw data. * @param client client. */ - constructor(data: APICalendarEvent, client: Client){ + constructor(data: RawCalendarEvent, client: Client){ super(data.id, client); this.data = data; this.id = data.id; @@ -84,7 +90,7 @@ export class CalendarEvent extends Base { client.params.collectionLimits?.scheduledEventsRSVPS ); this.comments = new TypedCollection( - CalendarEventComment, + CalendarComment, client, client.params.collectionLimits?.calendarComments ); @@ -115,7 +121,7 @@ export class CalendarEvent extends Base { }; } - protected override update(data: APICalendarEvent): void { + protected override update(data: RawCalendarEvent): void { if (data.cancellation !== undefined) { this.cancellation = data.cancellation; } diff --git a/lib/structures/CalendarRSVP.ts b/lib/structures/CalendarRSVP.ts index fe210f6a..a7d23947 100644 --- a/lib/structures/CalendarRSVP.ts +++ b/lib/structures/CalendarRSVP.ts @@ -7,15 +7,14 @@ import { Client } from "./Client"; import { Base } from "./Base"; -import { APICalendarEventRSVP, APICalendarEventRSVPStatuses } from "../Constants"; -import { JSONCalendarEventRSVP, EditCalendarRSVPOptions } from "../types"; +import { JSONCalendarEventRSVP, EditCalendarRSVPOptions, RawCalendarRSVP, CalendarRSVPStatus } from "../types"; /** CalendarEventRSVP represents a guild member's event RSVP. * It gives information about a member's set presence to an event. */ export class CalendarEventRSVP extends Base { /** Raw data */ - #data: APICalendarEventRSVP; + #data: RawCalendarRSVP; /** Guild/server ID. */ guildID: string; /** Calendar channel id. */ @@ -23,7 +22,7 @@ export class CalendarEventRSVP extends Base { /** ID of the entity assigned to this Event RSVP. */ entityID: string; /** Status of the RSVP */ - status: APICalendarEventRSVPStatuses; + status: CalendarRSVPStatus; /** When the RSVP was created. */ createdAt: Date | null; /** ID of the user who created this RSVP. */ @@ -37,7 +36,7 @@ export class CalendarEventRSVP extends Base { * @param data raw data. * @param client client. */ - constructor(data: APICalendarEventRSVP, client: Client){ + constructor(data: RawCalendarRSVP, client: Client){ super(data.calendarEventId, client); this.#data = data; this.guildID = data.serverId; @@ -65,7 +64,7 @@ export class CalendarEventRSVP extends Base { }; } - protected override update(data: APICalendarEventRSVP): void { + protected override update(data: RawCalendarRSVP): void { if (data.calendarEventId !== undefined) { this.id = data.calendarEventId; } diff --git a/lib/structures/GuildCategory.ts b/lib/structures/Category.ts similarity index 91% rename from lib/structures/GuildCategory.ts rename to lib/structures/Category.ts index bf5aba5c..ad23eea9 100644 --- a/lib/structures/GuildCategory.ts +++ b/lib/structures/Category.ts @@ -8,12 +8,12 @@ import { Client } from "./Client"; import { Base } from "./Base"; import { Permission } from "./Permission"; -import { JSONGuildCategory } from "../types"; +import { JSONGuildCategory, RawCategory } from "../types"; import { PATCHUpdateCategoryBody } from "../Constants"; -import { APIGuildCategory, PATCHChannelCategoryUserPermissionBody, POSTChannelCategoryUserPermissionBody } from "guildedapi-types.ts/v1"; +import { PATCHChannelCategoryUserPermissionBody, POSTChannelCategoryUserPermissionBody } from "guildedapi-types.ts/v1"; -/** Class representing a guild group. */ -export class GuildCategory extends Base { +/** Represents a Guild Category. */ +export class Category extends Base { /** Type of the subscription */ override id: number; /** The ID of the server */ @@ -27,7 +27,7 @@ export class GuildCategory extends Base { /** Name of the category (min length 1; max length 100) */ name: string; - constructor(data: APIGuildCategory, client: Client) { + constructor(data: RawCategory, client: Client) { super(data.id, client); this.id = data.id; this.guildID = data.serverId; @@ -49,7 +49,7 @@ export class GuildCategory extends Base { }; } - protected override update(data: APIGuildCategory): void { + protected override update(data: RawCategory): void { if (data.id !== undefined) { this.id = data.id; } @@ -74,7 +74,7 @@ export class GuildCategory extends Base { * Update a guild category. * @param options Edit options. */ - async editCategory(options: PATCHUpdateCategoryBody): Promise { + async editCategory(options: PATCHUpdateCategoryBody): Promise { return this.client.rest.guilds.editCategory( this.guildID as string, this.id as number, @@ -85,7 +85,7 @@ export class GuildCategory extends Base { /** * Delete a guild category. */ - async deleteCategory(): Promise { + async deleteCategory(): Promise { return this.client.rest.guilds.deleteCategory(this.guildID as string, this.id as number); } diff --git a/lib/structures/Channel.ts b/lib/structures/Channel.ts index e86e28b9..409a3ad3 100644 --- a/lib/structures/Channel.ts +++ b/lib/structures/Channel.ts @@ -14,8 +14,7 @@ import { DocChannel } from "./DocChannel"; import { ForumChannel } from "./ForumChannel"; import { TextChannel } from "./TextChannel"; import { AnnouncementChannel } from "./AnnouncementChannel"; -import type { APIGuildChannel } from "../Constants"; -import { AnyChannel, EditChannelOptions, JSONChannel } from "../types"; +import { AnyChannel, EditChannelOptions, JSONChannel, RawChannel } from "../types"; /** Represents a channel. */ export class Channel extends Base { @@ -27,13 +26,13 @@ export class Channel extends Base { * @param data raw data * @param client client */ - constructor(data: APIGuildChannel, client: Client){ + constructor(data: RawChannel, client: Client){ super(data.id, client); this.type = data.type; this.name = data.name; } - static from(data: APIGuildChannel, client: Client): T { + static from(data: RawChannel, client: Client): T { switch (data.type) { case "announcements": { return new AnnouncementChannel(data, client) as T; diff --git a/lib/structures/Client.ts b/lib/structures/Client.ts index 111b5d79..6cfd9574 100644 --- a/lib/structures/Client.ts +++ b/lib/structures/Client.ts @@ -28,14 +28,14 @@ import { User } from "./User"; import { BannedMember } from "./BannedMember"; import { TextChannel } from "./TextChannel"; import { ForumChannel } from "./ForumChannel"; -import { CalendarEventComment } from "./CalendarEventComment"; +import { CalendarComment } from "./CalendarComment"; import { DocComment } from "./DocComment"; import { AnnouncementComment } from "./AnnouncementComment"; import { Announcement } from "./Announcement"; -import { GuildRole } from "./GuildRole"; -import { GuildGroup } from "./GuildGroup"; -import { GuildSubscription } from "./GuildSubscription"; -import { GuildCategory } from "./GuildCategory"; +import { Role } from "./Role"; +import { Group } from "./Group"; +import { Subscription } from "./Subscription"; +import { Category } from "./Category"; import { Permission } from "./Permission"; import { WSManager } from "../gateway/WSManager"; import { GatewayHandler } from "../gateway/GatewayHandler"; @@ -47,8 +47,6 @@ import { POSTListItemBody, GATEWAY_EVENTS, ChannelReactionTypes, - APIGuild, - APIUser, ChannelSubcategoryReactionTypes, POSTCalendarEventBody, PATCHListItemBody, @@ -105,7 +103,9 @@ import { EditDocCommentOptions, EditWebhookOptions, WebhookExecuteOptions, - WebhookMessageDetails + WebhookMessageDetails, + RawGuild, + RawUser } from "../types"; import { Util } from "../util/Util"; import { config } from "../../pkgconfig"; @@ -131,9 +131,9 @@ export class Client extends TypedEmitter { /** Gateway Handler. */ #gateway: GatewayHandler; /** Cached guilds. */ - guilds: TypedCollection; + guilds: TypedCollection; /** Cached users. */ - users: TypedCollection; + users: TypedCollection; /** Utils */ util: Util; /** Time at which the connection started in ms. */ @@ -503,7 +503,7 @@ export class Client extends TypedEmitter { channelID: string, eventID: number, commentID: number - ): Promise { + ): Promise { return this.rest.channels.getCalendarEventComment(channelID, eventID, commentID); } @@ -512,7 +512,7 @@ export class Client extends TypedEmitter { * @param channelID ID of a "Calendar" channel. * @param eventID ID of the event containing comments. */ - async getCalendarEventComments(channelID: string, eventID: number): Promise> { + async getCalendarEventComments(channelID: string, eventID: number): Promise> { return this.rest.channels.getCalendarEventComments(channelID, eventID); } @@ -1004,7 +1004,7 @@ export class Client extends TypedEmitter { channelID: string, eventID: number, options: CreateCalendarCommentOptions - ): Promise { + ): Promise { return this.rest.channels.createCalendarComment(channelID, eventID, options); } @@ -1019,7 +1019,7 @@ export class Client extends TypedEmitter { eventID: number, commentID: number, options: EditCalendarCommentOptions - ): Promise { + ): Promise { return this.rest.channels.editCalendarComment( channelID, eventID, @@ -1424,7 +1424,7 @@ export class Client extends TypedEmitter { * Get every guild roles from a guild. * @param guildID ID of the guild where roles are. */ - async getGuildRoles(guildID: string): Promise> { + async getGuildRoles(guildID: string): Promise> { return this.rest.guilds.getRoles(guildID); } @@ -1433,7 +1433,7 @@ export class Client extends TypedEmitter { * @param guildID ID of the guild where the role is. * @param roleID ID of the role to get. */ - async getGuildRole(guildID: string, roleID: number): Promise { + async getGuildRole(guildID: string, roleID: number): Promise { return this.rest.guilds.getRole(guildID, roleID); } @@ -1442,7 +1442,7 @@ export class Client extends TypedEmitter { * @param guildID ID of the server you want to create the role in. * @param options Create options */ - async createGuildRole(guildID: string, options: POSTGuildRoleBody): Promise { + async createGuildRole(guildID: string, options: POSTGuildRoleBody): Promise { return this.rest.guilds.createRole(guildID, options); } @@ -1452,7 +1452,7 @@ export class Client extends TypedEmitter { * @param roleID ID of the role to edit * @param options Edit options */ - async editGuildRole(guildID: string, roleID: number, options: PATCHGuildRoleBody): Promise { + async editGuildRole(guildID: string, roleID: number, options: PATCHGuildRoleBody): Promise { return this.rest.guilds.editRole(guildID, roleID, options); } @@ -1466,7 +1466,7 @@ export class Client extends TypedEmitter { guildID: string, roleID: number, options: PATCHGuildRolePermissionUpdateBody - ): Promise { + ): Promise { return this.rest.guilds.editRolePermission(guildID, roleID, options); } @@ -1500,7 +1500,7 @@ export class Client extends TypedEmitter { * Get guild groups. * @param guildID ID of the guild. */ - async getGuildGroups(guildID: string): Promise> { + async getGuildGroups(guildID: string): Promise> { return this.rest.guilds.getGroups(guildID); } @@ -1509,7 +1509,7 @@ export class Client extends TypedEmitter { * @param guildID ID of the guild. * @param groupID ID of the group to get. */ - async getGuildGroup(guildID: string, groupID: string): Promise { + async getGuildGroup(guildID: string, groupID: string): Promise { return this.rest.guilds.getGroup(guildID, groupID); } @@ -1518,7 +1518,7 @@ export class Client extends TypedEmitter { * @param guildID The ID of the guild to create a group in. * @param options Create options */ - async createGuildGroup(guildID: string, options: POSTGuildGroupBody): Promise { + async createGuildGroup(guildID: string, options: POSTGuildGroupBody): Promise { return this.rest.guilds.createGroup(guildID, options); } @@ -1528,7 +1528,7 @@ export class Client extends TypedEmitter { * @param groupID The ID of the group to edit. * @param options Edit options */ - async editGuildGroup(guildID: string, groupID: string, options: PATCHGuildGroupBody): Promise { + async editGuildGroup(guildID: string, groupID: string, options: PATCHGuildGroupBody): Promise { return this.rest.guilds.editGroup(guildID, groupID, options); } @@ -1545,7 +1545,7 @@ export class Client extends TypedEmitter { * Get guild subscriptions. * @param guildID ID of the guild. */ - async getGuildSubscriptions(guildID: string): Promise> { + async getGuildSubscriptions(guildID: string): Promise> { return this.rest.guilds.getSubscriptions(guildID); } @@ -1554,7 +1554,7 @@ export class Client extends TypedEmitter { * @param guildID ID of the guild. * @param subscriptionID ID of the subscription to get. */ - async getGuildSubscription(guildID: string, subscriptionID: string): Promise { + async getGuildSubscription(guildID: string, subscriptionID: string): Promise { return this.rest.guilds.getSubscription(guildID, subscriptionID); } @@ -1616,7 +1616,7 @@ export class Client extends TypedEmitter { * @param guildID ID of the guild. * @param options Create options. */ - async createGuildCategory(guildID: string, options: POSTCreateCategoryBody): Promise { + async createGuildCategory(guildID: string, options: POSTCreateCategoryBody): Promise { return this.rest.guilds.createCategory(guildID, options); } /** @@ -1624,7 +1624,7 @@ export class Client extends TypedEmitter { * @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 { + async getGuildCategory(guildID: string, categoryID: number): Promise { return this.rest.guilds.getCategory(guildID, categoryID); } /** @@ -1638,7 +1638,7 @@ export class Client extends TypedEmitter { categoryID: number, options: PATCHUpdateCategoryBody - ): Promise { + ): Promise { return this.rest.guilds.editCategory(guildID, categoryID, options); } @@ -1647,7 +1647,7 @@ export class Client extends TypedEmitter { * @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 { + async deleteGuildCategory(guildID: string, categoryID: number): Promise { return this.rest.guilds.deleteCategory(guildID, categoryID); } diff --git a/lib/structures/Doc.ts b/lib/structures/Doc.ts index 52373048..361607ce 100644 --- a/lib/structures/Doc.ts +++ b/lib/structures/Doc.ts @@ -4,8 +4,13 @@ import { Member } from "./Member"; import { Base } from "./Base"; import { DocComment } from "./DocComment"; -import { APIDoc, APIDocComment, APIMentions } from "../Constants"; -import { EditDocOptions, JSONDoc } from "../types"; +import { + EditDocOptions, + JSONDoc, + RawDoc, + RawDocComment, + RawMentions +} from "../types"; import TypedCollection from "../util/TypedCollection"; // @@ -24,7 +29,7 @@ export class Doc extends Base { /** Content of the doc */ content: string; /** Doc mentions */ - mentions: APIMentions; + mentions: RawMentions; /** When the doc has been created. */ createdAt: Date; /** ID of the member who created this doc. */ @@ -33,13 +38,13 @@ export class Doc extends Base { editedTimestamp: Date | null; /** ID of the member who updated the doc. */ updatedBy: string | null; - comments: TypedCollection; + comments: TypedCollection; /** * @param data raw data * @param client client */ - constructor(data: APIDoc, client: Client) { + constructor(data: RawDoc, client: Client) { super(data.id, client); this.guildID = data.serverId; this.channelID = data.channelId; @@ -73,7 +78,7 @@ export class Doc extends Base { }; } - protected override update(data: APIDoc): void { + protected override update(data: RawDoc): void { if (data.channelId !== undefined) { this.channelID = data.channelId; } diff --git a/lib/structures/DocChannel.ts b/lib/structures/DocChannel.ts index 7ea2091b..f562aa4e 100644 --- a/lib/structures/DocChannel.ts +++ b/lib/structures/DocChannel.ts @@ -3,9 +3,14 @@ import { Client } from "./Client"; import { Doc } from "./Doc"; import { GuildChannel } from "./GuildChannel"; -import type { APIDoc, APIGuildChannel } from "../Constants"; import TypedCollection from "../util/TypedCollection"; -import { JSONDocChannel, CreateDocOptions, EditDocOptions } from "../types"; +import { + JSONDocChannel, + CreateDocOptions, + EditDocOptions, + RawDoc, + RawChannel +} from "../types"; // // Created by Wade (@pakkographic) @@ -15,12 +20,12 @@ import { JSONDocChannel, CreateDocOptions, EditDocOptions } from "../types"; /** Represents a "docs" channel. */ export class DocChannel extends GuildChannel { /** Cached docs. */ - docs: TypedCollection; + docs: TypedCollection; /** * @param data raw data * @param client client */ - constructor(data: APIGuildChannel, client: Client){ + constructor(data: RawChannel, client: Client){ super(data, client); this.docs = new TypedCollection(Doc, client, client.params.collectionLimits?.docs); this.update(data); diff --git a/lib/structures/DocComment.ts b/lib/structures/DocComment.ts index 7fc1ffed..899e883d 100644 --- a/lib/structures/DocComment.ts +++ b/lib/structures/DocComment.ts @@ -9,13 +9,19 @@ import { Client } from "./Client"; import { Base } from "./Base"; import { Member } from "./Member"; -import { APIDocComment, APIMentions } from "../Constants"; -import { JSONDocComment, ConstructorDocCommentOptions, CreateDocCommentOptions, EditDocCommentOptions } from "../types"; +import { + JSONDocComment, + ConstructorDocCommentOptions, + CreateDocCommentOptions, + EditDocCommentOptions, + RawDocComment, + RawMentions +} from "../types"; /** DocComment represents a doc comment coming from a Docs channel. */ export class DocComment extends Base { /** Raw data */ - raw: APIDocComment; + raw: RawDocComment; /** The content of the comment. */ content: string; /** The date of the comment's creation. */ @@ -29,7 +35,7 @@ export class DocComment extends Base { /** The ID of the doc the comment is in. */ docID: number; /** Mentions. */ - mentions: APIMentions | null; + mentions: RawMentions | null; /** ID of the guild, if provided. */ guildID: string | null; @@ -38,7 +44,7 @@ export class DocComment extends Base { * @param client client. * @param options Additional properties that can be added. */ - constructor(data: APIDocComment, client: Client, options?: ConstructorDocCommentOptions) { + constructor(data: RawDocComment, client: Client, options?: ConstructorDocCommentOptions) { super(data.id, client); this.raw = data; this.content = data.content; @@ -67,7 +73,7 @@ export class DocComment extends Base { }; } - protected override update(data: APIDocComment): void { + protected override update(data: RawDocComment): void { if (data.channelId !== undefined) { this.channelID = data.channelId; } diff --git a/lib/structures/ForumChannel.ts b/lib/structures/ForumChannel.ts index e567f861..dd3e552e 100644 --- a/lib/structures/ForumChannel.ts +++ b/lib/structures/ForumChannel.ts @@ -9,19 +9,24 @@ import { Client } from "./Client"; import { ForumThread } from "./ForumThread"; import { GuildChannel } from "./GuildChannel"; -import type { APIForumTopic, APIGuildChannel } from "../Constants"; import TypedCollection from "../util/TypedCollection"; -import { JSONForumChannel, CreateForumThreadOptions, EditForumThreadOptions } from "../types"; +import { + JSONForumChannel, + CreateForumThreadOptions, + EditForumThreadOptions, + RawForumThread, + RawChannel +} from "../types"; /** Represents a forum channel. */ export class ForumChannel extends GuildChannel { /** Cached threads. */ - threads: TypedCollection>; + threads: TypedCollection>; /** * @param data raw data * @param client client */ - constructor(data: APIGuildChannel, client: Client){ + constructor(data: RawChannel, client: Client){ super(data, client); this.threads = new TypedCollection( ForumThread, diff --git a/lib/structures/ForumThread.ts b/lib/structures/ForumThread.ts index 93bdc5b6..0e4d75eb 100644 --- a/lib/structures/ForumThread.ts +++ b/lib/structures/ForumThread.ts @@ -12,8 +12,15 @@ import { Base } from "./Base"; import { User } from "./User"; import { ForumThreadComment } from "./ForumThreadComment"; import { ForumChannel } from "./ForumChannel"; -import { APIForumTopic, APIForumTopicComment, APIMentions } from "../Constants"; -import { EditForumThreadOptions, JSONForumThread, AnyTextableChannel, CreateForumCommentOptions } from "../types"; +import { + EditForumThreadOptions, + JSONForumThread, + AnyTextableChannel, + CreateForumCommentOptions, + RawMentions, + RawForumThreadComment, + RawForumThread +} from "../types"; import TypedCollection from "../util/TypedCollection"; @@ -40,9 +47,9 @@ export class ForumThread extends Base { /** Content of the thread */ content: string; /** Thread mentions */ - mentions: APIMentions | null; + mentions: RawMentions | null; /** Cached comments. */ - comments: TypedCollection; + comments: TypedCollection; /** If true, the thread is locked. */ isLocked: boolean; /** If true, the thread is pinned. */ @@ -52,7 +59,7 @@ export class ForumThread extends Base { * @param data raw data * @param client client */ - constructor(data: APIForumTopic, client: Client){ + constructor(data: RawForumThread, client: Client){ super(data.id, client); this.guildID = data.serverId; this.channelID = data.channelId; @@ -98,7 +105,7 @@ export class ForumThread extends Base { }; } - protected override update(data: APIForumTopic): void { + protected override update(data: RawForumThread): void { if (data.bumpedAt !== undefined) { this.bumpedAt = new Date(data.bumpedAt); } diff --git a/lib/structures/ForumThreadComment.ts b/lib/structures/ForumThreadComment.ts index ae7a4f34..f13e7fc2 100644 --- a/lib/structures/ForumThreadComment.ts +++ b/lib/structures/ForumThreadComment.ts @@ -8,8 +8,14 @@ import { Client } from "./Client"; import { Base } from "./Base"; import { Member } from "./Member"; -import { APIForumTopicComment, APIMentions } from "../Constants"; -import { CreateForumCommentOptions, EditForumCommentOptions, ConstructorForumThreadOptions, JSONForumThreadComment } from "../types"; +import { + CreateForumCommentOptions, + EditForumCommentOptions, + ConstructorForumThreadOptions, + JSONForumThreadComment, + RawMentions, + RawForumThreadComment +} from "../types"; /** Represents a comment coming from a ForumThread. */ export class ForumThreadComment extends Base { @@ -28,10 +34,10 @@ export class ForumThreadComment extends Base { /** ID of the forum channel containing this thread. */ channelID: string; /** Mentions in this thread comment. */ - mentions: APIMentions | null; + mentions: RawMentions | null; constructor( - data: APIForumTopicComment, + data: RawForumThreadComment, client: Client, options?: ConstructorForumThreadOptions ){ @@ -61,7 +67,7 @@ export class ForumThreadComment extends Base { }; } - protected override update(data: APIForumTopicComment): void { + protected override update(data: RawForumThreadComment): void { if (data.channelId !== undefined) { this.channelID = data.channelId; } diff --git a/lib/structures/GuildGroup.ts b/lib/structures/Group.ts similarity index 92% rename from lib/structures/GuildGroup.ts rename to lib/structures/Group.ts index 1a8a69be..27cea5f9 100644 --- a/lib/structures/GuildGroup.ts +++ b/lib/structures/Group.ts @@ -7,11 +7,10 @@ import { Client } from "./Client"; import { Base } from "./Base"; -import { JSONGuildGroup } from "../types"; -import { APIGuildGroup } from "guildedapi-types.ts/v1"; +import { JSONGuildGroup, RawGroup } from "../types"; -/** Class representing a guild group. */ -export class GuildGroup extends Base { +/** Represents a Guild Group. */ +export class Group extends Base { /** ID of the guild */ guildID: string; /** The group's name (min length 1; max length 80) */ @@ -38,7 +37,7 @@ export class GuildGroup extends Base { archivedAt: Date | null; /** The ID of the user who archived this group, if archived. */ archivedBy: string | null; - constructor(data: APIGuildGroup, client: Client) { + constructor(data: RawGroup, client: Client) { super(data.id, client); this.guildID = data.serverId; this.name = data.name; @@ -75,7 +74,7 @@ export class GuildGroup extends Base { }; } - protected override update(data: APIGuildGroup): void { + protected override update(data: RawGroup): void { if (data.serverId !== undefined) { this.guildID = data.serverId; } diff --git a/lib/structures/Guild.ts b/lib/structures/Guild.ts index 9b1b4427..64a9f595 100644 --- a/lib/structures/Guild.ts +++ b/lib/structures/Guild.ts @@ -11,23 +11,23 @@ import { Channel } from "./Channel"; import { Member } from "./Member"; import { User } from "./User"; import { BannedMember } from "./BannedMember"; -import { GuildSubscription } from "./GuildSubscription"; +import { Subscription } from "./Subscription"; import { GuildChannel } from "./GuildChannel"; -import { GuildGroup } from "./GuildGroup"; -import { GuildRole } from "./GuildRole"; -import { GuildCategory } from "./GuildCategory"; -import { - APIGuild, - APIGuildChannel, - APIGuildGroup, - APIGuildMember, - APIGuildRole, - POSTBulkAwardXPResponse, - POSTCreateCategoryBody, - PATCHUpdateCategoryBody -} from "../Constants"; +import { Group } from "./Group"; +import { Role } from "./Role"; +import { Category } from "./Category"; +import { POSTBulkAwardXPResponse, POSTCreateCategoryBody, PATCHUpdateCategoryBody } from "../Constants"; import TypedCollection from "../util/TypedCollection"; -import { JSONGuild, AnyChannel, BulkXPOptions } from "../types"; +import { + JSONGuild, + AnyChannel, + BulkXPOptions, + RawGroup, + RawChannel, + RawMember, + RawRole, + RawGuild +} from "../types"; /** Represents a Guild, also called server. */ export class Guild extends Base { @@ -55,19 +55,19 @@ export class Guild extends Base { /** If true, the guild is verified. */ verified: boolean; /** Cached guild groups */ - groups: TypedCollection; + groups: TypedCollection; /** Cached guild channels. */ - channels: TypedCollection; + channels: TypedCollection; /** Cached guild members. */ - members: TypedCollection; + members: TypedCollection; /** Cached guild roles. */ - roles: TypedCollection; + roles: TypedCollection; /** * @param data raw data. * @param client client. */ - constructor(data: APIGuild, client: Client){ + constructor(data: RawGuild, client: Client){ super(data.id, client); this.ownerID = data.ownerId; this.type = data.type; @@ -80,10 +80,10 @@ export class Guild extends Base { this.defaultChannelID = data.defaultChannelId; this.createdAt = new Date(data.createdAt); this.verified = data.isVerified ?? false; - this.groups = new TypedCollection(GuildGroup, client); + this.groups = new TypedCollection(Group, client); this.channels = new TypedCollection(GuildChannel, client); this.members = new TypedCollection(Member, client); - this.roles = new TypedCollection(GuildRole, client); + this.roles = new TypedCollection(Role, client); this.update(data); } @@ -106,7 +106,7 @@ export class Guild extends Base { }; } - protected override update(data: APIGuild): void { + protected override update(data: RawGuild): void { if (data.about !== undefined) { this.description = data.about; } @@ -186,12 +186,12 @@ export class Guild extends Base { /** Get Subscription * @param subscriptionID ID of the subscription to get. */ - async getSubscription(subscriptionID: string): Promise { + async getSubscription(subscriptionID: string): Promise { return this.client.rest.guilds.getSubscription(this.id as string, subscriptionID); } /** Get Subscriptions */ - async getSubscriptions(): Promise> { + async getSubscriptions(): Promise> { return this.client.rest.guilds.getSubscriptions(this.id as string); } @@ -213,14 +213,14 @@ export class Guild extends Base { * Create a category * @param options Create options. */ - async createCategory(options: POSTCreateCategoryBody): Promise { + async createCategory(options: POSTCreateCategoryBody): Promise { return this.client.rest.guilds.createCategory(this.id as string, options); } /** * Read a guild category. * @param categoryID ID of the category you want to read. */ - async getCategory(categoryID: number): Promise { + async getCategory(categoryID: number): Promise { return this.client.rest.guilds.getCategory(this.id as string, categoryID); } /** @@ -228,7 +228,7 @@ export class Guild extends Base { * @param categoryID ID of the category you want to read. * @param options Options to update a category. */ - async editCategory(categoryID: number, options: PATCHUpdateCategoryBody): Promise { + async editCategory(categoryID: number, options: PATCHUpdateCategoryBody): Promise { return this.client.rest.guilds.editCategory(this.id as string, categoryID, options); } @@ -236,7 +236,7 @@ export class Guild extends Base { * Delete a category. * @param categoryID ID of the category you want to read. */ - async deleteCategory(categoryID: number): Promise { + async deleteCategory(categoryID: number): Promise { return this.client.rest.guilds.deleteCategory(this.id as string, categoryID); } diff --git a/lib/structures/GuildChannel.ts b/lib/structures/GuildChannel.ts index e1e72e11..b793b33c 100644 --- a/lib/structures/GuildChannel.ts +++ b/lib/structures/GuildChannel.ts @@ -9,8 +9,7 @@ import { Client } from "./Client"; import { Base } from "./Base"; import { Channel } from "./Channel"; -import { EditChannelOptions, JSONGuildChannel } from "../types"; -import type { APIGuildChannel } from "../Constants"; +import { EditChannelOptions, JSONGuildChannel, RawChannel } from "../types"; /** Represents a guild channel. */ export class GuildChannel extends Base { @@ -53,7 +52,7 @@ export class GuildChannel extends Base { * @param data raw data * @param client client */ - constructor(data: APIGuildChannel, client: Client) { + constructor(data: RawChannel, client: Client) { super(data.id, client); this.type = data.type; this.name = data.name; @@ -100,7 +99,7 @@ export class GuildChannel extends Base { }; } - protected override update(data: APIGuildChannel): void { + protected override update(data: RawChannel): void { if (data.archivedAt !== undefined) { this.archivedAt = new Date(data.archivedAt); } diff --git a/lib/structures/ListItem.ts b/lib/structures/ListItem.ts index 2bf25fa0..158a9df5 100644 --- a/lib/structures/ListItem.ts +++ b/lib/structures/ListItem.ts @@ -8,20 +8,20 @@ import { Client } from "./Client"; import { Member } from "./Member"; import { Base } from "./Base"; -import { ListItemNoteTypes, JSONListItem } from "../types"; -import { APIListItem, APIMentions, PATCHListItemBody } from "../Constants"; +import { ListItemNoteTypes, JSONListItem, RawMentions, RawListItem } from "../types"; +import { PATCHListItemBody } from "../Constants"; /** Represents an item of a "Lists" channel. */ export class ListItem extends Base { /** Raw data */ - _data: APIListItem; + _data: RawListItem; /** Guild id */ guildID: string; /** ID of the 'docs' channel. */ channelID: string; /** Content of the doc */ content: string; - mentions: APIMentions | null; + mentions: RawMentions | null; /** When the item was created. */ createdAt: Date | null; /** ID of the member who created the doc. */ @@ -43,7 +43,7 @@ export class ListItem extends Base { * @param data raw data. * @param client client. */ - constructor(data: APIListItem, client: Client){ + constructor(data: RawListItem, client: Client){ super(data.id, client); this._data = data; this.guildID = data.serverId; @@ -79,7 +79,7 @@ export class ListItem extends Base { }; } - protected override update(data: APIListItem): void { + protected override update(data: RawListItem): void { if (data.channelId !== undefined) { this.channelID = data.channelId; } diff --git a/lib/structures/Member.ts b/lib/structures/Member.ts index 0cd8e46b..ab78ebe7 100644 --- a/lib/structures/Member.ts +++ b/lib/structures/Member.ts @@ -10,8 +10,8 @@ import { User } from "./User"; import { Guild } from "./Guild"; import { BannedMember } from "./BannedMember"; import { SocialLink } from "./SocialLink"; -import { APIGuildMember, Permissions } from "../Constants"; -import { EditMemberOptions, JSONMember } from "../types"; +import { Permissions } from "../Constants"; +import { EditMemberOptions, JSONMember, RawMember } from "../types"; /** Represents a guild user. */ export class Member extends User { @@ -25,13 +25,13 @@ export class Member extends User { isOwner: boolean; /** Server ID. */ guildID: string; // member - private _data: APIGuildMember; + private _data: RawMember; /** * @param data raw data. * @param client client. * @param guildID ID of the guild. */ - constructor(data: APIGuildMember, client: Client, guildID: string) { + constructor(data: RawMember, client: Client, guildID: string) { super(data.user, client); this._data = data; this.roles = data.roleIds ?? null; @@ -53,7 +53,7 @@ export class Member extends User { }; } - protected override update(data: APIGuildMember): void { + protected override update(data: RawMember): void { if (data.isOwner !== undefined) { this.isOwner = data.isOwner ?? false; } diff --git a/lib/structures/Message.ts b/lib/structures/Message.ts index 08e921ff..628166e6 100644 --- a/lib/structures/Message.ts +++ b/lib/structures/Message.ts @@ -12,7 +12,6 @@ import { Guild } from "./Guild"; import { Base } from "./Base"; import { TextChannel } from "./TextChannel"; -import { APIChatMessage, APIEmbedOptions, APIMentions } from "../Constants"; import { JSONMessage, MessageAttachment, @@ -21,17 +20,20 @@ import { AnyTextableChannel, CreateMessageOptions, EditMessageOptions, - MessageEmbedOptions + MessageEmbedOptions, + RawMessage, + RawEmbed, + RawMentions } from "../types"; import { fetch } from "undici"; -import { APIURLSignature } from "guildedapi-types.ts/typings/payloads/v1/URLSignature"; +import { APIURLSignature } from "guildedapi-types.ts/v1"; /** Represents a guild message. */ export class Message extends Base { private _cachedChannel!: T extends AnyTextableChannel ? T : undefined; private _cachedGuild?: T extends Guild ? Guild : Guild | null; /** Raw data. */ - #data: APIChatMessage; + #data: RawMessage; /** Message type. */ type: string; /** ID of the server on which the message was sent. */ @@ -44,7 +46,7 @@ export class Message extends Base { * (min items 1; must have unique items true) */ hiddenLinkPreviewUrls?: Array; /** Array of message embed. */ - embeds?: Array | []; + embeds?: Array | []; /** The IDs of the message replied by the message. */ replyMessageIds: Array; /** If true, the message appears as private. */ @@ -52,7 +54,7 @@ export class Message extends Base { /** If true, the message didn't mention anyone. */ isSilent: boolean; /** object containing all mentioned users. */ - mentions: APIMentions; + mentions: RawMentions; /** ID of the message author. */ memberID: string; /** ID of the webhook used to send this message. (if sent by a webhook) */ @@ -76,7 +78,7 @@ export class Message extends Base { acknowledged: boolean; constructor( - data: APIChatMessage, + data: RawMessage, client: Client, params?: MessageConstructorParams ) { @@ -91,7 +93,7 @@ export class Message extends Base { this.replyMessageIds = data.replyMessageIds ?? []; this.isPrivate = data.isPrivate ?? false; this.isSilent = data.isSilent ?? false; - this.mentions = data.mentions as APIMentions ?? null; + this.mentions = data.mentions as RawMentions ?? null; this.createdAt = new Date(data.createdAt); this.editedTimestamp = data.updatedAt ? new Date(data.updatedAt) : null; this.memberID = data.createdBy; @@ -130,7 +132,7 @@ export class Message extends Base { }; } - protected override update(data: APIChatMessage): void { + protected override update(data: RawMessage): void { if (data.channelId !== undefined) { this.channelID = data.channelId; } diff --git a/lib/structures/ReactionInfo.ts b/lib/structures/ReactionInfo.ts index c2227698..32c98c55 100644 --- a/lib/structures/ReactionInfo.ts +++ b/lib/structures/ReactionInfo.ts @@ -8,7 +8,6 @@ import { Member } from "./Member"; import { Client } from "./Client"; import { - APIEmote, GatewayEvent_AnnouncementCommentReactionCreated, GatewayEvent_AnnouncementCommentReactionDeleted, GatewayEvent_AnnouncementReactionCreated, @@ -26,6 +25,7 @@ import { GatewayEvent_ForumTopicReactionCreated, GatewayEvent_ForumTopicReactionDeleted } from "../Constants"; +import { RawEmote } from "../types"; /** Default information every other reaction has. */ export class ReactionInfo { @@ -51,7 +51,7 @@ export class ReactionInfo { /** ID of the user who added the reaction. */ reactorID: string; /** Emote. */ - emoji: APIEmote; + emoji: RawEmote; /** * @param data raw data. * @param client client. diff --git a/lib/structures/GuildRole.ts b/lib/structures/Role.ts similarity index 92% rename from lib/structures/GuildRole.ts rename to lib/structures/Role.ts index d843b6ae..1822e069 100644 --- a/lib/structures/GuildRole.ts +++ b/lib/structures/Role.ts @@ -7,11 +7,11 @@ import { Base } from "./Base"; import { Client } from "./Client"; -import { JSONGuildRole } from "../types"; -import { APIGuildRole, PATCHGuildRolePermissionUpdateBody, Permissions } from "guildedapi-types.ts/v1"; +import { JSONGuildRole, RawRole } from "../types"; +import { PATCHGuildRolePermissionUpdateBody, Permissions } from "guildedapi-types.ts/v1"; -/** Class representing a guild role. */ -export class GuildRole extends Base { +/** Represents a Guild Role. */ +export class Role extends Base { /** ID of the guild */ guildID: string; /** Date of when the role was created. */ @@ -41,7 +41,7 @@ export class GuildRole extends Base { /** The bot user ID this role has been defined for. * Roles with this populated can only be deleted by kicking the bot */ botUserID: string | null; - constructor(data: APIGuildRole, client: Client) { + constructor(data: RawRole, client: Client) { super(data.id, client); this.guildID = data.serverId; this.createdAt = new Date(data.createdAt); @@ -78,7 +78,7 @@ export class GuildRole extends Base { }; } - protected override update(data: APIGuildRole): void { + protected override update(data: RawRole): void { if (data.serverId !== undefined) { this.guildID = data.serverId; } @@ -118,7 +118,7 @@ export class GuildRole extends Base { } /** Edit the role permission */ - async editPermission(options: PATCHGuildRolePermissionUpdateBody): Promise{ + async editPermission(options: PATCHGuildRolePermissionUpdateBody): Promise{ return this.client.rest.guilds.editRolePermission( this.guildID as string, this.id as number, diff --git a/lib/structures/SocialLink.ts b/lib/structures/SocialLink.ts index 6c3042f7..231156ae 100644 --- a/lib/structures/SocialLink.ts +++ b/lib/structures/SocialLink.ts @@ -8,27 +8,15 @@ import { Client } from "./Client"; import { User } from "./User"; -import { JSONSocialLink } from "../types"; -import { APISocialLink } from "guildedapi-types.ts/typings/payloads/v1/Users"; +import { JSONSocialLink, RawSocialLink } from "../types"; +import { SocialLinkType } from "../types/misc"; /** User's social link. */ export class SocialLink { /** Client. */ protected client: Client; /** Social media name `¯\_(ツ)_/¯` */ - type: "twitch" - | "bnet" - | "psn" - | "xbox" - | "steam" - | "origin" - | "youtube" - | "twitter" - | "facebook" - | "switch" - | "patreon" - | "roblox" - | "epic"; + type: SocialLinkType; /** ID of the user having this social linked to their profile. */ userID: string; /** The handle of the user within the external service */ @@ -42,7 +30,7 @@ export class SocialLink { * @param data raw data * @param client client */ - constructor(data: APISocialLink, client: Client) { + constructor(data: RawSocialLink, client: Client) { this.client = client; this.type = data.type; this.userID = data.userId; @@ -62,7 +50,7 @@ export class SocialLink { }; } - protected update(data: APISocialLink): void { + protected update(data: RawSocialLink): void { if (data.createdAt !== undefined) { this.createdAt = new Date(data.createdAt); } diff --git a/lib/structures/GuildSubscription.ts b/lib/structures/Subscription.ts similarity index 85% rename from lib/structures/GuildSubscription.ts rename to lib/structures/Subscription.ts index 1f564624..76c1bb6b 100644 --- a/lib/structures/GuildSubscription.ts +++ b/lib/structures/Subscription.ts @@ -7,11 +7,10 @@ import { Client } from "./Client"; import { Base } from "./Base"; -import { JSONGuildSubscription } from "../types"; -import { APIGuildSubscription } from "guildedapi-types.ts/v1"; +import { JSONGuildSubscription, RawSubscription } from "../types"; -/** Class representing a guild group. */ -export class GuildSubscription extends Base { +/** Represents a Guild Subscription. */ +export class Subscription extends Base { /** Type of the subscription */ type: string; /** ID of the guild */ @@ -25,7 +24,7 @@ export class GuildSubscription extends Base { /** The ISO 8601 timestamp that the subscription was created at */ createdAt: Date; - constructor(data: APIGuildSubscription, client: Client) { + constructor(data: RawSubscription, client: Client) { super(data.serverId, client); this.type = data.type; this.guildID = data.serverId; @@ -48,7 +47,7 @@ export class GuildSubscription extends Base { }; } - protected override update(data: APIGuildSubscription): void { + protected override update(data: RawSubscription): void { if (data.serverId !== undefined) { this.guildID = data.serverId; } diff --git a/lib/structures/TextChannel.ts b/lib/structures/TextChannel.ts index 105d91a0..b17509fb 100644 --- a/lib/structures/TextChannel.ts +++ b/lib/structures/TextChannel.ts @@ -10,19 +10,26 @@ import { Client } from "./Client"; import { Message } from "./Message"; import { GuildChannel } from "./GuildChannel"; import { Permission } from "./Permission"; -import { AnyTextableChannel, CreateMessageOptions, EditMessageOptions, JSONTextChannel } from "../types"; -import type { APIChatMessage, APIGuildChannel, PATCHChannelRolePermissionBody, POSTChannelRolePermissionBody } from "../Constants"; +import { + AnyTextableChannel, + CreateMessageOptions, + EditMessageOptions, + JSONTextChannel, + RawChannel, + RawMessage +} from "../types"; +import type { PATCHChannelRolePermissionBody, POSTChannelRolePermissionBody } from "../Constants"; import TypedCollection from "../util/TypedCollection"; /** Represents a guild channel where you can chat with others. */ export class TextChannel extends GuildChannel { /** Cached messages. */ - messages: TypedCollection>; + messages: TypedCollection>; /** * @param data raw data * @param client client */ - constructor(data: APIGuildChannel, client: Client){ + constructor(data: RawChannel, client: Client){ super(data, client); this.messages = new TypedCollection( Message, diff --git a/lib/structures/User.ts b/lib/structures/User.ts index e02b4210..44743497 100644 --- a/lib/structures/User.ts +++ b/lib/structures/User.ts @@ -7,8 +7,8 @@ import { Client } from "./Client"; import { Base } from "./Base"; -import { UserTypes, APIUser, APIGuildMember, APIUserSummary } from "../Constants"; -import { JSONUser } from "../types"; +import { UserTypes } from "../Constants"; +import { JSONUser, RawMember, RawPartialUser, RawUser } from "../types"; /** Represents a user. */ export class User extends Base { @@ -22,23 +22,26 @@ export class User extends Base { bannerURL: string | null; /** When the user account was created. */ createdAt: Date; // user. - /** If true, the user is a bot. */ + /** If true, the user is an app (aka: bot). */ + app: boolean; + /** @deprecated */ bot: boolean; /** * @param data raw data. * @param client client. */ - constructor(data: APIUser, client: Client){ + constructor(data: RawUser, client: Client) { super(data.id, client); - this.type = data.type ?? null; + this.type = data.type === "bot" ? "app" : (data.type === "user" ? "user" : null); this.username = data.name; this.createdAt = new Date(data.createdAt); this.avatarURL = data.avatar ?? null; this.bannerURL = data.banner ?? null; - if (!this.type) this.type = "user"; // as it is undefined when the user is a bot. - this.bot = this.type === "bot"; + if (!this.type) this.type = "user"; // as it is undefined when the user is an app. + this.app = this.type === "app"; + this.bot = this.type === "app"; // DEPRECATED (will be removed) this.update(data); } @@ -51,16 +54,16 @@ export class User extends Base { createdAt: this.createdAt, avatarURL: this.avatarURL, bannerURL: this.bannerURL, - bot: this.bot + bot: this.app }; } protected override update( - d: APIUser - | APIGuildMember - | APIUserSummary + d: RawUser + | RawMember + | RawPartialUser ): void { - const data = d as APIUser; + const data = d as RawUser; if (data.avatar !== undefined) { this.avatarURL = data.avatar ?? null; } @@ -77,7 +80,7 @@ export class User extends Base { this.username = data.name; } if (data.type !== undefined) { - this.type = data.type ?? null; + this.type = data.type === "bot" ? "app" : (data.type === "user" ? "user" : null); } } } diff --git a/lib/structures/UserClient.ts b/lib/structures/UserClient.ts index ad757fc6..ac56974a 100644 --- a/lib/structures/UserClient.ts +++ b/lib/structures/UserClient.ts @@ -7,8 +7,7 @@ import { Client } from "./Client"; import { User } from "./User"; -import { APIBotUser } from "../Constants"; -import { JSONUserClient } from "../types"; +import { RawAppUser, JSONUserClient } from "../types"; /** UserClient represents the logged bot's user. */ export class UserClient extends User { @@ -20,16 +19,16 @@ export class UserClient extends User { /** Boolean that shows if the user is a bot or not. * @defaultValue true */ - override bot: true; + override app: true; /** * @param data raw data. * @param client client. */ - constructor(data: APIBotUser, client: Client) { + constructor(data: RawAppUser, client: Client) { super(data, client); this.botID = data.botId; - this.type = "bot"; - this.bot = true; + this.type = "app"; + this.app = true; this.ownerID = data.createdBy; this.update(data); } @@ -43,7 +42,7 @@ export class UserClient extends User { }; } - protected override update(data: APIBotUser): void { + protected override update(data: RawAppUser): void { if (data.botId !== undefined) { this.botID = data.botId; } @@ -66,7 +65,7 @@ export class UserClient extends User { this.bannerURL = data.banner; } if (data.type !== undefined) { - this.type = data.type; + this.type = data.type === "bot" ? "app" : (data.type === "user" ? "user" : null); } } } diff --git a/lib/types/calendarEvent.d.ts b/lib/types/calendarEvent.d.ts deleted file mode 100644 index ac163bf3..00000000 --- a/lib/types/calendarEvent.d.ts +++ /dev/null @@ -1,91 +0,0 @@ - -// -// Created by Wade (@pakkographic) -// Copyright (c) 2024 DinographicPixels. All rights reserved. -// - -import { APICalendarEventRSVPStatuses } from "../Constants"; - -export interface CreateCalendarEventOptions { - /** The name of the event. */ - name: string; - /** The description of the event. */ - description?: string; - /** The location where the event will happen. */ - location?: string; - /** The event's starting date. */ - startsAt?: string; - /** Link a URL to the event. */ - url?: string; - /** Event card's color. */ - color?: number; - /** Does the event last all day? If passed with duration, - * duration will only be applied if it is an interval of minutes represented in days (e.g., duration: 2880) */ - isAllDay?: boolean; - /** Limit of member joining this event. */ - rsvpLimit?: number; - /** When `rsvpLimit` is set, users from the waitlist will be added as space becomes available in the event */ - autofillWaitlist?: boolean; - /** Event's duration in ms. */ - duration?: number; - /** If the event is private or not. */ - isPrivate?: boolean; - /** The role IDs to restrict the event to (min items 1; must have unique items true) */ - roleIDs?: Array; -} - -export interface EditCalendarEventOptions { - /** The name of the event. */ - name?: string; - /** The description of the event. */ - description?: string; - /** The location where the event will happen. */ - location?: string; - /** The event's starting date. */ - startsAt?: string; - /** Link a URL to the event. */ - url?: string; - /** Event card's color. */ - color?: number; - /** Does the event last all day? If passed with duration, duration will only be applied if it is an interval of - * minutes represented in days (e.g., duration: 2880) */ - isAllDay?: boolean; - /** Limit of member joining this event. */ - rsvpLimit?: number; - /** When `rsvpLimit` is set, users from the waitlist will be added as space becomes available in the event */ - autofillWaitlist?: boolean; - /** Event's duration in ms. */ - duration?: number; - /** If the event is private or not. */ - isPrivate?: boolean; - /** The role IDs to restrict the event to (min items 1; must have unique items true) */ - roleIDs?: Array; - cancellation?: { - /** The description of event cancellation (min length 1; max length 140) */ - description?: string; - }; -} - -export interface GetCalendarEventsFilter { - /** An ISO 8601 timestamp that will be used to filter out results for the current page */ - before?: string; - /** Order will be reversed when compared to before or when omitting this parameter altogether */ - after?: string; - /** Limit the number of calendar event that will output. (default `50`; min `1`; max `100`) */ - limit?: number; -} - -export interface EditCalendarRSVPOptions { - /** The status of the RSVP */ - status: APICalendarEventRSVPStatuses; -} - -export interface CreateCalendarCommentOptions { - /** The content of the comment. */ - content: string; -} - -export interface EditCalendarCommentOptions { - /** The new content of the comment. */ - content: string; -} diff --git a/lib/types/calendarEventComment.d.ts b/lib/types/calendarEventComment.d.ts deleted file mode 100644 index 9b5c6dc3..00000000 --- a/lib/types/calendarEventComment.d.ts +++ /dev/null @@ -1,9 +0,0 @@ - -// -// Created by Wade (@pakkographic) -// Copyright (c) 2024 DinographicPixels. All rights reserved. -// - -export interface ConstructorCalendarEventCommentOptions { - guildID?: string; -} diff --git a/lib/types/channel.d.ts b/lib/types/channel.d.ts deleted file mode 100644 index 430174ec..00000000 --- a/lib/types/channel.d.ts +++ /dev/null @@ -1,202 +0,0 @@ - -// -// Created by Wade (@pakkographic) -// Copyright (c) 2024 DinographicPixels. All rights reserved. -// - -import type { Message } from "../structures/Message"; -import { GuildChannel } from "../structures/GuildChannel"; -import { TextChannel } from "../structures/TextChannel"; -import { ForumChannel } from "../structures/ForumChannel"; -import { DocChannel } from "../structures/DocChannel"; -import { CalendarChannel } from "../structures/CalendarChannel"; -import { AnnouncementChannel } from "../structures/AnnouncementChannel"; -import type { APIEmbedField } from "guildedapi-types.ts/v1"; - -export interface CreateMessageOptions { - /** The content of the message (min length 1; max length 4000) */ - content?: string; - /** Links in content to prevent unfurling as a link preview when displaying in Guilded - * (min items 1; must have unique items true) */ - hiddenLinkPreviewURLs?: Array; - /** Embeds */ - embeds?: Array; - /** Message IDs to reply to (min items 1; max items 5) */ - replyMessageIDs?: Array; - /** If set, this message will not notify any mentioned users or roles (default `false`) */ - isSilent?: boolean; - /** If set, this message will only be seen by those mentioned or replied to */ - isPrivate?: boolean; -} - -export interface EditMessageOptions { - /** The content of the message (min length 1; max length 4000) */ - content?: string; - /** Links in content to prevent unfurling as a link preview when displaying in Guilded - * (min items 1; must have unique items true) */ - hiddenLinkPreviewURLs?: Array; - /** Embeds */ - embeds?: Array; - // /** Message IDs to reply to (min items 1; max items 5) */ - // replyMessageIds?: Array; - // /** If set, this message will not notify any mentioned users or roles (default `false`) */ - // isSilent?: boolean; - // /** If set, this message will only be seen by those mentioned or replied to */ - // isPrivate?: boolean; -} - -export interface MessageEmbedOptions { - /** Main header of the embed (max length 256) */ - title?: string; - /** Subtext of the embed (max length 2048) */ - description?: string; - /** URL to linkify the title field with (max length 1024; regex ^(?!attachment)) */ - url?: string; - /** Embed's color, decimal number (base 16), - * - * To convert to HEX use: `parseInt("HEX", 16)`, - * don't forget to remove the hashtag. - */ - color?: number ; - /** A small section at the bottom of the embed */ - footer?: { - /** URL of a small image to put in the footer (max length 1024) */ - iconURL?: string; - /** Text of the footer (max length 2048) */ - text: string; - }; - /** A timestamp to put in the footer */ - timestamp?: string; - /** An image to the right of the embed's content */ - thumbnail?: { - /** URL of the image (max length 1024) */ - url?: string; - }; - /** The main picture to associate with the embed */ - image?: { - /** URL of the image (max length 1024) */ - url?: string; - }; - /** A small section above the title of the embed */ - author?: { - /** Name of the author (max length 256) */ - name?: string; - /** URL to linkify the author's name field (max length 1024; regex ^(?!attachment)) */ - url?: string; - /** URL of a small image to display to the left of the author's name (max length 1024) */ - iconURL?: string; - }; - /** Table-like cells to add to the embed (max items 25) */ - fields?: Array; -} - -export interface CreateChannelOptions { - /** Description of the channel. */ - description?: string; - /** Set the channel as public or not. */ - isPublic?: boolean; - /** Place the channel in a specific category. */ - categoryID?: number; - /** Place the channel in a guild group. */ - groupID?: string; -} - -export interface EditChannelOptions { - /** The name of the channel or thread (min length 1; max length 100) */ - name?: string; - /** The description of the channel. Not applicable to threads (min length 1; max length 512) */ - description?: string; - /** Whether the channel can be accessed from users who are not member of the server. Not applicable to threads */ - isPublic?: boolean; -} - -export interface GetChannelMessagesFilter { - /** An ISO 8601 timestamp that will be used to filter out results for the current page */ - before?: string; - /** Order will be reversed when compared to before or when omitting this parameter altogether */ - after?: string; - /** The max size of the page (default `50`; min `1`; max `100`) */ - limit?: number; - /** Whether to include private messages between all users in response (default `false`) */ - includePrivate?: boolean; -} - -export type PossiblyUncachedMessage = Message | { - /** The ID of the message. */ - id: string; - /** ID of the server on which the message was sent. */ - guildID: string; - /** ID of the channel where the message was sent. */ - channelID: string; - /** When the message was deleted. */ - deletedAt: Date; - /** If true, the message is private. */ - isPrivate: boolean | null; -}; - -export interface ChannelMessageReactionBulkRemove { - /** The ID of the server */ - guildID: string; - /** The ID of the channel */ - channelID: string; - /** The ID of the message */ - messageID: string; - /** The ID of the user who deleted this reaction */ - deletedBy: string; - /** The count of reactions that were removed */ - count: number; - /** If present, only reactions of this emote were bulk removed from the message */ - emote: APIEmote | null; -} - -export interface ChannelRolePermission { - permission: Array; - /** The ISO 8601 timestamp that the permission override was created at */ - createdAt: string; - /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ - updatedAt?: string; - /** The ID of the role */ - roleID: number; - /** The ID of the channel */ - channelID: string; -} - -export interface ChannelUserPermission { - permission: Array; - /** The ISO 8601 timestamp that the permission override was created at */ - createdAt: string; - /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ - updatedAt?: string; - /** The ID of the role */ - userID: number; - /** The ID of the channel */ - channelID: string; -} - -export interface ChannelCategoryUserPermission { - permission: Array; - /** The ISO 8601 timestamp that the permission override was created at */ - createdAt: string; - /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ - updatedAt?: string; - /** The ID of the role */ - userID: number; - /** The ID of the channel */ - categoryID: string; -} - -export interface ChannelCategoryRolePermission { - permission: Array; - /** The ISO 8601 timestamp that the permission override was created at */ - createdAt: string; - /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ - updatedAt?: string; - /** The ID of the role */ - roleID: number; - /** The ID of the channel */ - categoryID: string; -} - -export type AnyTextableChannel = TextChannel; -export type AnyChannel = GuildChannel | TextChannel | ForumChannel | DocChannel | CalendarChannel | AnnouncementChannel; -export type AnyGuildChannel = Exclude; diff --git a/lib/types/channels.d.ts b/lib/types/channels.d.ts index e69de29b..7c90d672 100644 --- a/lib/types/channels.d.ts +++ b/lib/types/channels.d.ts @@ -0,0 +1,498 @@ + +// +// Created by Wade (@pakkographic) +// Copyright (c) 2024 DinographicPixels. All rights reserved. +// + +import type { Message } from "../structures/Message"; +import { GuildChannel } from "../structures/GuildChannel"; +import { TextChannel } from "../structures/TextChannel"; +import { ForumChannel } from "../structures/ForumChannel"; +import { DocChannel } from "../structures/DocChannel"; +import { CalendarChannel } from "../structures/CalendarChannel"; +import { AnnouncementChannel } from "../structures/AnnouncementChannel"; +import type { + APIChatMessage, + APIEmbedField, + APIEmbedOptions, + APIForumTopic, + APIForumTopicSummary, + APIGuild, + APIGuildCategory, + APIGuildChannel, + APIGuildGroup, + APIGuildMember, + APIGuildRole, + APIGuildSubscription, + APIUser, + APIAnnouncement, + APIAnnouncementComment, + APIAnnouncementCommentReaction, + APIUserSummary, + APICalendarEventRSVPStatuses, + APIMentions, + APICalendarEvent, + APICalendarEventComment, + APICalendarEventCommentReaction, + APIDoc, + APICalendarEventRSVP, + APIForumTopicComment, + APIGuildMemberBan, + APIListItem, + APIListItemSummary, + APIBotUser +} from "guildedapi-types.ts/v1"; +import { APIDocComment } from "guildedapi-types.ts/typings/payloads/v1/Docs"; +import { APIDocCommentReaction, APIForumTopicCommentReaction, APIForumTopicReaction } from "guildedapi-types.ts/typings/payloads/v1/Reactions"; +import { APIGuildMemberSummary } from "guildedapi-types.ts/typings/payloads/v1/Members"; +import { APIListItemNote, APIListItemNoteSummary } from "guildedapi-types.ts/typings/payloads/v1/ListItems"; +import { APIEmote } from "guildedapi-types.ts/typings/payloads/v1/Emotes"; +import { APISocialLink } from "guildedapi-types.ts/typings/payloads/v1/Users"; + +export type RawChannel = APIGuildChannel; +export type RawAnnouncement = APIAnnouncement; +export type RawAnnouncementComment = APIAnnouncementComment; +export type RawAnnouncementCommentReaction = APIAnnouncementCommentReaction; +export type RawCalendarEvent = APICalendarEvent; +export type RawCalendarRSVP = APICalendarEventRSVP; +export type RawCalendarComment = APICalendarEventComment; +export type RawCalendarCommentReaction = APICalendarEventCommentReaction; +export type CalendarRSVPStatus = APICalendarEventRSVPStatuses; +export type RawMessage = APIChatMessage; +export type RawForumThread = APIForumTopic; +export type RawPartialForumThread = APIForumTopicSummary; +export type RawForumThreadReaction = APIForumTopicReaction; +export type RawForumThreadComment = APIForumTopicComment; +export type RawForumThreadCommentReaction = APIForumTopicCommentReaction; +export type RawDoc = APIDoc; +export type RawDocComment = APIDocComment; +export type RawDocCommentReaction = APIDocCommentReaction; +export type RawListItem = APIListItem; +export type RawPartialListItem = APIListItemSummary; +export type RawListItemNote = APIListItemNote; +export type RawPartialListItemNote = APIListItemNoteSummary; +// TODO: has to move +export type RawGuild = APIGuild; +export type RawGroup = APIGuildGroup; +export type RawCategory = APIGuildCategory; +export type RawMember = APIGuildMember; +export type RawMemberBan = APIGuildMemberBan; +export type RawPartialMember = APIGuildMemberSummary; +export type RawRole = APIGuildRole; +export type RawSubscription = APIGuildSubscription; +export type RawUser = APIUser; +export type RawPartialUser = APIUserSummary; +export type RawAppUser = APIBotUser; +export type RawEmbed = APIEmbedOptions; +export type RawMentions = APIMentions; +export type RawEmote = APIEmote; +export type RawSocialLink = APISocialLink; + +export interface MessageConstructorParams { + originals?: { + responseID?: string | null; + triggerID?: string | null; + }; + acknowledged?: boolean; +} + +export interface MessageAttachment { + originalURL: string; + signedURL: string | null; + arrayBuffer: ArrayBuffer | null; + isImage: boolean; + fileExtension: string; +} + +export interface MessageOriginals { + triggerMessage: Message | null; + originalResponse: Message | null; +} + +export interface CreateMessageOptions { + /** The content of the message (min length 1; max length 4000) */ + content?: string; + /** Links in content to prevent unfurling as a link preview when displaying in Guilded + * (min items 1; must have unique items true) */ + hiddenLinkPreviewURLs?: Array; + /** Embeds */ + embeds?: Array; + /** Message IDs to reply to (min items 1; max items 5) */ + replyMessageIDs?: Array; + /** If set, this message will not notify any mentioned users or roles (default `false`) */ + isSilent?: boolean; + /** If set, this message will only be seen by those mentioned or replied to */ + isPrivate?: boolean; +} + +export interface EditMessageOptions { + /** The content of the message (min length 1; max length 4000) */ + content?: string; + /** Links in content to prevent unfurling as a link preview when displaying in Guilded + * (min items 1; must have unique items true) */ + hiddenLinkPreviewURLs?: Array; + /** Embeds */ + embeds?: Array; + // /** Message IDs to reply to (min items 1; max items 5) */ + // replyMessageIds?: Array; + // /** If set, this message will not notify any mentioned users or roles (default `false`) */ + // isSilent?: boolean; + // /** If set, this message will only be seen by those mentioned or replied to */ + // isPrivate?: boolean; +} + +export interface MessageEmbedOptions { + /** Main header of the embed (max length 256) */ + title?: string; + /** Subtext of the embed (max length 2048) */ + description?: string; + /** URL to linkify the title field with (max length 1024; regex ^(?!attachment)) */ + url?: string; + /** Embed's color, decimal number (base 16), + * + * To convert to HEX use: `parseInt("HEX", 16)`, + * don't forget to remove the hashtag. + */ + color?: number ; + /** A small section at the bottom of the embed */ + footer?: { + /** URL of a small image to put in the footer (max length 1024) */ + iconURL?: string; + /** Text of the footer (max length 2048) */ + text: string; + }; + /** A timestamp to put in the footer */ + timestamp?: string; + /** An image to the right of the embed's content */ + thumbnail?: { + /** URL of the image (max length 1024) */ + url?: string; + }; + /** The main picture to associate with the embed */ + image?: { + /** URL of the image (max length 1024) */ + url?: string; + }; + /** A small section above the title of the embed */ + author?: { + /** Name of the author (max length 256) */ + name?: string; + /** URL to linkify the author's name field (max length 1024; regex ^(?!attachment)) */ + url?: string; + /** URL of a small image to display to the left of the author's name (max length 1024) */ + iconURL?: string; + }; + /** Table-like cells to add to the embed (max items 25) */ + fields?: Array; +} + +export interface CreateChannelOptions { + /** Description of the channel. */ + description?: string; + /** Set the channel as public or not. */ + isPublic?: boolean; + /** Place the channel in a specific category. */ + categoryID?: number; + /** Place the channel in a guild group. */ + groupID?: string; +} + +export interface EditChannelOptions { + /** The name of the channel or thread (min length 1; max length 100) */ + name?: string; + /** The description of the channel. Not applicable to threads (min length 1; max length 512) */ + description?: string; + /** Whether the channel can be accessed from users who are not member of the server. Not applicable to threads */ + isPublic?: boolean; +} + +export interface GetChannelMessagesFilter { + /** An ISO 8601 timestamp that will be used to filter out results for the current page */ + before?: string; + /** Order will be reversed when compared to before or when omitting this parameter altogether */ + after?: string; + /** The max size of the page (default `50`; min `1`; max `100`) */ + limit?: number; + /** Whether to include private messages between all users in response (default `false`) */ + includePrivate?: boolean; +} + +export type PossiblyUncachedMessage = Message | { + /** The ID of the message. */ + id: string; + /** ID of the server on which the message was sent. */ + guildID: string; + /** ID of the channel where the message was sent. */ + channelID: string; + /** When the message was deleted. */ + deletedAt: Date; + /** If true, the message is private. */ + isPrivate: boolean | null; +}; + +export interface ChannelMessageReactionBulkRemove { + /** The ID of the server */ + guildID: string; + /** The ID of the channel */ + channelID: string; + /** The ID of the message */ + messageID: string; + /** The ID of the user who deleted this reaction */ + deletedBy: string; + /** The count of reactions that were removed */ + count: number; + /** If present, only reactions of this emote were bulk removed from the message */ + emote: RawEmote | null; +} + +export interface ChannelRolePermission { + permission: Array; + /** The ISO 8601 timestamp that the permission override was created at */ + createdAt: string; + /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ + updatedAt?: string; + /** The ID of the role */ + roleID: number; + /** The ID of the channel */ + channelID: string; +} + +export interface ChannelUserPermission { + permission: Array; + /** The ISO 8601 timestamp that the permission override was created at */ + createdAt: string; + /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ + updatedAt?: string; + /** The ID of the role */ + userID: number; + /** The ID of the channel */ + channelID: string; +} + +export interface ChannelCategoryUserPermission { + permission: Array; + /** The ISO 8601 timestamp that the permission override was created at */ + createdAt: string; + /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ + updatedAt?: string; + /** The ID of the role */ + userID: number; + /** The ID of the channel */ + categoryID: string; +} + +export interface ChannelCategoryRolePermission { + permission: Array; + /** The ISO 8601 timestamp that the permission override was created at */ + createdAt: string; + /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ + updatedAt?: string; + /** The ID of the role */ + roleID: number; + /** The ID of the channel */ + categoryID: string; +} + +export type AnyTextableChannel = TextChannel; +export type AnyChannel = GuildChannel | TextChannel | ForumChannel | DocChannel | CalendarChannel | AnnouncementChannel; +export type AnyGuildChannel = Exclude; + +// FORUM CHANNEL +export interface CreateForumThreadOptions { + /** Forum thread's title. */ + title: string; + /** Content of the thread. */ + content: string; +} + +export interface EditForumThreadOptions { + /** New forum thread's title. */ + title?: string; + /** New content of the thread. */ + content?: string; +} + +export interface GetForumThreadsFilter { + /** An ISO 8601 timestamp that will be used to filter out results for the current page */ + before?: string; + /** Limit the number of threads that will output. */ + limit?: number; +} + + +export interface ConstructorForumThreadOptions { + /** ID of the forum channel's parent guild. */ + guildID?: string | null; + /** ID of the "Forums" channel containing this ForumThreadComment. */ + channelID?: string | null; +} + +export interface CreateForumCommentOptions { + /** Content of the comment. */ + content: string; +} + +export interface EditForumCommentOptions { + /** New content of the comment. */ + content?: string; +} + +export interface ConstructorForumThreadOptions { + /** ID of the forum channel's parent guild. */ + guildID?: string | null; + /** ID of the "Forums" channel containing this ForumThreadComment. */ + channelID?: string | null; +} + +export interface CreateForumCommentOptions { + /** Content of the comment. */ + content: string; +} + +export interface EditForumCommentOptions { + /** New content of the comment. */ + content?: string; +} + +export interface ConstructorForumThreadOptions { + /** ID of the forum channel's parent guild. */ + guildID?: string | null; + /** ID of the "Forums" channel containing this ForumThreadComment. */ + channelID?: string | null; +} + +export interface CreateForumCommentOptions { + /** Content of the comment. */ + content: string; +} + +export interface EditForumCommentOptions { + /** New content of the comment. */ + content?: string; +} + +// DOC CHANNEL +export interface CreateDocOptions { + /** Title of the doc. */ + title: string; + /** Content of the doc. */ + content: string; +} + +export interface EditDocOptions { + /** New doc title. */ + title?: string; + /** New doc content. */ + content?: string; +} + +export interface GetDocsFilter { + /** An ISO 8601 timestamp that will be used to filter out results for the current page */ + before?: string; + /** The max size of the page (default `25`; min `1`; max `100`) */ + limit?: number; +} + +export interface ConstructorDocCommentOptions { + guildID?: string; +} + +export interface CreateDocCommentOptions { + /** The content of the doc comment (min length 1; max length 10000) */ + content: string; +} + +export interface EditDocCommentOptions { + /** The content of the doc comment (min length 1; max length 10000) */ + content: string; +} + +// CALENDAR CHANNEL +export interface CreateCalendarEventOptions { + /** The name of the event. */ + name: string; + /** The description of the event. */ + description?: string; + /** The location where the event will happen. */ + location?: string; + /** The event's starting date. */ + startsAt?: string; + /** Link a URL to the event. */ + url?: string; + /** Event card's color. */ + color?: number; + /** Does the event last all day? If passed with duration, + * duration will only be applied if it is an interval of minutes represented in days (e.g., duration: 2880) */ + isAllDay?: boolean; + /** Limit of member joining this event. */ + rsvpLimit?: number; + /** When `rsvpLimit` is set, users from the waitlist will be added as space becomes available in the event */ + autofillWaitlist?: boolean; + /** Event's duration in ms. */ + duration?: number; + /** If the event is private or not. */ + isPrivate?: boolean; + /** The role IDs to restrict the event to (min items 1; must have unique items true) */ + roleIDs?: Array; +} + +export interface EditCalendarEventOptions { + /** The name of the event. */ + name?: string; + /** The description of the event. */ + description?: string; + /** The location where the event will happen. */ + location?: string; + /** The event's starting date. */ + startsAt?: string; + /** Link a URL to the event. */ + url?: string; + /** Event card's color. */ + color?: number; + /** Does the event last all day? If passed with duration, duration will only be applied if it is an interval of + * minutes represented in days (e.g., duration: 2880) */ + isAllDay?: boolean; + /** Limit of member joining this event. */ + rsvpLimit?: number; + /** When `rsvpLimit` is set, users from the waitlist will be added as space becomes available in the event */ + autofillWaitlist?: boolean; + /** Event's duration in ms. */ + duration?: number; + /** If the event is private or not. */ + isPrivate?: boolean; + /** The role IDs to restrict the event to (min items 1; must have unique items true) */ + roleIDs?: Array; + cancellation?: { + /** The description of event cancellation (min length 1; max length 140) */ + description?: string; + }; +} + +export interface GetCalendarEventsFilter { + /** An ISO 8601 timestamp that will be used to filter out results for the current page */ + before?: string; + /** Order will be reversed when compared to before or when omitting this parameter altogether */ + after?: string; + /** Limit the number of calendar event that will output. (default `50`; min `1`; max `100`) */ + limit?: number; +} + +export interface EditCalendarRSVPOptions { + /** The status of the RSVP */ + status: CalendarRSVPStatus; +} + +export interface CreateCalendarCommentOptions { + /** The content of the comment. */ + content: string; +} + +export interface EditCalendarCommentOptions { + /** The new content of the comment. */ + content: string; +} + +export interface ConstructorCalendarCommentOptions { + guildID?: string; +} + diff --git a/lib/types/doc.d.ts b/lib/types/doc.d.ts deleted file mode 100644 index de5ac3c7..00000000 --- a/lib/types/doc.d.ts +++ /dev/null @@ -1,26 +0,0 @@ - -// -// Created by Wade (@pakkographic) -// Copyright (c) 2024 DinographicPixels. All rights reserved. -// - -export interface CreateDocOptions { - /** Title of the doc. */ - title: string; - /** Content of the doc. */ - content: string; -} - -export interface EditDocOptions { - /** New doc title. */ - title?: string; - /** New doc content. */ - content?: string; -} - -export interface GetDocsFilter { - /** An ISO 8601 timestamp that will be used to filter out results for the current page */ - before?: string; - /** The max size of the page (default `25`; min `1`; max `100`) */ - limit?: number; -} diff --git a/lib/types/docComment.d.ts b/lib/types/docComment.d.ts deleted file mode 100644 index 3c265a20..00000000 --- a/lib/types/docComment.d.ts +++ /dev/null @@ -1,19 +0,0 @@ - -// -// Created by Wade (@pakkographic) -// Copyright (c) 2024 DinographicPixels. All rights reserved. -// - -export interface ConstructorDocCommentOptions { - guildID?: string; -} - -export interface CreateDocCommentOptions { - /** The content of the doc comment (min length 1; max length 10000) */ - content: string; -} - -export interface EditDocCommentOptions { - /** The content of the doc comment (min length 1; max length 10000) */ - content: string; -} diff --git a/lib/types/events.d.ts b/lib/types/events.d.ts index 5a2223a8..59ae78da 100644 --- a/lib/types/events.d.ts +++ b/lib/types/events.d.ts @@ -13,7 +13,13 @@ import type { UserStatusCreate, UserStatusDelete } from "./types"; -import { AnyChannel, AnyTextableChannel, ChannelMessageReactionBulkRemove, PossiblyUncachedMessage } from "./channel"; +import { + AnyChannel, + AnyTextableChannel, + ChannelMessageReactionBulkRemove, + PossiblyUncachedMessage, + RawAppUser +} from "./channels"; import type { AnyPacket, WelcomePacket } from "./gateway-raw"; import { JSONAnnouncement, @@ -53,14 +59,13 @@ import { CalendarChannel } from "../structures/CalendarChannel"; import { DocChannel } from "../structures/DocChannel"; import { GuildChannel } from "../structures/GuildChannel"; import { Channel } from "../structures/Channel"; -import { CalendarEventComment } from "../structures/CalendarEventComment"; +import { CalendarComment } from "../structures/CalendarComment"; import { DocComment } from "../structures/DocComment"; import { Announcement } from "../structures/Announcement"; import type { AnnouncementComment } from "../structures/AnnouncementComment"; -import { GuildGroup } from "../structures/GuildGroup"; -import { GuildRole } from "../structures/GuildRole"; -import { GuildCategory } from "../structures/GuildCategory"; -import type { APIBotUser } from "guildedapi-types.ts/v1"; +import { Group } from "../structures/Group"; +import { Role } from "../structures/Role"; +import { Category } from "../structures/Category"; /** Every client events. */ export interface ClientEvents { @@ -165,17 +170,17 @@ export interface ClientEvents { /** @event Emitted when the client leaves a guild. */ guildDelete: [GuildDeleteInfo: GuildDeleteInfo]; /** @event Emitted when a guild group is created. */ - guildGroupCreate: [guildGroup: GuildGroup]; + guildGroupCreate: [guildGroup: Group]; /** @event Emitted when a guild group is updated. */ - guildGroupUpdate: [guildGroup: GuildGroup, oldGuildGroup: JSONGuildGroup | null]; + guildGroupUpdate: [guildGroup: Group, oldGuildGroup: JSONGuildGroup | null]; /** @event Emitted when a guild group is deleted. */ - guildGroupDelete: [guildGroup: GuildGroup]; + guildGroupDelete: [guildGroup: Group]; /** @event Emitted when a guild role is created. */ - guildRoleCreate: [role: GuildRole]; + guildRoleCreate: [role: Role]; /** @event Emitted when a guild role is updated. */ - guildRoleUpdate: [role: GuildRole, oldRole: JSONGuildRole | null]; + guildRoleUpdate: [role: Role, oldRole: JSONGuildRole | null]; /** @event Emitted when a guild role is deleted. */ - guildRoleDelete: [role: GuildRole]; + guildRoleDelete: [role: Role]; /** @event Emitted when a doc is created. */ docCreate: [Doc: Doc]; /** @event Emitted when a doc is edited. */ @@ -201,11 +206,11 @@ export interface ClientEvents { /** @event Emitted when an event RSVP is deleted. */ calendarEventRsvpDelete: [CalendarRSVP: CalendarEventRSVP]; /** @event Emitted when a calendar event comment is created. */ - calendarCommentCreate: [comment: CalendarEventComment]; + calendarCommentCreate: [comment: CalendarComment]; /** @event Emitted when a calendar event comment is edited. */ - calendarCommentUpdate: [comment: CalendarEventComment, oldComment: JSONCalendarEventComment | null]; + calendarCommentUpdate: [comment: CalendarComment, oldComment: JSONCalendarEventComment | null]; /** @event Emitted when a calendar event comment is deleted. */ - calendarCommentDelete: [comment: CalendarEventComment]; + calendarCommentDelete: [comment: CalendarComment]; /** @event Emitted when a list item is created. */ listItemCreate: [item: ListItem]; /** @event Emitted when a list item is edited. */ @@ -237,11 +242,11 @@ export interface ClientEvents { /** @event Emitted when a user delete their user status. */ userStatusDelete: [userStatus: UserStatusDelete]; /** @event Emitted when a category is created. */ - guildCategoryCreate: [category: GuildCategory]; + guildCategoryCreate: [category: Category]; /** @event Emitted when a category is updated. */ - guildCategoryUpdate: [category: GuildCategory]; + guildCategoryUpdate: [category: Category]; /** @event Emitted when a category is deleted. */ - guildCategoryDelete: [category: GuildCategory]; + guildCategoryDelete: [category: Category]; /** @event Emitted on process exit. */ exit: [message: string]; } @@ -259,7 +264,7 @@ export interface WebsocketEvents { /** @event Emitted when a packet is sent. */ GATEWAY_PACKET: [packet: AnyPacket]; /** @event Emitted when connected to gateway. */ - GATEWAY_WELCOME: [data: APIBotUser]; + GATEWAY_WELCOME: [data: RawAppUser]; /** @event Emitted when connected to gateway. */ GATEWAY_WELCOME_PACKET: [packet: WelcomePacket]; /** @event Emitted when a packet isn't recognized. */ diff --git a/lib/types/forumThread.d.ts b/lib/types/forumThread.d.ts deleted file mode 100644 index a4231b80..00000000 --- a/lib/types/forumThread.d.ts +++ /dev/null @@ -1,26 +0,0 @@ - -// -// Created by Wade (@pakkographic) -// Copyright (c) 2024 DinographicPixels. All rights reserved. -// - -export interface CreateForumThreadOptions { - /** Forum thread's title. */ - title: string; - /** Content of the thread. */ - content: string; -} - -export interface EditForumThreadOptions { - /** New forum thread's title. */ - title?: string; - /** New content of the thread. */ - content?: string; -} - -export interface GetForumThreadsFilter { - /** An ISO 8601 timestamp that will be used to filter out results for the current page */ - before?: string; - /** Limit the number of threads that will output. */ - limit?: number; -} diff --git a/lib/types/forumThreadComment.d.ts b/lib/types/forumThreadComment.d.ts deleted file mode 100644 index 10749042..00000000 --- a/lib/types/forumThreadComment.d.ts +++ /dev/null @@ -1,22 +0,0 @@ - -// -// Created by Wade (@pakkographic) -// Copyright (c) 2024 DinographicPixels. All rights reserved. -// - -export interface ConstructorForumThreadOptions { - /** ID of the forum channel's parent guild. */ - guildID?: string | null; - /** ID of the "Forums" channel containing this ForumThreadComment. */ - channelID?: string | null; -} - -export interface CreateForumCommentOptions { - /** Content of the comment. */ - content: string; -} - -export interface EditForumCommentOptions { - /** New content of the comment. */ - content?: string; -} diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts index a367eaac..90de8436 100644 --- a/lib/types/index.d.ts +++ b/lib/types/index.d.ts @@ -1,19 +1,9 @@ -export * from "./calendarEvent"; -export * from "./calendarEventComment"; -export * from "./channel"; export * from "./channels"; export * from "./client"; -export * from "./doc"; -export * from "./docComment"; export * from "./events"; -export * from "./forumThread"; -export * from "./forumThreadComment"; export * from "./gateway-raw"; export * from "./guilds"; export * from "./json"; -export * from "./listItem"; -export * from "./message"; export * from "./request-handler"; export * from "./types"; -export * from "./webhook"; export * from "./webhooks"; diff --git a/lib/types/json.d.ts b/lib/types/json.d.ts index e5cedde8..1ac2b4b4 100644 --- a/lib/types/json.d.ts +++ b/lib/types/json.d.ts @@ -4,11 +4,20 @@ // Copyright (c) 2024 DinographicPixels. All rights reserved. // +import { + RawCalendarEvent, + RawCalendarComment, + RawDocComment, + RawEmbed, + RawMentions, + CalendarRSVPStatus +} from "./channels"; import { Member } from "../structures/Member"; import { User } from "../structures/User"; import { Guild } from "../structures/Guild"; import { UserTypes } from "../Constants"; -import { APICalendarEvent, APICalendarEventComment, Permissions } from "guildedapi-types.ts/v1"; +import { Permissions } from "guildedapi-types.ts/v1"; +import { SocialLinkType } from "guildedapi-types.ts/typings/schemas/v1"; export interface JSONBase { // createdAt: number; @@ -28,7 +37,7 @@ export interface JSONMessage extends JSONBase { * (min items 1; must have unique items true) */ hiddenLinkPreviewUrls?: Array; /** Array of message embed. */ - embeds?: Array | []; + embeds?: Array | []; /** The IDs of the message replied by the message. */ replyMessageIds: Array; /** If true, the message appears as private. */ @@ -36,7 +45,7 @@ export interface JSONMessage extends JSONBase { /** If true, the message didn't mention anyone. */ isSilent: boolean; /** object containing all mentioned users. */ - mentions: APIMentions; + mentions: RawMentions; /** ID of the message author. */ memberID: string; /** ID of the webhook used to send this message. (if sent by a webhook) */ @@ -65,7 +74,7 @@ export interface JSONForumThreadComment extends JSONBase { /** ID of the forum channel containing this thread. */ channelID: string; /** Mentions in this thread comment. */ - mentions: APIMentions | null; + mentions: RawMentions | null; } export interface JSONDoc extends JSONBase { @@ -78,7 +87,7 @@ export interface JSONDoc extends JSONBase { /** Content of the doc */ content: string; /** Doc mentions */ - mentions: APIMentions; + mentions: RawMentions; /** When the doc has been created. */ createdAt: Date; /** ID of the member who created this doc. */ @@ -155,7 +164,7 @@ export type AnyJSONChannel = JSONTextChannel | JSONDocChannel | JSONForumChannel export interface JSONCalendarEvent extends JSONBase { /** Raw data */ - data: APICalendarEvent; + data: RawCalendarEvent; /** Guild/server ID */ guildID: string; /** ID of the channel the event was created on. */ @@ -179,13 +188,13 @@ export interface JSONCalendarEvent extends JSONBase { /** If true, this event is private. */ isPrivate: boolean; /** Mentions in this calendar event. */ - mentions: APIMentions | null; + mentions: RawMentions | null; /** When the event was created. */ createdAt: Date | null; /** ID of the owner of this event. */ ownerID: string; /** Details about event cancelation (if canceled) */ - cancellation: APICalendarEvent["cancellation"] | null; + cancellation: RawCalendarEvent["cancellation"] | null; /** Cached RSVPS. */ rsvps: Array; } @@ -198,7 +207,7 @@ export interface JSONCalendarEventRSVP extends JSONBase { /** ID of the entity assigned to this Event RSVP. */ entityID: string; /** Status of the RSVP */ - status: APICalendarEventRSVPStatuses; + status: CalendarRSVPStatus; /** When the RSVP was created. */ createdAt: Date | null; /** ID of the user who created this RSVP. */ @@ -243,7 +252,7 @@ export interface JSONForumThread extends JSONBase { /** Content of the thread */ content: string; /** Thread mentions */ - mentions: APIMentions | null; + mentions: RawMentions | null; /** Cached comments. */ comments: Array; /** If true, the thread is locked. */ @@ -342,7 +351,7 @@ export interface JSONListItem extends JSONBase { channelID: string; /** Content of the doc */ content: string; - mentions: APIMentions | null; + mentions: RawMentions | null; /** When the item was created. */ createdAt: Date | null; /** ID of the member who created the doc. */ @@ -363,7 +372,7 @@ export interface JSONListItem extends JSONBase { export interface JSONCalendarEventComment extends JSONBase { /** Raw data */ - data: APICalendarEventComment; + data: RawCalendarComment; /** The content of the comment. */ content: string; /** The ISO 8601 timestamp that this comment was created at. */ @@ -380,19 +389,7 @@ export interface JSONCalendarEventComment extends JSONBase { export interface JSONSocialLink { /** Social media name. */ - type: "twitch" - | "bnet" - | "psn" - | "xbox" - | "steam" - | "origin" - | "youtube" - | "twitter" - | "facebook" - | "switch" - | "patreon" - | "roblox" - | "epic"; + type: SocialLinkType | `${SocialLinkType}`; /** ID of the user having this social linked to their profile. */ userID: string; /** The handle of the user within the external service */ @@ -405,7 +402,7 @@ export interface JSONSocialLink { export interface JSONDocComment extends JSONBase { /** Raw data */ - raw: APIDocComment; + raw: RawDocComment; /** The content of the comment. */ content: string; /** The date of the comment's creation. */ @@ -419,7 +416,7 @@ export interface JSONDocComment extends JSONBase { /** The ID of the doc the comment is in. */ docID: number; /** Mentions. */ - mentions: APIMentions | null; + mentions: RawMentions | null; /** ID of the guild, if provided. */ guildID: string | null; } @@ -436,7 +433,7 @@ export interface JSONAnnouncement extends JSONBase { /** The announcement's content */ content: string; /** Mentions. */ - mentions: APIMentions | null; + mentions: RawMentions | null; /** The announcement's title. */ title: string; } @@ -455,7 +452,7 @@ export interface JSONAnnouncementComment extends JSONBase { /** ID of the parent announcement. */ announcementID: string; /** Mentions */ - mentions: APIMentions | null; + mentions: RawMentions | null; /** ID of the guild, if received. */ guildID: string | null; } diff --git a/lib/types/listItem.d.ts b/lib/types/listItem.d.ts deleted file mode 100644 index a66f033f..00000000 --- a/lib/types/listItem.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -/* eslint-disable unicorn/no-empty-file */ -// empty. diff --git a/lib/types/message.d.ts b/lib/types/message.d.ts deleted file mode 100644 index bfe7ec78..00000000 --- a/lib/types/message.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { AnyTextableChannel } from "./channel"; -import { Message } from "../structures/Message"; - -export interface MessageConstructorParams { - originals?: { - responseID?: string | null; - triggerID?: string | null; - }; - acknowledged?: boolean; -} - -export interface MessageAttachment { - originalURL: string; - signedURL: string | null; - arrayBuffer: ArrayBuffer | null; - isImage: boolean; - fileExtension: string; -} - -export interface MessageOriginals { - triggerMessage: Message | null; - originalResponse: Message | null; -} diff --git a/lib/types/misc.d.ts b/lib/types/misc.d.ts new file mode 100644 index 00000000..2cdb4bde --- /dev/null +++ b/lib/types/misc.d.ts @@ -0,0 +1,9 @@ + +// +// Created by Wade (@pakkographic) +// Copyright (c) 2024 DinographicPixels. All rights reserved. +// + +import { PathsServersServerIdMembersUserIdSocialLinksSocialLinkTypeGetParametersPathSocialLinkType as APISocialLinkType } from "guildedapi-types.ts/typings/schemas/v1"; + +export type SocialLinkType = APISocialLinkType | `${APISocialLinkType}`; diff --git a/lib/types/types.d.ts b/lib/types/types.d.ts index 42458774..1b5a881c 100644 --- a/lib/types/types.d.ts +++ b/lib/types/types.d.ts @@ -5,13 +5,13 @@ // Copyright (c) 2024 DinographicPixels. All rights reserved. // +import type { RawEmote, RawMentions } from "./channels"; import { ForumThread } from "../structures/ForumThread"; import { Guild } from "../structures/Guild"; import { Member } from "../structures/Member"; import { Message } from "../structures/Message"; import type { MessageReactionInfo } from "../structures/MessageReactionInfo"; import type { ForumThreadReactionInfo } from "../structures/ForumThreadReactionInfo"; -import type { APIEmote, APIMentions } from "../Constants"; import { CalendarEvent } from "../structures/CalendarEvent"; import { CalendarReactionInfo } from "../structures/CalendarReactionInfo"; import { Doc } from "../structures/Doc"; @@ -27,7 +27,7 @@ export interface MessageReactionTypes { }; channelID: string; }; - emoji: APIEmote; + emoji: RawEmote; reactor: Member | { id: string; }; @@ -41,7 +41,7 @@ export interface ForumThreadReactionTypes { }; channelID: string; }; - emoji: APIEmote; + emoji: RawEmote; reactor: Member | { id: string; }; @@ -55,7 +55,7 @@ export interface CalendarReactionTypes { }; channelID: string; }; - emoji: APIEmote; + emoji: RawEmote; reactor: Member | { id: string; }; @@ -69,7 +69,7 @@ export interface DocReactionTypes { }; channelID: string; }; - emoji: APIEmote; + emoji: RawEmote; reactor: Member | { id: string; }; @@ -83,7 +83,7 @@ export interface AnnouncementReactionTypes { }; channelID: string; }; - emoji: APIEmote; + emoji: RawEmote; reactor: Member | { id: string; }; @@ -115,7 +115,7 @@ export interface ListItemNoteTypes { /** ID of the member who edited this note, if edited. */ editedBy: null | string; /** The mentions in this note. */ - mentions: null | APIMentions; + mentions: null | RawMentions; /** The content of the note. */ content: string; } diff --git a/lib/types/webhooks.d.ts b/lib/types/webhooks.d.ts index de2b9e89..155e90a5 100644 --- a/lib/types/webhooks.d.ts +++ b/lib/types/webhooks.d.ts @@ -4,7 +4,7 @@ // Copyright (c) 2024 DinographicPixels. All rights reserved. // -import { MessageEmbedOptions } from "./channel"; +import { MessageEmbedOptions } from "./channels"; export interface WebhookEditOptions { /** New name of the webhook. */ diff --git a/lib/util/Util.ts b/lib/util/Util.ts index fa63c623..ba88aa3f 100644 --- a/lib/util/Util.ts +++ b/lib/util/Util.ts @@ -7,31 +7,34 @@ import { Client } from "../structures/Client"; import { Member } from "../structures/Member"; -import { AnyChannel, AnyTextableChannel, MessageEmbedOptions, MessageConstructorParams } from "../types"; +import { + AnyChannel, + AnyTextableChannel, + MessageEmbedOptions, + MessageConstructorParams, + RawUser, + RawMember, + RawForumThread, + RawPartialForumThread, + RawGuild, + RawRole, + RawGroup, + RawChannel, + RawSubscription, + RawCategory, + RawMessage, + RawEmbed +} from "../types"; import { Channel } from "../structures/Channel"; import { ForumThread } from "../structures/ForumThread"; import { ForumChannel } from "../structures/ForumChannel"; import { Guild } from "../structures/Guild"; 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 { Role } from "../structures/Role"; +import { Group } from "../structures/Group"; +import { Subscription } from "../structures/Subscription"; +import { Category } from "../structures/Category"; import { Message } from "../structures/Message"; -import { - APIForumTopic, - APIForumTopicSummary, - APIGuild, - APIGuildChannel, - APIGuildGroup, - APIGuildMember, - APIGuildRole, - APIGuildSubscription, - APIUser, - APIGuildCategory, - APIChatMessage, - APIEmbedOptions -} from "guildedapi-types.ts/v1"; export class Util { #client: Client; @@ -39,13 +42,13 @@ export class Util { this.#client = client; } - updateUser(user: APIUser): User { + updateUser(user: RawUser): User { return this.#client.users.has(user.id) ? this.#client.users.update(user) : this.#client.users.add(new User(user, this.#client)); } - updateMember(guildID: string, memberID: string, member: APIGuildMember): Member { + updateMember(guildID: string, memberID: string, member: RawMember): Member { const guild = this.#client.guilds.get(guildID); if (guild && this.#client.user?.id === memberID) { if (guild["_clientMember"]) { @@ -59,21 +62,21 @@ export class Util { : new Member({ ...member }, this.#client, guildID); } - updateForumThread(data: APIForumTopic | APIForumTopicSummary): ForumThread { + updateForumThread(data: RawForumThread | RawPartialForumThread): ForumThread { if (data.serverId) { const guild = this.#client.guilds.get(data.serverId); const channel = guild?.channels.get(data.channelId) as ForumChannel; if (guild && channel) { const thread = channel.threads.has(data.id) ? channel.threads.update(data) - : channel.threads.add(new ForumThread(data as APIForumTopic, this.#client)); + : channel.threads.add(new ForumThread(data as RawForumThread, this.#client)); return thread; } } - return new ForumThread(data as APIForumTopic, this.#client); + return new ForumThread(data as RawForumThread, this.#client); } - updateGuild(data: APIGuild): Guild { + updateGuild(data: RawGuild): Guild { if (data.id) { return this.#client.guilds.has(data.id) ? this.#client.guilds.update(data) @@ -82,38 +85,38 @@ export class Util { return new Guild(data, this.#client); } - updateRole(data: APIGuildRole): GuildRole { + updateRole(data: RawRole): Role { if (data.serverId) { const guild = this.#client.guilds.get(data.serverId); if (guild) { const role = guild.roles.has(data.id) - ? guild.roles.update(data as APIGuildRole) - : guild.roles.add(new GuildRole(data, this.#client)); + ? guild.roles.update(data as RawRole) + : guild.roles.add(new Role(data, this.#client)); return role; } } - return new GuildRole(data, this.#client); + return new Role(data, this.#client); } - updateGuildGroup(data: APIGuildGroup): GuildGroup { + updateGuildGroup(data: RawGroup): Group { if (data.serverId) { const guild = this.#client.guilds.get(data.serverId); if (guild) { const group = guild.groups.has(data.id) - ? guild.groups.update(data as APIGuildGroup) - : guild.groups.add(new GuildGroup(data, this.#client)); + ? guild.groups.update(data as RawGroup) + : guild.groups.add(new Group(data, this.#client)); return group; } } - return new GuildGroup(data, this.#client); + return new Group(data, this.#client); } - updateChannel(data: APIGuildChannel): T { + updateChannel(data: RawChannel): T { if (data.serverId) { const guild = this.#client.guilds.get(data.serverId); if (guild) { const channel = guild.channels.has(data.id) - ? guild.channels.update(data as APIGuildChannel) + ? guild.channels.update(data as RawChannel) : guild.channels.add(Channel.from(data, this.#client)); return channel as T; } @@ -121,16 +124,16 @@ export class Util { return Channel.from(data, this.#client); } - updateGuildSubscription(data: APIGuildSubscription): GuildSubscription { - return new GuildSubscription(data, this.#client); + updateGuildSubscription(data: RawSubscription): Subscription { + return new Subscription(data, this.#client); } - updateGuildCategory(data: APIGuildCategory): GuildCategory { - return new GuildCategory(data, this.#client); + updateGuildCategory(data: RawCategory): Category { + return new Category(data, this.#client); } updateMessage( - data: APIChatMessage, + data: RawMessage, params?: MessageConstructorParams ): Message { const channel = this.#client.getChannel(data.serverId ?? "", data.channelId); @@ -144,7 +147,7 @@ export class Util { return new Message(data, this.#client, params); } - embedsToParsed(embeds: Array): Array { + embedsToParsed(embeds: Array): Array { return embeds.map(embed => ({ author: embed.author === undefined ? undefined : { name: embed.author.name, @@ -173,7 +176,7 @@ export class Util { })); } - embedsToRaw(embeds: Array): Array { + embedsToRaw(embeds: Array): Array { return embeds.map(embed => ({ author: embed.author === undefined ? undefined : { name: embed.author.name,