feat: Message.crosspost and fix latest commit

This commit is contained in:
Yuzu 2022-07-01 14:31:43 -05:00
parent 050d5a3973
commit c6e6a6392e
4 changed files with 34 additions and 4 deletions

View File

@ -250,6 +250,23 @@ export class Message implements Model {
); );
} }
async crosspost() {
const message = await this.session.rest.runMethod<DiscordMessage>(
this.session.rest,
"POST",
Routes.CHANNEL_MESSAGE_CROSSPOST(this.channelId, this.id),
);
return new Message(this.session, message);
}
/*
* alias of Message.crosspost
* */
get publish() {
return this.crosspost;
}
inGuild(): this is { guildId: Snowflake } & Message { inGuild(): this is { guildId: Snowflake } & Message {
return !!this.guildId; return !!this.guildId;
} }

View File

@ -2,6 +2,7 @@ import type { Snowflake } from "../util/Snowflake.ts";
import type { Session } from "../session/Session.ts"; import type { Session } from "../session/Session.ts";
import type { DiscordChannel } from "../vendor/external.ts"; import type { DiscordChannel } from "../vendor/external.ts";
import TextChannel from "./TextChannel.ts"; import TextChannel from "./TextChannel.ts";
import Message from "./Message.ts";
export class NewsChannel extends TextChannel { export class NewsChannel extends TextChannel {
constructor(session: Session, data: DiscordChannel, guildId: Snowflake) { constructor(session: Session, data: DiscordChannel, guildId: Snowflake) {
@ -9,6 +10,14 @@ export class NewsChannel extends TextChannel {
this.defaultAutoArchiveDuration = data.default_auto_archive_duration; this.defaultAutoArchiveDuration = data.default_auto_archive_duration;
} }
defaultAutoArchiveDuration?: number; defaultAutoArchiveDuration?: number;
crosspostMessage(messageId: Snowflake): Promise<Message> {
return Message.prototype.crosspost.call({ id: messageId, channelId: this.id, session: this.session });
}
get publishMessage() {
return this.crosspostMessage;
}
} }
export default NewsChannel; export default NewsChannel;

View File

@ -118,15 +118,15 @@ export class TextChannel extends GuildChannel {
} }
async addReaction(messageId: Snowflake, reaction: ReactionResolvable) { async addReaction(messageId: Snowflake, reaction: ReactionResolvable) {
await Message.prototype.addReaction.call({ channelId: this.id, id: messageId }, reaction); await Message.prototype.addReaction.call({ channelId: this.id, id: messageId, session: this.session }, reaction);
} }
async removeReaction(messageId: Snowflake, reaction: ReactionResolvable, options?: { userId: Snowflake }) { async removeReaction(messageId: Snowflake, reaction: ReactionResolvable, options?: { userId: Snowflake }) {
await Message.prototype.removeReaction.call({ channelId: this.id, id: messageId }, reaction, options); await Message.prototype.removeReaction.call({ channelId: this.id, id: messageId, session: this.session }, reaction, options);
} }
async removeReactionEmoji(messageId: Snowflake, reaction: ReactionResolvable) { async removeReactionEmoji(messageId: Snowflake, reaction: ReactionResolvable) {
await Message.prototype.removeReactionEmoji.call({ channelId: this.id, id: messageId }, reaction); await Message.prototype.removeReactionEmoji.call({ channelId: this.id, id: messageId, session: this.session }, reaction);
} }
async nukeReactions(messageId: Snowflake) { async nukeReactions(messageId: Snowflake) {
@ -134,7 +134,7 @@ export class TextChannel extends GuildChannel {
} }
async fetchReactions(messageId: Snowflake, reaction: ReactionResolvable, options?: GetReactions) { async fetchReactions(messageId: Snowflake, reaction: ReactionResolvable, options?: GetReactions) {
const users = await Message.prototype.fetchReactions.call({ channelId: this.id, id: messageId }, reaction, options); const users = await Message.prototype.fetchReactions.call({ channelId: this.id, id: messageId, session: this.session }, reaction, options);
return users; return users;
} }

View File

@ -207,3 +207,7 @@ export function CHANNEL_MESSAGE_REACTION(channelId: Snowflake, messageId: Snowfl
return url; return url;
} }
export function CHANNEL_MESSAGE_CROSSPOST(channelId: Snowflake, messageId: Snowflake) {
return `/channels/${channelId}/messages/${messageId}/crosspost`;
}