import Emote from './Emote.js'
import Constants from '../util/Constants.js'
/** @augments Emote */
class BTTVEmote extends Emote {
/**
* A BTTV emote.
* @param {Channel} channel - {@linkcode Channel} this emote belongs to.
* @param {string} id - ID of the emote.
* @param {data} data - The raw emote data.
*/
constructor (channel, id, data) {
super(channel, id, data)
this.type = 'bttv'
}
_setup (data) {
super._setup(data)
/**
* The name of the emote owner.
* Might be null for global emotes.
* @type {string | null}
*/
this.ownerName = 'user' in data ? data.user.name : null
/**
* The image type of the emote.
* @type {string}
*/
this.imageType = 'webp'
/**
* If the emote is animated.
* @type {boolean}
*/
this.animated = data.animated
}
/**
* Gets the image link of the emote.
* @param {object} [options] - Options for the link.
* @param {number} [options.size=0] - Size (scale) for the emote.
* @param {boolean} [options.forceStatic] - Whether to force the emote to be static (non-animated). Defaults to the fetcher's forceStatic or `false`.
* @returns {string} - The URL to the emote.
*/
toLink (options) {
const {
size = 0,
forceStatic = this.fetcher.forceStatic || false,
} = options || {}
return Constants.BTTV.CDN(this.id, size, forceStatic)
}
/**
* Override of the override for `toObject`.
* Will result in an Object representation of a {@linkcode BTTVEmote}.
* @returns {object} - Object representation of the {@linkcode BTTVEmote}.
*/
toObject () {
return {
...super.toObject(),
type: this.type,
ownerName: this.ownerName,
animated: this.animated,
}
}
/**
* Converts an emote Object into a {@linkcode BTTVEmote}
* @param {object} [emoteObject] - Object representation of this emote
* @param {Channel} [channel] - {@linkcode Channel} this emote belongs to.
* @returns {BTTVEmote} - A {@linkcode BTTVEmote} instance.
*/
static fromObject (emoteObject, channel) {
return new BTTVEmote(
channel,
emoteObject.id,
{
code: emoteObject.code,
animated: emoteObject.animated,
user: {
name: emoteObject.ownerName,
},
}
)
}
}
export default BTTVEmote