UNPKG

@twitchfy/chatbot

Version:

A powerful node module to make your own Twitch ChatBot

109 lines (108 loc) 3.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Clip = void 0; const BaseClip_1 = require("./BaseClip"); const Video_1 = require("./Video"); const BaseUserWithoutUsername_1 = require("./BaseUserWithoutUsername"); /** * Represents a Twitch clip. */ class Clip extends BaseClip_1.BaseClip { /** * The URL to embed the clip in a frame. */ embedURL; /** * The user who created the clip. The user will not have an username because Twitch limitations. */ creator; /** * The user who broadcasted the clip. The user will not have an username because Twitch limitations. */ broadcaster; /** * The Id of the game which was played in the clip. */ gameId; /** * The language of the clip. */ language; /** * The title of the clip. */ title; /** * The view count of the clip. */ viewCount; /** * The URL to the thumbnail of the clip. */ thumbnailURL; /** * The duration of the clip in seconds. */ duration; /** * The offset in the VOD where the clip starts. If the clip is not from a VOD, this will be null. */ vodOffset; /** * Whether the clip is featured. */ isFeatured; /** * The data of the clip returned from the API. */ data; /** * Creates a new instance of the clip. * @param chatbot The current instance of the chatbot. * @param data The data of the clip returned from the API. */ constructor(chatbot, data) { super(chatbot, data); this.data = data; this.embedURL = data.embed_url; this.creator = new BaseUserWithoutUsername_1.BaseUserWithoutUsername(chatbot, { id: data.creator_id, display_name: data.creator_name }); this.broadcaster = new BaseUserWithoutUsername_1.BaseUserWithoutUsername(chatbot, { id: data.broadcaster_id, display_name: data.broadcaster_name }); this.gameId = data.game_id; this.language = data.language; this.title = data.title; this.viewCount = data.view_count; this.thumbnailURL = data.thumbnail_url; this.duration = data.duration; this.vodOffset = data.vod_offset; this.isFeatured = data.is_featured; } /** * When the clip was created. Returns a JavaScript Date object. */ get createdAt() { return new Date(this.data.created_at); } /** * The Id of the video of the clip. */ get videoId() { return this.data.video_id.length ? this.data.video_id : null; } /** * Fetches the video of the clip. * @returns The video of the clip. Returns null if the video doesn't exist. */ async video() { if (!this.videoId) return null; return new Video_1.Video(this.chatbot, await this.chatbot.helixClient.getVideo({ id: this.videoId })); } /** * Fetches the stream of the broadcaster of the clip. * @returns The stream of the broadcaster of the clip. If the stream is offline, it will return null. */ async stream() { return await this.chatbot.stream({ user_id: this.broadcaster.id }); } } exports.Clip = Clip;