UNPKG

@twurple/easy-bot

Version:

A simplified framework to get a chat bot running easily.

99 lines (98 loc) 2.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BanEvent = void 0; const tslib_1 = require("tslib"); const shared_utils_1 = require("@d-fischer/shared-utils"); const chat_1 = require("@twurple/chat"); const common_1 = require("@twurple/common"); /** * An event representing a user getting banned from a channel. * * @meta category events */ let BanEvent = class BanEvent { /** @internal */ constructor(channel, userName, duration, msg, bot) { this._broadcasterName = (0, chat_1.toUserName)(channel); this._userName = userName; this._duration = duration; this._msg = msg; this._bot = bot; } /** * The ID of the broadcaster. */ get broadcasterId() { return this._msg.channelId; } /** * The name of the broadcaster. */ get broadcasterName() { return this._broadcasterName; } /** * Gets more information about the broadcaster. */ async getBroadcaster() { return (0, common_1.checkRelationAssertion)(await this._bot.api.users.getUserById(this.broadcasterId)); } /** * The ID of the user who was banned. */ get userId() { if (!this._msg.targetUserId) { throw new common_1.HellFreezesOverError('Ban event without target user received'); } return this._msg.targetUserId; } /** * The name of the user who was banned. */ get userName() { return this._userName; } /** * Gets more information about the user who was banned. */ async getUser() { return (0, common_1.checkRelationAssertion)(await this._bot.api.users.getUserById(this.userId)); } /** * The duration of the ban, or `null` if it's permanent. */ get duration() { return this._duration; } /** * Remove the ban. */ async unban() { await this._bot.unbanByIds(this.broadcasterId, this.userId); } /** * The full object that contains all the message information. */ get messageObject() { return this._msg; } }; exports.BanEvent = BanEvent; tslib_1.__decorate([ (0, shared_utils_1.Enumerable)(false) ], BanEvent.prototype, "_broadcasterName", void 0); tslib_1.__decorate([ (0, shared_utils_1.Enumerable)(false) ], BanEvent.prototype, "_userName", void 0); tslib_1.__decorate([ (0, shared_utils_1.Enumerable)(false) ], BanEvent.prototype, "_duration", void 0); tslib_1.__decorate([ (0, shared_utils_1.Enumerable)(false) ], BanEvent.prototype, "_msg", void 0); tslib_1.__decorate([ (0, shared_utils_1.Enumerable)(false) ], BanEvent.prototype, "_bot", void 0); exports.BanEvent = BanEvent = tslib_1.__decorate([ (0, common_1.rtfm)('easy-bot', 'BanEvent', 'userId') ], BanEvent);