@mkody/twitch-emoticons
Version:
Gets Twitch, BTTV, FFZ and 7TV emotes as well as parsing text to emotes!
181 lines (138 loc) • 8.17 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>struct/SevenTVEmote.js - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<script src="scripts/nav.js" defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav >
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="BTTVEmote.html">BTTVEmote</a><ul class='methods'><li data-type='method'><a href="BTTVEmote.html#toLink">toLink</a></li><li data-type='method'><a href="BTTVEmote.html#toObject">toObject</a></li><li data-type='method'><a href="BTTVEmote.html#.fromObject">fromObject</a></li></ul></li><li><a href="Channel.html">Channel</a><ul class='methods'><li data-type='method'><a href="Channel.html#fetchBTTVEmotes">fetchBTTVEmotes</a></li><li data-type='method'><a href="Channel.html#fetchFFZEmotes">fetchFFZEmotes</a></li><li data-type='method'><a href="Channel.html#fetchSevenTVEmotes">fetchSevenTVEmotes</a></li></ul></li><li><a href="Collection.html">Collection</a><ul class='methods'><li data-type='method'><a href="Collection.html#filter">filter</a></li><li data-type='method'><a href="Collection.html#find">find</a></li><li data-type='method'><a href="Collection.html#map">map</a></li></ul></li><li><a href="Emote.html">Emote</a><ul class='methods'><li data-type='method'><a href="Emote.html#toObject">toObject</a></li></ul></li><li><a href="EmoteFetcher.html">EmoteFetcher</a><ul class='methods'><li data-type='method'><a href="EmoteFetcher.html#_cacheBTTVEmote">_cacheBTTVEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_cacheFFZEmote">_cacheFFZEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_cacheSevenTVEmote">_cacheSevenTVEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_cacheTwitchEmote">_cacheTwitchEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawBTTVEmotes">_getRawBTTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawFFZEmoteSet">_getRawFFZEmoteSet</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawFFZEmotes">_getRawFFZEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawSevenTVEmotes">_getRawSevenTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawTwitchEmotes">_getRawTwitchEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_setupChannel">_setupChannel</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchBTTVEmotes">fetchBTTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchFFZEmotes">fetchFFZEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchSevenTVEmotes">fetchSevenTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchTwitchEmotes">fetchTwitchEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fromObject">fromObject</a></li></ul></li><li><a href="EmoteParser.html">EmoteParser</a><ul class='methods'><li data-type='method'><a href="EmoteParser.html#parse">parse</a></li></ul></li><li><a href="FFZEmote.html">FFZEmote</a><ul class='methods'><li data-type='method'><a href="FFZEmote.html#toLink">toLink</a></li><li data-type='method'><a href="FFZEmote.html#toObject">toObject</a></li><li data-type='method'><a href="FFZEmote.html#.fromObject">fromObject</a></li></ul></li><li><a href="SevenTVEmote.html">SevenTVEmote</a><ul class='methods'><li data-type='method'><a href="SevenTVEmote.html#toLink">toLink</a></li><li data-type='method'><a href="SevenTVEmote.html#toObject">toObject</a></li><li data-type='method'><a href="SevenTVEmote.html#.fromObject">fromObject</a></li></ul></li><li><a href="TwitchEmote.html">TwitchEmote</a><ul class='methods'><li data-type='method'><a href="TwitchEmote.html#toLink">toLink</a></li><li data-type='method'><a href="TwitchEmote.html#toObject">toObject</a></li><li data-type='method'><a href="TwitchEmote.html#.fromObject">fromObject</a></li></ul></li></ul>
</nav>
<div id="main">
<h1 class="page-title">struct/SevenTVEmote.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const Emote = require('./Emote');
const Constants = require('../util/Constants');
/** @augments Emote */
class SevenTVEmote extends Emote {
/**
* A 7TV emote.
* @param {Channel} channel - 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 = '7tv';
}
/**
* The channel of this emote's creator.
* Not guaranteed to contain the emote, or be cached.
* @readonly
* @type {?Channel}
*/
get owner() {
return this.fetcher.channels.get(this.ownerName);
}
_setup(data) {
super._setup(data);
this.code = data.name;
/**
* The name of the emote creator's channel.
* @type {?string}
*/
this.ownerName = 'owner' in data.data ? data.data.owner.display_name : null;
/**
* Available image sizes.
* @type {string[]}
*/
this.sizes = data.data.host.files
.filter(el => el.format === this.channel.format.toUpperCase())
.map(el => el.name);
/**
* If emote is animated.
* @type {boolean}
*/
this.animated = data.data.animated;
/**
* The image type of the emote.
* @type {string}
*/
this.imageType = this.channel.format;
}
/**
* Gets the image link of the emote.
* @param {number} size - The size of the image.
* @returns {string}
*/
toLink(size = 0) {
size = this.sizes[size];
return Constants.SevenTV.CDN(this.id, size); // eslint-disable-line new-cap
}
/**
* Override for `toObject`.
* Will result in an Object representation of a SevenTVEmote
* @returns {object}
*/
toObject() {
return Object.assign({}, super.toObject(), {
animated: this.animated,
sizes: this.sizes,
ownerName: this.ownerName,
type: this.type,
imageType: this.imageType
});
}
/**
* Converts an emote Object into a SevenTVEmote
* @param {object} [emoteObject] - Object representation of this emote
* @param {Channel} [channel] - Channel this emote belongs to.
* @returns {SevenTVEmote}
*/
static fromObject(emoteObject, channel) {
const sizes = emoteObject.sizes.map(size => { return { format: channel.format.toUpperCase(), name: size }; });
return new SevenTVEmote(channel, emoteObject.id,
{
code: emoteObject.code,
name: emoteObject.code,
data: {
animated: emoteObject.animated,
owner: {
display_name: emoteObject.ownerName
},
host: {
files: sizes
}
}
});
}
}
module.exports = SevenTVEmote;
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>
</body>
</html>