UNPKG

@twitchfy/chatbot

Version:

A powerful node module to make your own Twitch ChatBot

140 lines (139 loc) 3.74 kB
"use strict"; /* eslint-disable @typescript-eslint/ban-types */ /* eslint-disable @typescript-eslint/ban-ts-comment */ Object.defineProperty(exports, "__esModule", { value: true }); exports.TwitchContext = 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 TwitchContext extends Base_1.Base { /** * The message received when the command was run. */ message; /** * The options of the command. */ options; /** * The prefix used to run the command. */ prefix; /** * The name of the command. */ commandName; /** * The author of the command. */ author; /** * The chatroom where the command was run. */ chatroom; /** * The data of the command. */ // @ts-ignore data; /** * 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, { ...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. */ async reply(message) { return await this.message.reply(message); } /** * Checks whether the bot is moderator in this context. * @returns A boolean indicating whether the bot is moderator. */ async isModerator() { return await this.channel.isModerator(); } /** * Fetches the stream which is currently live in the context. If the stream is offline, it will return null. */ async stream() { return await this.author.stream(); } /** * Checks whether the author is a moderator in the context. */ async inStream() { return await 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.TwitchContext = TwitchContext;