Skip to content

Commit

Permalink
Misc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pakkographic committed Aug 11, 2024
1 parent 38b7f0b commit f65ace1
Show file tree
Hide file tree
Showing 20 changed files with 101 additions and 93 deletions.
2 changes: 1 addition & 1 deletion lib/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const RESTMethods = [
] as const;
export type RESTMethod = typeof RESTMethods[number];

export type UserTypes = "app" | "user";
export type RawUserTypes = "bot" | "user";
export type UserTypes = "app" | "user";

export * from "guildedapi-types.ts/v1"; // marks api typings as non-external (for docs).

Expand Down
2 changes: 1 addition & 1 deletion lib/gateway/WSManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ export class WSManager extends TypedEmitter<WebsocketEvents> {


export interface WSManagerParams {
/** Bot's token */
/** App token */
token: string;
/** Guilded API URL */
proxyURL?: string;
Expand Down
8 changes: 4 additions & 4 deletions lib/routes/Misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export class Miscellaneous {
/**
* Get a user.
*
* Note: when getting the bot's user, only the information specific to 'User' will be returned.
* If you'd like to get the UserClient (the bot itself), use Client#user.
* Note: when getting the app's user, only the information specific to 'User' will be returned.
* If you'd like to get the UserClient (the app itself), use Client#user.
* @param userID The ID of the user to get.
*/
async getUser(userID: string): Promise<User> {
Expand All @@ -65,7 +65,7 @@ export class Miscellaneous {
}

/**
* Change a user's status, this includes the bot's one.
* Change a user's status, this includes the app's one.
* @param userID User ID (@me can be used).
* @param options Status options
*/
Expand All @@ -78,7 +78,7 @@ export class Miscellaneous {
}

/**
* Delete a user's status, this includes the bot's one.
* Delete a user's status, this includes the app's one.
* @param userID User ID (@me can be used).
*/
async deleteUserStatus(userID: string | "@me"): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion lib/structures/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { inspect } from "node:util";

/** Default information that every other structure has. */
export abstract class Base<ID= string | number> {
/** Bot's client. */
/** App's client. */
client!: Client;
/** Item ID */
id: ID;
Expand Down
4 changes: 2 additions & 2 deletions lib/structures/CalendarComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Member } from "./Member";
import {
CreateCalendarCommentOptions,
EditCalendarCommentOptions,
JSONCalendarEventComment,
JSONCalendarComment,
ConstructorCalendarCommentOptions,
RawCalendarComment
} from "../types";
Expand Down Expand Up @@ -59,7 +59,7 @@ export class CalendarComment extends Base<number> {
this.update(data);
}

override toJSON(): JSONCalendarEventComment {
override toJSON(): JSONCalendarComment {
return {
...super.toJSON(),
data: this.data,
Expand Down
4 changes: 2 additions & 2 deletions lib/structures/CalendarRSVP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { Client } from "./Client";
import { Base } from "./Base";
import { JSONCalendarEventRSVP, EditCalendarRSVPOptions, RawCalendarRSVP, CalendarRSVPStatus } from "../types";
import { JSONCalendarRSVP, 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.
Expand Down Expand Up @@ -50,7 +50,7 @@ export class CalendarEventRSVP extends Base<number> {
this.update(data);
}

override toJSON(): JSONCalendarEventRSVP {
override toJSON(): JSONCalendarRSVP {
return {
...super.toJSON(),
guildID: this.guildID,
Expand Down
4 changes: 2 additions & 2 deletions lib/structures/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { Client } from "./Client";
import { Base } from "./Base";
import { Permission } from "./Permission";
import { JSONGuildCategory, RawCategory } from "../types";
import { JSONCategory, RawCategory } from "../types";
import { PATCHUpdateCategoryBody } from "../Constants";
import { PATCHChannelCategoryUserPermissionBody, POSTChannelCategoryUserPermissionBody } from "guildedapi-types.ts/v1";

Expand Down Expand Up @@ -38,7 +38,7 @@ export class Category extends Base<number> {
this.update(data);
}

override toJSON(): JSONGuildCategory {
override toJSON(): JSONCategory {
return {
...super.toJSON(),
guildID: this.guildID,
Expand Down
12 changes: 6 additions & 6 deletions lib/structures/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ import { fetch } from "undici";
*
* That's where everything begins.*/
export class Client extends TypedEmitter<ClientEvents> {
/** Client's params, including bot's token & rest options. */
/** Client's params, including app's token & rest options. */
params: ClientOptions;
/** Websocket Manager. */
ws: WSManager;
Expand All @@ -138,7 +138,7 @@ export class Client extends TypedEmitter<ClientEvents> {
util: Util;
/** Time at which the connection started in ms. */
startTime: number;
/** @param params Client's parameters, this includes bot's token & rest options. */
/** @param params Client's parameters, this includes app's token & rest options. */
constructor(params: ClientOptions) {
if (typeof params !== "object") throw new Error("The token isn't provided in an object.");
if (!params?.token) throw new Error("Cannot create client without token, no token is provided.");
Expand Down Expand Up @@ -383,8 +383,8 @@ export class Client extends TypedEmitter<ClientEvents> {
/**
* Get a user.
*
* Note: when getting the bot's user, only the information specific to 'User' will be returned.
* If you'd like to get the UserClient (the bot itself), use Client#user.
* Note: when getting the app's user, only the information specific to 'User' will be returned.
* If you'd like to get the UserClient (the app itself), use Client#user.
* @param userID The ID of the user to get.
*/
async getUser(userID: string): Promise<User> {
Expand Down Expand Up @@ -1480,7 +1480,7 @@ export class Client extends TypedEmitter<ClientEvents> {
}

/**
* Change a user's status, this includes the bot's one.
* Change a user's status, this includes the app's one.
* @param userID User ID (@me can be used).
* @param options Status options
*/
Expand All @@ -1489,7 +1489,7 @@ export class Client extends TypedEmitter<ClientEvents> {
}

/**
* Delete a user's status, this includes the bot's one.
* Delete a user's status, this includes the app's one.
* @param userID User ID (@me can be used).
*/
async deleteUserStatus(userID: string | "@me"): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions lib/structures/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { Client } from "./Client";
import { Base } from "./Base";
import { JSONGuildGroup, RawGroup } from "../types";
import { JSONGroup, RawGroup } from "../types";

/** Represents a Guild Group. */
export class Group extends Base<string> {
Expand Down Expand Up @@ -55,7 +55,7 @@ export class Group extends Base<string> {
this.update(data);
}

override toJSON(): JSONGuildGroup {
override toJSON(): JSONGroup {
return {
...super.toJSON(),
guildID: this.guildID,
Expand Down
13 changes: 8 additions & 5 deletions lib/structures/Role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { Base } from "./Base";
import { Client } from "./Client";
import { JSONGuildRole, RawRole } from "../types";
import { JSONRole, RawRole } from "../types";
import { PATCHGuildRolePermissionUpdateBody, Permissions } from "guildedapi-types.ts/v1";

/** Represents a Guild Role. */
Expand Down Expand Up @@ -38,8 +38,10 @@ export class Role extends Base<number> {
/** The default role users are given when joining the server.
* Base roles are tied directly to the server and cannot be created or deleted */
isBase: boolean;
/** The bot user ID this role has been defined for.
* Roles with this populated can only be deleted by kicking the bot */
/** The app user ID this role has been defined for.
* Roles with this populated can only be deleted by kicking the app */
appUserID: string | null;
/** @deprecated, Use Role#appUserID. */
botUserID: string | null;
constructor(data: RawRole, client: Client) {
super(data.id, client);
Expand All @@ -55,11 +57,12 @@ export class Role extends Base<number> {
this.iconURL = data.icon ?? null;
this.position = data.priority ?? null;
this.isBase = data.isBase ?? false;
this.appUserID = data.botUserId ?? null;
this.botUserID = data.botUserId ?? null;
this.update(data);
}

override toJSON(): JSONGuildRole {
override toJSON(): JSONRole {
return {
...super.toJSON(),
guildID: this.guildID,
Expand All @@ -74,7 +77,7 @@ export class Role extends Base<number> {
iconURL: this.iconURL,
position: this.position,
isBase: this.isBase,
botUserID: this.botUserID
appUserID: this.appUserID
};
}

Expand Down
4 changes: 2 additions & 2 deletions lib/structures/Subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { Client } from "./Client";
import { Base } from "./Base";
import { JSONGuildSubscription, RawSubscription } from "../types";
import { JSONSubscription, RawSubscription } from "../types";

/** Represents a Guild Subscription. */
export class Subscription extends Base<string> {
Expand Down Expand Up @@ -35,7 +35,7 @@ export class Subscription extends Base<string> {
this.update(data);
}

override toJSON(): JSONGuildSubscription {
override toJSON(): JSONSubscription {
return {
...super.toJSON(),
type: this.type,
Expand Down
6 changes: 4 additions & 2 deletions lib/structures/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class User extends Base<string> {
createdAt: Date; // user.
/** If true, the user is an app (aka: bot). */
app: boolean;
/** @deprecated */
/** @deprecated Use User#app. */
bot: boolean;

/**
Expand Down Expand Up @@ -54,7 +54,7 @@ export class User extends Base<string> {
createdAt: this.createdAt,
avatarURL: this.avatarURL,
bannerURL: this.bannerURL,
bot: this.app
app: this.app
};
}

Expand All @@ -81,6 +81,8 @@ export class User extends Base<string> {
}
if (data.type !== undefined) {
this.type = data.type === "bot" ? "app" : (data.type === "user" ? "user" : null);
this.app = this.type === "app";
this.bot = this.type === "app";
}
}
}
21 changes: 11 additions & 10 deletions lib/structures/UserClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,21 @@ import { Client } from "./Client";
import { User } from "./User";
import { RawAppUser, JSONUserClient } from "../types";

/** UserClient represents the logged bot's user. */
/** UserClient represents the logged app's user. */
export class UserClient extends User {
/** Client User Bot ID */
botID: string;
/** ID of the bot's owner. */
/** Client User App ID (aka botID) */
appID: string;
/** ID of the app owner. */
ownerID: string;

/** Boolean that shows if the user is a bot or not.
* @defaultValue true
*/
override app: true;
/** @deprecated Use UserClient#appID */
botID: string; // DEPRECATED
/**
* @param data raw data.
* @param client client.
*/
constructor(data: RawAppUser, client: Client) {
super(data, client);
this.appID = data.botId;
this.botID = data.botId;
this.type = "app";
this.app = true;
Expand All @@ -36,14 +34,15 @@ export class UserClient extends User {
override toJSON(): JSONUserClient {
return {
...super.toJSON(),
botID: this.botID,
appID: this.appID,
createdAt: this.createdAt,
ownerID: this.ownerID
};
}

protected override update(data: RawAppUser): void {
if (data.botId !== undefined) {
this.appID = data.botId;
this.botID = data.botId;
}
if (data.createdAt !== undefined) {
Expand All @@ -66,6 +65,8 @@ export class UserClient extends User {
}
if (data.type !== undefined) {
this.type = data.type === "bot" ? "app" : (data.type === "user" ? "user" : null);
this.app = this.type === "app";
this.bot = this.type === "app";
}
}
}
2 changes: 1 addition & 1 deletion lib/types/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Agent } from "undici";

export interface ClientOptions {
/**
* The bot's bearer token, needed to connect to the bot.
* The app's bearer token, required to connect to the API.
*/
token: string;
/**
Expand Down
20 changes: 10 additions & 10 deletions lib/types/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import {
JSONAnnouncementComment,
JSONCalendarChannel,
JSONCalendarEvent,
JSONCalendarEventComment,
JSONCalendarEventRSVP,
JSONCalendarComment,
JSONCalendarRSVP,
JSONChannel,
JSONDoc,
JSONDocChannel,
Expand All @@ -36,8 +36,8 @@ import {
JSONForumThread,
JSONForumThreadComment,
JSONGuildChannel,
JSONGuildGroup,
JSONGuildRole,
JSONGroup,
JSONRole,
JSONMessage,
JSONTextChannel
} from "./json";
Expand Down Expand Up @@ -76,7 +76,7 @@ export interface ClientEvents {
warn: [message: string];
/** @event Emitted when things needs to be debugged. */
debug: [message: string | object];
/** @event Emitted when the bot is ready. */
/** @event Emitted when the app is ready. */
ready: [];
/** @event Emitted when a message is created in a "chat" channel. */
messageCreate: [message: Message<AnyTextableChannel>];
Expand Down Expand Up @@ -172,13 +172,13 @@ export interface ClientEvents {
/** @event Emitted when a guild group is created. */
guildGroupCreate: [guildGroup: Group];
/** @event Emitted when a guild group is updated. */
guildGroupUpdate: [guildGroup: Group, oldGuildGroup: JSONGuildGroup | null];
guildGroupUpdate: [guildGroup: Group, oldGuildGroup: JSONGroup | null];
/** @event Emitted when a guild group is deleted. */
guildGroupDelete: [guildGroup: Group];
/** @event Emitted when a guild role is created. */
guildRoleCreate: [role: Role];
/** @event Emitted when a guild role is updated. */
guildRoleUpdate: [role: Role, oldRole: JSONGuildRole | null];
guildRoleUpdate: [role: Role, oldRole: JSONRole | null];
/** @event Emitted when a guild role is deleted. */
guildRoleDelete: [role: Role];
/** @event Emitted when a doc is created. */
Expand All @@ -200,15 +200,15 @@ export interface ClientEvents {
/** @event Emitted when a calendar event is deleted. */
calendarEventDelete: [CalendarEvent: CalendarEvent];
/** @event Emitted when an event RSVP is updated. */
calendarEventRsvpUpdate: [CalendarRSVP: CalendarEventRSVP, oldRSVP: JSONCalendarEventRSVP | null];
calendarEventRsvpUpdate: [CalendarRSVP: CalendarEventRSVP, oldRSVP: JSONCalendarRSVP | null];
/** @event Emitted when multiple event RSVPs are updated. */
calendarEventRsvpBulkUpdate: [CalendarRSVPs: Array<CalendarEventRSVP>, oldRSVPs: Array<JSONCalendarEventRSVP | null>];
calendarEventRsvpBulkUpdate: [CalendarRSVPs: Array<CalendarEventRSVP>, oldRSVPs: Array<JSONCalendarRSVP | null>];
/** @event Emitted when an event RSVP is deleted. */
calendarEventRsvpDelete: [CalendarRSVP: CalendarEventRSVP];
/** @event Emitted when a calendar event comment is created. */
calendarCommentCreate: [comment: CalendarComment];
/** @event Emitted when a calendar event comment is edited. */
calendarCommentUpdate: [comment: CalendarComment, oldComment: JSONCalendarEventComment | null];
calendarCommentUpdate: [comment: CalendarComment, oldComment: JSONCalendarComment | null];
/** @event Emitted when a calendar event comment is deleted. */
calendarCommentDelete: [comment: CalendarComment];
/** @event Emitted when a list item is created. */
Expand Down
Loading

0 comments on commit f65ace1

Please sign in to comment.