2020-10-22 15:50:47 +00:00
|
|
|
import { Base } from './base.ts'
|
|
|
|
import {
|
|
|
|
Attachment,
|
|
|
|
ChannelMention,
|
|
|
|
MessageActivity,
|
|
|
|
MessageApplication,
|
2020-10-25 17:03:53 +00:00
|
|
|
MessageOption,
|
2020-10-22 15:50:47 +00:00
|
|
|
MessagePayload,
|
|
|
|
MessageReference,
|
|
|
|
Reaction
|
2020-10-31 12:33:34 +00:00
|
|
|
} from '../types/channel.ts'
|
2020-10-22 15:50:47 +00:00
|
|
|
import { Client } from '../models/client.ts'
|
2020-10-25 17:03:53 +00:00
|
|
|
import { User } from './user.ts'
|
|
|
|
import { Member } from './member.ts'
|
|
|
|
import { Embed } from './embed.ts'
|
|
|
|
import { CHANNEL_MESSAGE } from '../types/endpoint.ts'
|
2020-11-08 07:57:24 +00:00
|
|
|
import { MessageMentions } from './messageMentions.ts'
|
|
|
|
import { TextChannel } from './textChannel.ts'
|
|
|
|
import { Guild } from './guild.ts'
|
2020-10-22 15:50:47 +00:00
|
|
|
|
2020-11-09 10:29:16 +00:00
|
|
|
type AllMessageOptions = MessageOption | Embed
|
|
|
|
|
2020-10-24 18:11:27 +00:00
|
|
|
export class Message extends Base {
|
2020-10-22 15:50:47 +00:00
|
|
|
id: string
|
2020-10-23 16:11:00 +00:00
|
|
|
channelID: string
|
2020-11-02 12:08:38 +00:00
|
|
|
channel: TextChannel
|
2020-10-23 16:11:00 +00:00
|
|
|
guildID?: string
|
2020-11-02 12:08:38 +00:00
|
|
|
guild?: Guild
|
2020-10-25 17:03:53 +00:00
|
|
|
author: User
|
2020-10-29 14:43:27 +00:00
|
|
|
member?: Member
|
2020-10-22 15:50:47 +00:00
|
|
|
content: string
|
|
|
|
timestamp: string
|
2020-10-23 16:11:00 +00:00
|
|
|
editedTimestamp?: string
|
2020-10-22 15:50:47 +00:00
|
|
|
tts: boolean
|
2020-10-23 16:11:00 +00:00
|
|
|
mentionEveryone: boolean
|
2020-11-01 11:22:09 +00:00
|
|
|
mentions: MessageMentions
|
2020-10-29 14:43:27 +00:00
|
|
|
mentionRoles: string[]
|
2020-10-23 16:11:00 +00:00
|
|
|
mentionChannels?: ChannelMention[]
|
2020-10-22 15:50:47 +00:00
|
|
|
attachments: Attachment[]
|
2020-10-25 17:03:53 +00:00
|
|
|
embeds: Embed[]
|
2020-10-23 16:11:00 +00:00
|
|
|
reactions?: Reaction[]
|
|
|
|
nonce?: string | number
|
2020-10-22 15:50:47 +00:00
|
|
|
pinned: boolean
|
2020-10-29 14:43:27 +00:00
|
|
|
webhookID?: string
|
2020-10-22 15:50:47 +00:00
|
|
|
type: number
|
|
|
|
activity?: MessageActivity
|
|
|
|
application?: MessageApplication
|
2020-10-23 16:11:00 +00:00
|
|
|
messageReference?: MessageReference
|
|
|
|
flags?: number
|
2020-10-22 15:50:47 +00:00
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
constructor (
|
|
|
|
client: Client,
|
|
|
|
data: MessagePayload,
|
2020-11-02 16:31:10 +00:00
|
|
|
channel: TextChannel,
|
2020-11-09 10:29:16 +00:00
|
|
|
author: User
|
2020-11-02 06:58:23 +00:00
|
|
|
) {
|
2020-10-22 15:50:47 +00:00
|
|
|
super(client)
|
|
|
|
this.id = data.id
|
2020-10-23 16:11:00 +00:00
|
|
|
this.channelID = data.channel_id
|
|
|
|
this.guildID = data.guild_id
|
2020-11-01 11:22:09 +00:00
|
|
|
this.author = author
|
2020-10-22 15:50:47 +00:00
|
|
|
this.content = data.content
|
|
|
|
this.timestamp = data.timestamp
|
2020-10-23 16:11:00 +00:00
|
|
|
this.editedTimestamp = data.edited_timestamp
|
2020-10-22 15:50:47 +00:00
|
|
|
this.tts = data.tts
|
2020-10-23 16:11:00 +00:00
|
|
|
this.mentionEveryone = data.mention_everyone
|
2020-11-09 10:29:16 +00:00
|
|
|
this.mentions = new MessageMentions(this.client, this)
|
2020-10-29 14:43:27 +00:00
|
|
|
this.mentionRoles = data.mention_roles
|
|
|
|
this.mentionChannels = data.mention_channels
|
2020-10-22 15:50:47 +00:00
|
|
|
this.attachments = data.attachments
|
2020-10-29 14:43:27 +00:00
|
|
|
this.embeds = data.embeds.map(v => new Embed(v))
|
2020-10-22 15:50:47 +00:00
|
|
|
this.reactions = data.reactions
|
|
|
|
this.nonce = data.nonce
|
|
|
|
this.pinned = data.pinned
|
2020-10-29 14:43:27 +00:00
|
|
|
this.webhookID = data.webhook_id
|
2020-10-22 15:50:47 +00:00
|
|
|
this.type = data.type
|
|
|
|
this.activity = data.activity
|
|
|
|
this.application = data.application
|
2020-10-23 16:11:00 +00:00
|
|
|
this.messageReference = data.message_reference
|
2020-10-22 15:50:47 +00:00
|
|
|
this.flags = data.flags
|
2020-11-01 11:22:09 +00:00
|
|
|
this.channel = channel
|
2020-10-22 15:50:47 +00:00
|
|
|
}
|
2020-10-25 17:03:53 +00:00
|
|
|
|
2020-10-30 14:51:40 +00:00
|
|
|
protected readFromData (data: MessagePayload): void {
|
2020-10-29 14:43:27 +00:00
|
|
|
super.readFromData(data)
|
|
|
|
this.channelID = data.channel_id ?? this.channelID
|
|
|
|
this.guildID = data.guild_id ?? this.guildID
|
|
|
|
this.content = data.content ?? this.content
|
|
|
|
this.timestamp = data.timestamp ?? this.timestamp
|
|
|
|
this.editedTimestamp = data.edited_timestamp ?? this.editedTimestamp
|
|
|
|
this.tts = data.tts ?? this.tts
|
|
|
|
this.mentionEveryone = data.mention_everyone ?? this.mentionEveryone
|
|
|
|
this.mentionRoles = data.mention_roles ?? this.mentionRoles
|
|
|
|
this.mentionChannels = data.mention_channels ?? this.mentionChannels
|
|
|
|
this.attachments = data.attachments ?? this.attachments
|
|
|
|
this.embeds = data.embeds.map(v => new Embed(v)) ?? this.embeds
|
|
|
|
this.reactions = data.reactions ?? this.reactions
|
|
|
|
this.nonce = data.nonce ?? this.nonce
|
|
|
|
this.pinned = data.pinned ?? this.pinned
|
|
|
|
this.webhookID = data.webhook_id ?? this.webhookID
|
|
|
|
this.type = data.type ?? this.type
|
|
|
|
this.activity = data.activity ?? this.activity
|
|
|
|
this.application = data.application ?? this.application
|
|
|
|
this.messageReference = data.message_reference ?? this.messageReference
|
|
|
|
this.flags = data.flags ?? this.flags
|
|
|
|
}
|
|
|
|
|
2020-11-03 09:21:29 +00:00
|
|
|
async edit (text?: string, option?: MessageOption): Promise<Message> {
|
2020-11-09 10:29:16 +00:00
|
|
|
return this.channel.editMessage(this.id, text, option)
|
2020-11-02 12:08:38 +00:00
|
|
|
}
|
|
|
|
|
2020-11-17 03:16:32 +00:00
|
|
|
/** These will **not** work in all servers, as this feature is coming slowly. */
|
2020-11-09 10:29:16 +00:00
|
|
|
async reply(text?: string | AllMessageOptions, option?: AllMessageOptions): Promise<Message> {
|
2020-11-17 03:16:32 +00:00
|
|
|
return this.channel.send(text, Object.assign(option, { reply: this }))
|
2020-10-25 17:03:53 +00:00
|
|
|
}
|
2020-10-29 14:43:27 +00:00
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
async delete (): Promise<void> {
|
|
|
|
return this.client.rest.delete(CHANNEL_MESSAGE(this.channelID, this.id))
|
2020-10-29 14:43:27 +00:00
|
|
|
}
|
2020-10-22 15:50:47 +00:00
|
|
|
}
|