Skip to content

Commit

Permalink
feat: message#isReply & message#url (#222)
Browse files Browse the repository at this point in the history
Co-authored-by: Nico <nico.03727+github@gmail.com>
  • Loading branch information
WeismannS and zaida04 authored Apr 11, 2023
1 parent 355d1d7 commit 0a6088b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-walls-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"guilded.js": patch
---

Added a few more properties and methods to Message structure
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

pnpm run build:typecheck && npx lint-staged --config .config/.lintstagedrc.json
npm run build:typecheck && npx lint-staged --config .config/.lintstagedrc.json
54 changes: 35 additions & 19 deletions packages/guilded.js/lib/structures/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { User } from "./User";
import type { Member } from "./Member";
import { buildMemberKey, buildReactionKey } from "../util";
import { Embed } from "./Embed";
import type { Server } from "./Server";
import type { Channel } from "./channels";
import type { MessageContent } from "../typings";

Expand Down Expand Up @@ -38,6 +39,8 @@ export class Message extends Base<ChatMessagePayload> {
readonly isSilent: boolean;
/** The ID of the user who created this message (Note: If this event has createdByBotId or createdByWebhookId present, this field will still be populated, but can be ignored. In these cases, the value of this field will always be Ann6LewA) */
readonly createdById: string;
/** Bool value to wether message is a reply or not */
readonly isReply: boolean;
/** The ID of the bot who created this message, if it was created by a bot */
readonly createdByBotId: string | null;
/** The ID of the webhook who created this message, if it was created by a webhook */
Expand All @@ -55,7 +58,7 @@ export class Message extends Base<ChatMessagePayload> {

constructor(client: Client, data: ChatMessagePayload) {
super(client, data);

this.isReply = !!data.replyMessageIds;
this.channelId = data.channelId;
this.content = data.content ?? "";
this.serverId = data.serverId ?? null;
Expand All @@ -73,24 +76,6 @@ export class Message extends Base<ChatMessagePayload> {
this._update(data);
}

get createdAt(): Date {
return new Date(this._createdAt);
}

/**
* Returns the date and time the message was last updated, if relevant.
*/
get updatedAt(): Date | null {
return this._updatedAt ? new Date(this._updatedAt) : null;
}

/**
* Returns the date and time the message was deleted, if it was.
*/
get deletedAt(): Date | null {
return this._deletedAt ? new Date(this._deletedAt) : null;
}

/** Update details of this structure */
_update(data: Partial<ChatMessagePayload> | { deletedAt: string }): this {
if ("content" in data && typeof data.content !== "undefined") {
Expand All @@ -116,6 +101,31 @@ export class Message extends Base<ChatMessagePayload> {

return this;
}

get createdAt(): Date {
return new Date(this._createdAt);
}

/**
* Returns the date and time the message was last updated, if relevant.
*/
get updatedAt(): Date | null {
return this._updatedAt ? new Date(this._updatedAt) : null;
}

/**
* Returns the date and time the message was deleted, if it was.
*/
get deletedAt(): Date | null {
return this._deletedAt ? new Date(this._deletedAt) : null;
}

/** Returns the url of this message */
get url(): string {
if (!this.serverId) return "";
return `https://www.guilded.gg/chat/${this.channelId}?messageId=${this.id}`;
}

/**
* Returns the author of this message, or null if the author is not cached.
*/
Expand Down Expand Up @@ -148,6 +158,12 @@ export class Message extends Base<ChatMessagePayload> {
return this.client.channels.cache.get(this.channelId) ?? null;
}

get server(): Server | null {
return this.serverId
? this.client.servers.cache.get(this.serverId) ?? null
: null;
}

/**
* Edit message content.
* @param newContent - The new content of the message.
Expand Down

0 comments on commit 0a6088b

Please sign in to comment.