@twitchfy/chatbot
Version:
A powerful node module to make your own Twitch ChatBot
93 lines (92 loc) • 3.13 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.BaseUserWithoutUsername = void 0;
const Base_1 = require("./Base");
const User_1 = require("./User");
/**
* The base class for a user without an username.
*/
class BaseUserWithoutUsername extends Base_1.Base {
/**
* The id of the user.
*/
id;
/**
* The display name of the user.
*/
dislayName;
/**
* Creates a new instance of the base user without an username.
* @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.dislayName = data.display_name;
}
/**
* Fetches the current user from the API.
* @returns The fetched user from the API.
*/
async fetch() {
return new User_1.User(this.chatbot, await this.chatbot.helixClient.getUser(this.id));
}
/**
* Returns the mention of the user.
*/
toString() {
return `@${this.dislayName}`;
}
/**
* Fetches the current stream of the user from the API.
* @returns The current stream or null if the stream is offline.
*/
async stream() {
const { Stream } = await Promise.resolve().then(() => __importStar(require('./Stream')));
const data = await this.chatbot.helixClient.getStream({ user_id: this.id });
if (!data)
return null;
return new Stream(this.chatbot, data);
}
/**
* Returns whether the user is currently in stream or not.
* @returns A boolean indicating whether the user is currently streaming.
*/
async inStream() {
const stream = await this.stream();
return !!stream;
}
/**
* 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.BaseUserWithoutUsername = BaseUserWithoutUsername;