UNPKG

@twitchfy/chatbot

Version:

A powerful node module to make your own Twitch ChatBot

130 lines (129 loc) 4.46 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.BaseChannel = void 0; const Base_1 = require("./Base"); const BaseUser_1 = require("./BaseUser"); const ChannelEmote_1 = require("./ChannelEmote"); const Collection_1 = require("./Collection"); class BaseChannel extends Base_1.Base { /** * The id of the channel. */ id; /** * The broadcaster of the channel. */ broadcaster; /** * The chatroom of the channel. */ chatroom; constructor(chatbot, data, chatroom) { super(chatbot); this.id = data.broadcaster_id; this.broadcaster = new BaseUser_1.BaseUser(chatbot, { id: data.broadcaster_id, login: data.broadcaster_login, display_name: data.broadcaster_name }); this.chatroom = chatroom; } /** * The id of the broadcaster who owns the channel. */ get broadcasterId() { return this.broadcaster.id; } /** * The id of the chatroom of the channel. */ get chatroomId() { return this.broadcaster.id; } /** * The chatroom bans manager. See {@link BanManager}. */ get bans() { return this.chatroom.bans; } /** * The chatroom timeouts manager. See {@link TimeoutManager}. */ get timeouts() { return this.chatroom.timeouts; } /** * The chatroom messages manager. See {@link MessageManager}. */ get messages() { return this.chatroom.messages; } /** * The chatroom warns manager. See {@link WarnsManager}. */ get warns() { return this.chatroom.warns; } /** * The chatroom chatters manager. See {@link ChatterManager}. */ get chatters() { return this.chatroom.chatters; } /** * Fetches all the emotes of this channel. * @returns The a Collection containing all the emotes of the channel. */ async emotes() { const data = await this.chatbot.helixClient.getChannelEmotes(this.broadcaster.id); return new Collection_1.Collection(data.emotes.map(emote => [emote.id, new ChannelEmote_1.ChannelEmote(this.chatbot, { ...emote, owner_id: this.broadcaster.id, template: data.template })])); } /** * Fetches the current stream of the channel from the API. * @returns The current stream or null if the stream is offline. */ async stream() { return await this.chatbot.stream({ user_id: this.broadcaster.id }); } /** * Fetches the clips of the channel from the API. * @param options The options to fetch the clips. * @returns An array containing the clips of the channel. */ async clips(options) { if (options?.id) return await this.chatbot.clips(options); return await this.chatbot.clips({ ...options, broadcaster_id: this.broadcaster.id }); } async isModerator() { return await this.chatbot.isModerator(this.broadcaster.id); } /** * Fetches the current channel from the API. * @returns The fetched channel from the API. */ async fetch() { const { Channel } = await Promise.resolve().then(() => __importStar(require('./Channel'))); return new Channel(this.chatbot, await this.chatbot.helixClient.getChannel(this.broadcaster.id)); } } exports.BaseChannel = BaseChannel;