UNPKG

@twitchfy/chatbot

Version:

A powerful node module to make your own Twitch ChatBot

117 lines (116 loc) 3.86 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseEmote = void 0; const Base_1 = require("./Base"); /** * The base emote class. */ class BaseEmote extends Base_1.Base { /** * The id of the emote. */ id; /** * The name of the emote. */ name; /** * The base data of the emote. */ data; /** * Creates a new instance of the base emote. * @param chatbot The current instance of the chatbot. * @param data The base data of the emote. */ constructor(chatbot, data) { super(chatbot); this.data = data; this.id = data.id; this.name = data.name; } /** * The Id of the owner of the emote. */ get ownerId() { return this.data.owner_id === '0' ? null : this.data.owner_id; } /** * The Id of the emote set. */ get setId() { return this.data.emote_set_id === '0' ? null : this.data.emote_set_id; } /** * Whether the emote is static. */ get static() { return this.data.format.includes('static'); } /** * Whether the emote is animated. */ get animated() { return this.data.format.includes('animated'); } /** * Check if the emote is a global Twitch emote. * @returns A boolean indicating whether the emote is a global Twitch emote. */ isGlobal() { return this.data.owner_id === '0'; } /** * Check if the emote is a custom channel emote. * @returns A boolean indicating whether the emote is a channel emote. */ isChannel() { return this.data.owner_id !== '0'; } /** * Fetches the emote from the API. * @returns The fetched emote. Returns null if the emote was not found. */ async fetch() { const { ChannelEmote } = await Promise.resolve().then(() => __importStar(require('./ChannelEmote'))); const { GlobalEmote } = await Promise.resolve().then(() => __importStar(require('./GlobalEmote'))); if (this.isChannel()) { const emoteData = await this.chatbot.helixClient.getChannelEmotes(this.data.owner_id); const emote = emoteData.emotes.find((x) => x.id === this.data.id); if (!emote) return null; return new ChannelEmote(this.chatbot, { ...emote, template: emoteData.template, owner_id: this.data.owner_id }); } else { const emoteData = await this.chatbot.helixClient.getGlobalEmotes(); const emote = emoteData.emotes.find((x) => x.id === this.data.id); if (!emote) return null; return new GlobalEmote(this.chatbot, { ...emote, template: emoteData.template }); } } } exports.BaseEmote = BaseEmote;