UNPKG

@twitchfy/chatbot

Version:

A powerful node module to make your own Twitch ChatBot

104 lines (103 loc) 3.29 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.BaseUser = void 0; const Base_1 = require("./Base"); /** * The base class for a user. */ class BaseUser extends Base_1.Base { /** * The id of the user. */ id; /** * The username of the user. */ username; /** * The display name of the user. */ displayName; /** * Creates a new instance of the base user. * @param chatbot The current instance of the chatbot. * @param data The base data of the user. */ constructor(chatbot, data) { super(chatbot); this.id = data.id; this.username = data.login; this.displayName = data.display_name; } /** * Gets the chatroom of the user. * @returns The chatroom of the user. */ async chatroom() { const { ChatRoom } = await Promise.resolve().then(() => __importStar(require('./ChatRoom'))); return new ChatRoom(this.chatbot, { broadcaster_id: this.id, broadcaster_login: this.username, broadcaster_name: this.displayName }); } /** * Fetches the current user from the API. * @returns The fetched user from the API. */ async fetch() { return this.chatbot.users.fetch(this.id); } /** * Returns the mention of the user. */ toString() { return `@${this.displayName}`; } /** * Fetches the current stream of the user from the API. * @returns The current stream or null if the stream is offline. */ async stream() { return await this.chatbot.stream({ user_id: this.id }); } /** * Checks whether the user is currently streaming. * @returns A boolean indicating whether the user is currently streaming. */ async inStream() { const stream = await this.stream(); return !!stream; } async channel() { return await this.chatbot.channels.fetch(this.id); } /** * Sends a whisper to the user. * @param message The message to send. * @returns */ async whisper(message) { return await this.chatbot.helixClient.sendWhisper(this.chatbot.userId, this.id, { message }); } } exports.BaseUser = BaseUser;