Add Sticker Feature

This commit is contained in:
Helloyunho 2020-12-17 10:20:06 +09:00
parent e27002fc55
commit d7f4b244c1
4 changed files with 87 additions and 4 deletions

View file

@ -16,6 +16,7 @@ import { MessageMentions } from './messageMentions.ts'
import { TextChannel } from './textChannel.ts'
import { Guild } from './guild.ts'
import { MessageReactionsManager } from '../managers/messageReactions.ts'
import { MessageSticker } from './messageSticker.ts'
type AllMessageOptions = MessageOption | Embed
@ -43,6 +44,7 @@ export class Message extends Base {
application?: MessageApplication
messageReference?: MessageReference
flags?: number
stickers?: MessageSticker[]
constructor(
client: Client,
@ -72,6 +74,12 @@ export class Message extends Base {
this.messageReference = data.message_reference
this.flags = data.flags
this.channel = channel
this.stickers =
data.stickers !== undefined
? data.stickers.map(
(payload) => new MessageSticker(this.client, payload)
)
: undefined
}
readFromData(data: MessagePayload): void {
@ -91,6 +99,12 @@ export class Message extends Base {
this.application = data.application ?? this.application
this.messageReference = data.message_reference ?? this.messageReference
this.flags = data.flags ?? this.flags
this.stickers =
data.stickers !== undefined
? data.stickers.map(
(payload) => new MessageSticker(this.client, payload)
)
: this.stickers
}
/** Edits this message. */

View file

@ -0,0 +1,43 @@
import { Client } from '../models/client.ts'
import {
MessageStickerFormatTypes,
MessageStickerPayload
} from '../types/channel.ts'
import { Base } from './base.ts'
export class MessageSticker extends Base {
id: string
packID: string
name: string
description: string
tags?: string[]
asset: string
previewAsset: string | null
formatType: MessageStickerFormatTypes
constructor(client: Client, data: MessageStickerPayload) {
super(client)
this.id = data.id
this.packID = data.pack_id
this.name = data.name
this.description = data.description
this.tags = data.tags !== undefined ? data.tags.split(', ') : undefined
this.asset = data.asset
this.previewAsset = data.preview_asset
this.formatType = data.format_type
}
readFromData(data: MessageStickerPayload): void {
this.id = data.id ?? this.id
this.packID = data.pack_id ?? this.packID
this.name = data.name ?? this.name
this.description = data.description ?? this.description
this.tags = data.tags !== undefined ? data.tags.split(', ') : this.tags
this.asset = data.asset ?? this.asset
this.previewAsset = data.preview_asset ?? this.previewAsset
this.formatType = data.format_type ?? this.formatType
}
// TODO: Make asset url function when it's available
}

View file

@ -14,9 +14,9 @@ import {
import { TOKEN } from './config.ts'
const client = new Client({
clientProperties: {
browser: 'Discord iOS'
}
// clientProperties: {
// browser: 'Discord iOS'
// }
// bot: false,
// cache: new RedisCacheAdapter({
// hostname: '127.0.0.1',
@ -47,7 +47,15 @@ client.on('channelUpdate', (b: EveryChannelTypes, a: EveryChannelTypes) => {
client.on('messageCreate', async (msg: Message) => {
if (msg.author.bot === true) return
console.log(`${msg.author.tag}: ${msg.content}`)
if (msg.stickers !== undefined) {
console.log(
`${msg.author.tag}: (Sticker)${msg.stickers.map(
(sticker) => `Name: ${sticker.name}, Tags: ${sticker.tags}`
)}`
)
} else {
console.log(`${msg.author.tag}: ${msg.content}`)
}
if (msg.content === '!ping') {
msg.reply(`Pong! Ping: ${client.ping}ms`)
} else if (msg.content === '!members') {

View file

@ -96,6 +96,7 @@ export interface MessagePayload {
application?: MessageApplication
message_reference?: MessageReference
flags?: number
stickers?: MessageStickerPayload[]
}
export interface MessageOption {
@ -256,3 +257,20 @@ export interface FollowedChannel {
channel_id: string
webhook_id: string
}
export enum MessageStickerFormatTypes {
PNG = 1,
APNG = 2,
LOTTIE = 3
}
export interface MessageStickerPayload {
id: string
pack_id: string
name: string
description: string
tags?: string
asset: string
preview_asset: string | null
format_type: MessageStickerFormatTypes
}