@twitchfy/chatbot
Version:
A powerful node module to make your own Twitch ChatBot
152 lines (151 loc) • 5.34 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChatRoom = void 0;
const Base_1 = require("./Base");
const BaseUser_1 = require("./BaseUser");
const AutoMod_1 = require("./AutoMod");
const BaseChannel_1 = require("./BaseChannel");
const managers_1 = require("./managers");
const managers_2 = require("./managers");
/**
* Represents a Twitch chatroom of a channel.
*/
class ChatRoom extends Base_1.Base {
/**
* The broadcaster who owns the chatroom.
*/
broadcaster;
/**
* The channel of the chatroom.
*/
channel;
/**
* The ban manager of the chatroom.
*/
bans;
/**
* The timeout manager of the chatroom.
*/
timeouts;
/**
* The settings manager of the chatroom.
*/
settings;
/**
* The warns manager of the chatroom.
*/
warns;
/**
* The chatters manager of the chatroom.
*/
chatters;
/**
* The automod manager of the chatroom.
*/
automod;
/**
* The message manager of the chatroom.
*/
messages;
/**
* The data of the chatroom.
*/
data;
/**
* Creates a new instance of the chatroom.
* @param chatbot The current instance of the chatbot.
* @param data The data of the chatroom.
*/
constructor(chatbot, data) {
super(chatbot);
this.data = data;
this.broadcaster = new BaseUser_1.BaseUser(chatbot, { id: data.broadcaster_id, login: data.broadcaster_login, display_name: data.broadcaster_name });
this.channel = new BaseChannel_1.BaseChannel(chatbot, data, this);
this.bans = new managers_2.BanManager(this.chatbot, this);
this.timeouts = new managers_2.TimeoutManager(this.chatbot, this);
this.settings = new managers_2.ChatRoomSettingsManager(this.chatbot, this);
this.messages = new managers_2.MessageManager(this.chatbot, this);
this.warns = new managers_2.WarnsManager(this.chatbot, this);
this.chatters = new managers_1.ChatterManager(this.chatbot, this);
this.automod = new AutoMod_1.AutoMod(this.chatbot, this);
}
/**
* The Id of the chatroom. Its id is the same as the broadcaster id.
*/
get id() {
return this.data.broadcaster_id;
}
/**
* Sends a message to the chatroom.
* @param message The message to send.
* @returns The message that was sent. See {@link BaseMessage}
*/
async send(message) {
return await this.chatbot.messages.send(this.id, message);
}
/**
* Sets the slow mode of the chatroom.
* @param duration The duration of the slow mode in seconds. If null, it will disable the slow mode.
* @returns The updated settings of the chatroom.
*/
async setSlowMode(duration) {
return await this.settings.edit({ slow_mode: !!duration, slow_mode_wait_time: duration });
}
/**
* Sets the followers mode of the chatroom.
* @param duration The time, in seconds, the followers must be following the broadcaster to be able to send a message. If null, it will disable the followers mode.
* @returns The updated settings of the chatroom.
*/
async setFollowersMode(duration) {
return await this.settings.edit({ follower_mode: !!duration, follower_mode_duration: duration / 60 });
}
/**
* Sets the subscribers mode of the chatroom.
* @param enabled Whether the subscribers mode is enabled.
* @returns The updated settings of the chatroom.
*/
async setSubscribersMode(enabled) {
return await this.settings.edit({ subscriber_mode: enabled });
}
/**
* Sets the unique messages mode of the chatroom.
* @param enabled Whether the unique messages mode is enabled.
* @returns The updated settings of the chatroom.
*/
async setUniqueMessagesMode(enabled) {
return await this.settings.edit({ unique_chat_mode: enabled });
}
/**
* Sets the chat delay of the chatroom.
* @param duration The duration of the chat delay in seconds. If null, it will disable the chat delay.
* @returns The updated settings of the chatroom.
*/
async setChatDelay(duration) {
return await this.settings.edit({ non_moderator_chat_delay: !!duration, non_moderator_chat_delay_duration: duration });
}
/**
* Sets the emote only mode of the chatroom.
* @param enabled Whether the emote only mode is enabled.
* @returns The updated settings of the chatroom.
*/
async setEmoteOnlyMode(enabled) {
return await this.settings.edit({ emote_mode: enabled });
}
/**
* Sends an announcement to the chatroom.
* @param options The options of the announcement. See {@link AnnouncementOptions}
* @returns The announcement that was sent.
*/
async announce(options) {
return await this.chatbot.helixClient.sendAnnouncement(this.id, this.chatbot.userId, options);
}
/**
* Sends a shoutout to a user in the chatroom.
* @param receiverId The Id of the user to shoutout.
* @returns The shoutout that was sent.
*/
async shoutout(receiverId) {
return await this.chatbot.helixClient.sendShoutout(this.id, receiverId, this.chatbot.userId);
}
}
exports.ChatRoom = ChatRoom;