UNPKG

@twitchfy/chatbot

Version:

A powerful node module to make your own Twitch ChatBot

128 lines (127 loc) 4.24 kB
"use strict"; /* eslint-disable @typescript-eslint/ban-types */ /* eslint-disable @typescript-eslint/ban-ts-comment */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommandContext = void 0; const Base_1 = require("./Base"); const Message_1 = require("./Message"); const Author_1 = require("./Author"); const ChatRoom_1 = require("./ChatRoom"); /** * The context of the command. */ class CommandContext extends Base_1.Base { /** * Creates a new instance of the command context. * @param chatbot The current instance of the chatbot. * @param data The data of the command. */ constructor(chatbot, data) { super(chatbot); this.data = data; this.options = data.options; this.prefix = data.prefix; this.commandName = data.commandName; this.author = new Author_1.Author(this.chatbot, Object.assign(Object.assign({}, data.chatter), { display_name: data.chatter.displayName })); this.chatroom = new ChatRoom_1.ChatRoom(this.chatbot, { broadcaster_id: data.broadcaster.id, broadcaster_login: data.broadcaster.login, broadcaster_name: data.broadcaster.displayName }); this.message = new Message_1.Message(this.chatbot, data, this.chatroom); } /** * Replies to the message of the command. * @param message The message to reply. */ reply(message) { return __awaiter(this, void 0, void 0, function* () { return yield this.message.reply(message); }); } /** * Checks whether the bot is moderator in this context. * @returns A boolean indicating whether the bot is moderator. */ isModerator() { return __awaiter(this, void 0, void 0, function* () { return yield this.channel.isModerator(); }); } /** * Fetches the stream which is currently live in the context. If the stream is offline, it will return null. */ stream() { return __awaiter(this, void 0, void 0, function* () { return yield this.author.stream(); }); } /** * Checks whether the author is a moderator in the context. */ inStream() { return __awaiter(this, void 0, void 0, function* () { return yield this.author.inStream(); }); } /** * The ID of the author of the command. */ get authorID() { return this.author.id; } /** * The content of the context's message. This message is parsed so it will return the message without the prefix and the command name. */ get content() { return this.message.content; } /** * The ID of the context's chatroom. */ get chatroomID() { return this.chatroom.id; } /** * The context's broadcaster. */ get broadcaster() { return this.chatroom.broadcaster; } /** * The mentions of the context's message. */ get mentions() { return this.message.mentions; } /** * The emotes of the context's message. */ get emotes() { return this.message.emotes; } /** * The cheermotes of the context's message. */ get cheermotes() { return this.message.cheermotes; } /** * The bits cheered in the context's message. */ get bits() { return this.message.bits; } /** * Fetches channel of the context's chatroom. */ get channel() { return this.chatroom.channel; } } exports.CommandContext = CommandContext;