Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: message#isReply & message#url #222

Merged
merged 5 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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