Skip to content

Commit

Permalink
typing changes + fixes
Browse files Browse the repository at this point in the history
* Fixed imports for `ClientEvents`.

* Deprecate `createdby` in favor of `inviterID` (`GuildCreateInfo`)

* Deprecate `BannedMember.ban.createdBy` in favor of `BannedMember.ban.bannedBy`

* Deprecate `CalendarEvent.memberID` in favor of `CalendarEvent.ownerID`

* Deprecate `CalendarEvent.member` in favor of `CalendarEvent.owner`.

* Deprecate `CalendarRSVP.memberID` in favor of `CalendarRSVP.entityID`.

* Deprecate `CalendarRSVP.createdBy` in favor of `CalendarRSVP.creatorID`

* Deprecate  `Channel.memberID` in favor of `Channel.creatorID`

* Deprecate `Channel.updatedAt` in favor `Channel.editedTimestamp`

* Deprecate `Doc.title` in favor of `Doc.name`

* Deprecate `Doc.updatedAt` in favor of `Doc.editedTimestamp`

* Deprecate `ForumThread.updatedAt` in favor `ForumThread.editedTimestamp`

* Deprecate `ForumThreadComment.ownerID` in favor `ForumThreadComment.memberID`

* Deprecate `ForumThreadComment.owner` in favor of `ForumThreadComment.member`

* Deprecate `ListItem.updatedAt` in favor of `ListItem.editedTimestamp`

* `ListItemNoteTypes` changed: createdBy => memberID
updatedAt => editedTimestamp

* Every structures doesn't include raw timestamps anymore.
  • Loading branch information
