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-10-29 14:43:27 +00:00
|
|
|
import cache from '../models/cache.ts'
|
2020-11-01 06:38:45 +00:00
|
|
|
import { Channel } from "./channel.ts"
|
2020-11-01 11:22:09 +00:00
|
|
|
import { MessageMentions } from "./MessageMentions.ts"
|
|
|
|
import { TextChannel } from "./textChannel.ts"
|
2020-10-22 15:50:47 +00:00
|
|
|
|
2020-10-24 18:11:27 +00:00
|
|
|
export class Message extends Base {
|
2020-10-25 17:03:53 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly
|
|
|
|
private data: MessagePayload
|
2020-10-22 15:50:47 +00:00
|
|
|
id: string
|
2020-10-23 16:11:00 +00:00
|
|
|
channelID: string
|
2020-11-01 06:38:45 +00:00
|
|
|
channel: Channel
|
2020-10-23 16:11:00 +00:00
|
|
|
guildID?: string
|
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-01 11:22:09 +00:00
|
|
|
constructor (client: Client, data: MessagePayload, channel: Channel, author: User, mentions: MessageMentions) {
|
2020-10-22 15:50:47 +00:00
|
|
|
super(client)
|
2020-10-25 17:03:53 +00:00
|
|
|
this.data = data
|
2020-10-22 15:50:47 +00:00
|
|
|
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
|
|
|
|
// this.author =
|
|
|
|
// this.client.users.get(data.author.id) || new User(this.client, data.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-01 11:22:09 +00:00
|
|
|
this.mentions = mentions
|
|
|
|
// this.mentions = data.mentions.map(
|
|
|
|
// v => this.client.users.get(v.id) || new User(client, v)
|
|
|
|
// )
|
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
|
|
|
|
// TODO: Cache in Gateway Event Code
|
|
|
|
// if(!noSave) this.client.messages.set(this.id, data)
|
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
|
2020-11-01 11:22:09 +00:00
|
|
|
// this.author =
|
|
|
|
// this.client.users.get(data.author.id) ||
|
|
|
|
// this.author ||
|
|
|
|
// new User(this.client, data.author)
|
2020-10-29 14:43:27 +00:00
|
|
|
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
|
2020-11-01 11:22:09 +00:00
|
|
|
// this.mentions =
|
|
|
|
// data.mentions.map(
|
|
|
|
// v => this.client.users.get(v.id) || new User(this.client, v)
|
|
|
|
// ) ?? this.mentions
|
2020-10-29 14:43:27 +00:00
|
|
|
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-01 11:22:09 +00:00
|
|
|
edit (text?: string, option?: MessageOption): Promise<Message> {
|
|
|
|
return (this.channel as TextChannel).editMessage(this.id, text, option)
|
2020-10-25 17:03:53 +00:00
|
|
|
}
|
2020-10-29 14:43:27 +00:00
|
|
|
|
2020-10-31 13:00:33 +00:00
|
|
|
delete (): Promise<void> {
|
|
|
|
return this.client.rest.delete(CHANNEL_MESSAGE(this.channelID, this.id)) as any
|
2020-10-29 14:43:27 +00:00
|
|
|
}
|
2020-10-22 15:50:47 +00:00
|
|
|
}
|