@twitchfy/chatbot
Version:
A powerful node module to make your own Twitch ChatBot
88 lines (87 loc) • 2.95 kB
JavaScript
;
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.BaseStream = void 0;
const Base_1 = require("./Base");
const BaseUser_1 = require("./BaseUser");
const BaseClip_1 = require("./BaseClip");
/**
* The base class for a stream.
*/
class BaseStream extends Base_1.Base {
/**
* The id of the stream.
*/
id;
/**
* The type of the stream.
*/
type;
/**
* The broadcaster of the stream.
*/
broadcaster;
/**
* The base data of the stream.
*/
data;
/**
* Creates a new instance of the base stream.
* @param chatbot The current instance of the chatbot.
* @param data The base data of the stream.
*/
constructor(chatbot, data) {
super(chatbot);
this.data = data;
this.id = data.id;
this.type = data.type;
this.broadcaster = new BaseUser_1.BaseUser(chatbot, { id: data.user_id, login: data.user_login, display_name: data.user_name });
}
/**
* Creates a new clip of the stream.
* @param delay Whether to delay few seconds the clip or not.
*/
async createClip(delay) {
return new BaseClip_1.BaseClip(this.chatbot, await this.chatbot.helixClient.createClip(this.data.user_id, delay));
}
/**
* Fetches the current stream from the API.
* @returns The current stream or null if the stream is offline.
*/
async fetch() {
const { Stream } = await Promise.resolve().then(() => __importStar(require('./Stream')));
const data = await this.chatbot.helixClient.getStream({ user_id: this.broadcaster.id });
if (!data)
return null;
return new Stream(this.chatbot, data);
}
/**
* When the stream has started. Returns a JavaScript Date object.
*/
get startedAt() {
return new Date(this.data.started_at);
}
}
exports.BaseStream = BaseStream;