pakkographic committed Nov 21, 2022
1 parent c767221 commit d519000
Show file tree
Hide file tree
Showing 17 changed files with 151 additions and 266 deletions.
2 changes: 1 addition & 1 deletion lib/gateway/events/GuildHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class GuildHandler extends GatewayEventHandler{
const GuildComponent = new Guild(data.server, this.client);
const output = {
guild: GuildComponent,
createdBy: data.createdBy
inviterID: data.createdBy
};
this.client.emit("guildCreate", output as GuildCreateInfo);
}
Expand Down
12 changes: 6 additions & 6 deletions lib/structures/BannedMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export class BannedMember extends User {
ban: {
/** Reason of the ban */
reason?: string;
/** Timestamp (unix epoch time) of when the member has been banned. */
createdAt: number|null;
/** ID of the member that banned the user. */
createdBy: string;
/** When the member has been banned. */
createdAt: Date | null;
/** ID of the member who banned this member. */
bannedBy: string;
};
/**
* @param guildID ID of the guild.
Expand All @@ -27,8 +27,8 @@ export class BannedMember extends User {
this.guildID = guildID;
this.ban = {
reason: data.reason,
createdAt: data.createdAt ? Date.parse(data.createdAt) : null,
createdBy: data.createdBy
createdAt: data.createdAt ? new Date(data.createdAt) : null,
bannedBy: data.createdBy
};
}

Expand Down
37 changes: 16 additions & 21 deletions lib/structures/CalendarEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ export class CalendarEvent extends Base {
/** Limit of event entry. */
rsvpLimit: number | null;
/** Timestamp (unix epoch time) of the event starting time.*/
_startsAt: number|null;
startsAt: Date | null;
/** Duration in *ms* of the event. */
duration: number;
/** */
isPrivate: boolean;
mentions: APIMentions | null;
/** Timestamp (unix epoch time) of the event's creation. */
_createdAt: number|null;
/** ID of the member that created the event. */
memberID: string;
/** When the event was created. */
createdAt: Date | null;
/** ID of the owner of this event. */
ownerID: string;
/** Details about event cancelation (if canceled) */
cancelation: APICalendarEvent["cancellation"] | null;

Expand All @@ -57,34 +57,29 @@ export class CalendarEvent extends Base {
this.url = data.url ?? null;
this.color = data.color ?? null;
this.rsvpLimit = data.rsvpLimit ?? null;
this._startsAt = data.startsAt ? Date.parse(data.startsAt) : null;
this.startsAt = data.startsAt ? new Date(data.startsAt) : null;
this.duration = (data.duration as number) * 60000 ?? null; // in ms.
this.isPrivate = data.isPrivate ?? false;
this.mentions = data.mentions ?? null;
this._createdAt = data.createdAt ? Date.parse(data.createdAt) : null;
this.memberID = data.createdBy;
this.createdAt = data.createdAt ? new Date(data.createdAt) : null;
this.ownerID = data.createdBy;
this.cancelation = data.cancellation ?? null;
}

/** Retrieve message's member, if cached.
/** Retrieve the event's owner, if cached.
*
* Note: this getter can output: Member, User, Promise<Member> or undefined.
*/
get member(): Member | User | Promise<Member> | undefined {
if (this.client.cache.members.get(this.memberID) && this.memberID){
return this.client.cache.members.get(this.memberID);
} else if (this.client.cache.users.get(this.memberID) && this.memberID){
return this.client.cache.users.get(this.memberID);
} else if (this.memberID && this.guildID){
return this.client.rest.guilds.getMember(this.guildID, this.memberID);
get owner(): Member | User | Promise<Member> | undefined {
if (this.client.cache.members.get(this.ownerID) && this.ownerID){
return this.client.cache.members.get(this.ownerID);
} else if (this.client.cache.users.get(this.ownerID) && this.ownerID){
return this.client.cache.users.get(this.ownerID);
} else if (this.ownerID && this.guildID){
return this.client.rest.guilds.getMember(this.guildID, this.ownerID);
}
}

/** string representation of the _createdAt timestamp */
get createdAt(): Date|number|null{
return this._createdAt ? new Date(this._createdAt) : null;
}

/** Edit this event */
async edit(options: EditCalendarEventOptions): Promise<CalendarEvent>{
return this.client.rest.channels.editCalendarEvent(this.channelID, this.id as number, options);
Expand Down
46 changes: 12 additions & 34 deletions lib/structures/CalendarRSVP.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/** @module CalendarRSVP */
import { Client } from "./Client";
import { Member } from "./Member";
import { Base } from "./Base";

import { User } from "./User";
import { APICalendarEventRSVP, APICalendarEventRSVPStatuses, PUTCalendarEventRSVPBody } from "../Constants";

/** CalendarEventRSVP represents a guild member's event RSVP.
Expand All @@ -16,15 +13,15 @@ export class CalendarEventRSVP extends Base {
guildID: string;
/** Calendar channel id. */
channelID: string;
/** RSVP member id */
memberID: string;
/** ID of the entity assigned to this Event RSVP. */
entityID: string;
/** Status of the RSVP */
status: APICalendarEventRSVPStatuses;
/** Timestamp (unix epoch time) of the rsvp's creation. */
_createdAt: number|null;
/** ID of the member that created the rsvp. */
createdBy: string;
/** ID of the member that updated the rsvp (if updated) */
/** When the RSVP was created. */
createdAt: Date | null;
/** ID of the user who created this RSVP. */
creatorID: string;
/** ID of the member who updated the rsvp, if updated. */
updatedBy?: string | null;

/**
Expand All @@ -36,39 +33,20 @@ export class CalendarEventRSVP extends Base {
this.data = data;
this.guildID = data.serverId;
this.channelID = data.channelId;
this.memberID = data.userId;
this.entityID = data.userId;
this.status = data.status;
this.createdBy = data.createdBy ?? null;
this.creatorID = data.createdBy ?? null;
this.updatedBy = data.updatedBy ?? null;
this._createdAt = data.createdAt ? Date.parse(data.createdAt) : null;
}

/** Retrieve message's member, if cached.
*
* Note: this getter can output: Member, User, Promise<Member> or undefined.
*/
get member(): Member | User | Promise<Member> | undefined {
if (this.client.cache.members.get(this.memberID) && this.memberID){
return this.client.cache.members.get(this.memberID);
} else if (this.client.cache.users.get(this.memberID) && this.memberID){
return this.client.cache.users.get(this.memberID);
} else if (this.memberID && this.guildID){
return this.client.rest.guilds.getMember(this.guildID, this.memberID);
}
}

/** String representation of the _createdAt timestamp. */
get createdAt(): Date|null{
return this._createdAt ? new Date(this._createdAt) : null;
this.createdAt = data.createdAt ? new Date(data.createdAt) : null;
}

/** Edit this RSVP. */
async edit(options: PUTCalendarEventRSVPBody): Promise<CalendarEventRSVP>{
return this.client.rest.channels.editCalendarRsvp(this.channelID, this.id as number, this.memberID, options);
return this.client.rest.channels.editCalendarRsvp(this.channelID, this.id as number, this.entityID, options);
}

/** Delete this RSVP. */
async delete(): Promise<void>{
return this.client.rest.channels.deleteCalendarRsvp(this.channelID, this.id as number, this.memberID);
return this.client.rest.channels.deleteCalendarRsvp(this.channelID, this.id as number, this.entityID);
}
}
42 changes: 12 additions & 30 deletions lib/structures/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ import type { APIGuildChannel } from "../Constants";

/** Represents a guild channel. */
export class Channel extends Base {
/** Raw data */
data: APIGuildChannel;
/** Channel type */
type: string;
/** Channel name */
name: string;
/** Channel description */
description: string | null;
/** Timestamp (unix epoch time) of the channel's creation. */
_createdAt: number;
/** ID of the channel's creator. */
memberID: string;
/** Timestamp (unix epoch time) of the channel's edition. (if edited) */
_updatedAt: number|null;
/** When this channel was created. */
createdAt: Date;
/** ID of the member who created this channel. */
creatorID: string;
/** Timestamp at which this channel was last edited. */
editedTimestamp: Date | null;
/** Server ID */
guildID: string;
/** ID of the parent category. */
Expand All @@ -33,44 +31,28 @@ export class Channel extends Base {
isPublic: boolean;
/** ID of the member that archived the channel (if archived) */
archivedBy: string | null;
/** Timestamp (unix epoch time) of when the channel has been archived. */
_archivedAt: number|null;
/** When the channel was last archived. */
archivedAt: Date | null;

/**
* @param data raw data
* @param client client
*/
constructor(data: APIGuildChannel, client: Client){
super(data.id, client);
this.data = data;
this.type = data.type;
this.name = data.name;
this.description = data.topic ?? null;
this._createdAt = Date.parse(data.createdAt);
this.memberID = data.createdBy;
this._updatedAt = data.updatedAt ? Date.parse(data.updatedAt) : null;
this.createdAt = new Date(data.createdAt);
this.creatorID = data.createdBy;
this.editedTimestamp = data.updatedAt ? new Date(data.updatedAt) : null;
this.guildID = data.serverId;
this.parentID = data.parentId ?? null;
this.categoryID = data.categoryId ?? null;
this.groupID = data.groupId;
this.isPublic = data.isPublic ?? false;
this.archivedBy = data.archivedBy ?? null;
this._archivedAt = data.archivedAt ? Date.parse(data.archivedAt) : null;
}

/** Date of the channel's creation. */
get createdAt(): Date{
return new Date(this._createdAt);
}

/** Date of the channel's last edition, if updated. */
get updatedAt(): Date|null{
return this._updatedAt !== null ? new Date(this._updatedAt) : null;
}

/** Date of when the channel got archived, if archived. */
get archivedAt(): Date|null{
return this._archivedAt !== null ? new Date(this._archivedAt) : null;
this.archivedAt = data.archivedAt ? new Date(data.archivedAt) : null;
}

/** Create a message in the channel. */
Expand Down
33 changes: 10 additions & 23 deletions lib/structures/Doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@ export class Doc extends Base {
guildID: string;
/** ID of the 'docs' channel. */
channelID: string;
/** Doc title/name */
title: string;
/** Doc title/name */
/** Doc name */
name: string;
/** Content of the doc */
content: string;
/** Doc mentions */
mentions: APIMentions;
/** Timestamp (unix epoch time) of the doc's creation. */
_createdAt: number|null;
/** ID of the member who created the doc. */
/** When the doc has been created. */
createdAt: Date;
/** ID of the member who created this doc. */
memberID: string;
/** Timestamp (unix epoch time) of when the doc was updated. (if updated) */
_updatedAt?: number | null;
/** ID of the member who updated the doc. (if updated) */
updatedBy?: string | null;
/** When the doc has been updated. */
editedTimestamp: Date | null;
/** ID of the member who updated the doc. */
updatedBy: string | null;

/**
* @param data raw data
Expand All @@ -39,12 +37,11 @@ export class Doc extends Base {
this.guildID = data.serverId;
this.channelID = data.channelId;
this.name = data.title ?? null;
this.title = data.title ?? null; // same as name, different type.
this.content = data.content ?? null;
this.mentions = data.mentions ?? {};
this._createdAt = data.createdAt ? Date.parse(data.createdAt) : null;
this.createdAt = new Date(data.createdAt);
this.memberID = data.createdBy;
this._updatedAt = data.updatedAt ? Date.parse(data.updatedAt) : null;
this.editedTimestamp = data.updatedAt ? new Date(data.updatedAt) : null;
this.updatedBy = data.updatedBy ?? null;
}

Expand All @@ -61,16 +58,6 @@ export class Doc extends Base {
} else throw new Error("ERROR: Couldn't get member, failed to retrieve member.");
}

/** Date of this doc's creation. */
get createdAt(): Date | null {
return this._createdAt ? new Date(this._createdAt) : null;
}

/** Date of this last doc's edition, if updated. */
get updatedAt(): Date | null {
return this._updatedAt ? new Date(this._updatedAt) : null;
}

/** Edit this doc.
* @param options Edit options.
*/
Expand Down
26 changes: 8 additions & 18 deletions lib/structures/ForumThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ export class ForumThread extends Base {
guildID: string;
/** Forum channel id */
channelID: string;
/** Thread name/title */
/** Name of the thread */
name: string;
/** Timestamp (unix epoch time) of the thread's creation. */
_createdAt: number;
/** When this forum thread was created. */
createdAt: Date;
/** The ID of the owner of this thread. */
ownerID: string;
/** ID of the webhook that created the thread (if created by webhook) */
webhookID: string | null;
/** Timestamp (unix epoch time) of when the thread got updated. (if updated) */
_updatedAt: number| null;
/** Timestamp at which this channel was last edited. */
editedTimestamp: Date | null;
/** Timestamp (unix epoch time) that the forum thread was bumped at. */
bumpedAt: string | null;
/** Content of the thread */
Expand All @@ -42,10 +42,10 @@ export class ForumThread extends Base {
this.guildID = data.serverId;
this.channelID = data.channelId;
this.name = data.title;
this._createdAt = Date.parse(data.createdAt);
this.createdAt = new Date(data.createdAt);
this.ownerID = data.createdBy;
this.webhookID = data.createdByWebhookId ?? null;
this._updatedAt = data.updatedAt ? Date.parse(data.updatedAt) : null;
this.editedTimestamp = data.updatedAt ? new Date(data.updatedAt) : null;
this.bumpedAt = data.bumpedAt ?? null;
this.content = data.content;
this.mentions = data.mentions ?? null;
Expand Down Expand Up @@ -79,17 +79,7 @@ export class ForumThread extends Base {
return this.client.rest.channels.getChannel(this.channelID);
}

/** string representation of the _createdAt timestamp. */
get createdAt(): Date {
return new Date(this._createdAt);
}

/** string representation of the _updatedAt timestamp. */
get updatedAt(): Date|null {
return this._updatedAt ? new Date(this._updatedAt) : null;
}

/** Boolean that tells you if the forum thread was created by a webhook or not. */
/** If true, this forum thread was created by a webhook. */
get createdByWebhook(): boolean {
return this.webhookID ? true : false;
}
Expand Down
Loading

0 comments on commit d519000

Please sign in to comment.