UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

825 lines 39.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChatHandler = void 0; const base_handler_1 = require("./base.handler"); const chat_service_sdk_1 = require("../services/chat.service.sdk"); const confirmation_1 = require("../utils/confirmation"); const errors_1 = require("../utils/errors"); class ChatHandler extends base_handler_1.BaseHandler { constructor(authConfig, serviceConfig) { super(); this.chatService = new chat_service_sdk_1.ChatServiceSdk(authConfig, serviceConfig); } async sendAdminMessage(options) { return this.executeWithErrorHandling(async () => { this.validateSendOptions(options); const result = await this.chatService.sendAdminMessage(options); this.displaySendResult(result, options.output); }, 'chat.send'); } async listMessages(options) { return this.executeWithErrorHandling(async () => { this.validateListOptions(options); const result = await this.chatService.listMessages(options); this.displayListResult(result, options); }, 'chat.list'); } async deleteMessage(options) { return this.executeWithErrorHandling(async () => { this.validateDeleteOptions(options); if (!options.force) { if (!options.clear) { const confirmed = await (0, confirmation_1.confirmDeletion)(`Are you sure you want to delete message "${options.messageId}"? This action cannot be undone.`, 'yes'); if (!confirmed) { this.displayInfo('Operation cancelled'); return; } } else { const confirmed = await (0, confirmation_1.confirmDeletion)('Are you sure you want to clear all chat messages? This action cannot be undone.', 'yes'); if (!confirmed) { this.displayInfo('Operation cancelled'); return; } } } await this.chatService.deleteMessage(options); this.displayDeleteResult(options); }, 'chat.delete'); } async getGroupLoginTimes(options) { return this.executeWithErrorHandling(async () => { if (!options.channelId || options.channelId.trim() === '') { throw new errors_1.PolyVValidationError('channelId is required', 'channelId', options.channelId, 'validation_failed'); } this.displayData(await this.chatService.getGroupLoginTimes({ channelId: options.channelId }), options.output || 'table'); }, 'chat.group-login-times.get'); } async sendHiddenMessage(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId', 'userId']); this.validateContentOrImage(options); const result = await this.chatService.sendChat(options); this.displayGenericResult(result, options.output, 'Hidden message sent successfully'); }, 'chat.message.hidden-send'); } async sendHiddenByAdmin(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId', 'content', 'role']); const result = await this.chatService.sendHiddenByAdmin(options); this.displayGenericResult(result, options.output, 'Admin hidden message sent successfully'); }, 'chat.message.admin-send'); } async countOnlineUser(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId']); const result = await this.chatService.getChatOnlineCount(options.channelId); this.displayGenericResult({ channelId: options.channelId, onlineUserCount: result }, options.output); }, 'chat.message.online-count'); } async removeChatContents(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId', 'ids']); if (!(await this.confirmIfNeeded(options.force, `Remove chat message(s) ${options.ids.join(',')} from channel ${options.channelId}?`))) return; const result = await this.chatService.removeChatContents({ channelId: options.channelId, ids: options.ids, }); this.displayGenericResult(result, options.output, 'Chat message(s) removed successfully'); }, 'chat.message.remove-contents'); } async listSpeak(options) { return this.executeWithErrorHandling(async () => { const result = await this.chatService.getSpeakList(options); this.displayGenericResult(result, options.output); }, 'chat.message.speak-list'); } async alertToSpecial(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId', 'title', 'message']); if (!(await this.confirmIfNeeded(options.force, `Send popup alert to channel ${options.channelId}?`))) return; const result = await this.chatService.alertToSpecial(options); this.displayGenericResult(result, options.output, 'Popup alert sent successfully'); }, 'chat.message.alert-special'); } async auditMessage(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId', 'msgId', 'viewerId', 'nickName', 'content']); if (!(await this.confirmIfNeeded(options.force, `Submit audited chat message ${options.msgId}?`))) return; const result = await this.chatService.messageAudit({ channelId: options.channelId, messages: [{ msgId: options.msgId, viewerId: options.viewerId, nickName: options.nickName, content: options.content, avatar: options.avatar, sessionId: options.sessionId, viewerType: options.viewerType }] }); this.displayGenericResult(result, options.output, 'Audited message submitted successfully'); }, 'chat.message.audit'); } async sendCustomMessage(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId']); this.validateContentOrImage(options); if (!(await this.confirmIfNeeded(options.force, `Send custom message to channel ${options.channelId}?`))) return; const result = await this.chatService.sendCustomMessage(options); this.displayGenericResult(result ?? { success: true }, options.output, 'Custom message sent successfully'); }, 'chat.message.custom-send'); } async sendCustomMessageEncode(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId']); this.validateContentOrImage(options); if (!(await this.confirmIfNeeded(options.force, `Send encoded custom message to channel ${options.channelId}?`))) return; const result = await this.chatService.sendCustomMessageEncode(options); this.displayGenericResult(result ?? { success: true }, options.output, 'Encoded custom message sent successfully'); }, 'chat.message.custom-send-encode'); } async emitByUserId(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['roomId', 'payload']); if (!options.userIds || options.userIds.length === 0) { throw new errors_1.PolyVValidationError('userIds is required', 'userIds', options.userIds, 'validation_failed'); } if (!(await this.confirmIfNeeded(options.force, `Broadcast message to ${options.userIds.length} users in room ${options.roomId}?`))) return; const result = await this.chatService.emitByUserId(options); this.displayGenericResult(result ?? { success: true }, options.output, 'Broadcast message sent successfully'); }, 'chat.message.emit-by-user-id'); } async listUserBadwords(options) { return this.executeWithErrorHandling(async () => { const result = await this.chatService.getUserBadwordList(); this.displayGenericResult(result, options.output); }, 'chat.badword.list'); } async addBadwords(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['userId']); if (!options.words || options.words.length === 0) { throw new errors_1.PolyVValidationError('words is required', 'words', options.words, 'validation_failed'); } if (!(await this.confirmIfNeeded(options.force, `Add ${options.words.length} badword(s)?`))) return; const result = await this.chatService.addBadwords(options); this.displayGenericResult(result, options.output, 'Badwords added successfully'); }, 'chat.badword.add'); } async deleteUserBadword(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['words']); if (!(await this.confirmIfNeeded(options.force, `Delete account badword(s): ${options.words}?`))) return; const result = await this.chatService.deleteUserBadword({ words: options.words }); this.displayGenericResult(result, options.output, 'Account badwords deleted successfully'); }, 'chat.badword.delete'); } async addBannedIp(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId', 'ip']); if (!(await this.confirmIfNeeded(options.force, `Ban IP ${options.ip} in channel ${options.channelId}?`))) return; const result = await this.chatService.addBannedIp({ channelId: options.channelId, ip: options.ip }); this.displayGenericResult(result, options.output, 'IP banned successfully'); }, 'chat.banned.ip-add'); } async listUserBanned(options) { return this.executeWithErrorHandling(async () => { const result = await this.chatService.getUserBannedList(this.compactOptions({ page: options.page, size: options.size })); this.displayGenericResult(result, options.output); }, 'chat.banned.user-list'); } async listForbidUsers(options) { return this.executeWithErrorHandling(async () => { const result = await this.chatService.getForbidUserList(options); this.displayGenericResult(result, options.output); }, 'chat.banned.forbid-list'); } async deleteChannelBanned(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId', 'type', 'content']); if (options.type !== 'ip' && options.type !== 'badword') { throw new errors_1.PolyVValidationError('type must be ip or badword', 'type', options.type, 'validation_failed'); } if (!(await this.confirmIfNeeded(options.force, `Delete ${options.type} from channel ${options.channelId}: ${options.content}?`))) return; const result = await this.chatService.deleteChannelBanned(options); this.displayGenericResult(result, options.output, 'Channel banned item deleted successfully'); }, 'chat.banned.delete'); } async listBulletins(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId']); const result = await this.chatService.listBulletins(this.compactOptions({ channelId: options.channelId, pageNumber: options.pageNumber || 1, pageSize: options.pageSize || 20, sort: options.sort })); this.displayGenericResult(result, options.output); }, 'chat.notice.list'); } async addBulletin(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId', 'content']); this.validateYN('isTop', options.isTop); this.validateYN('isPop', options.isPop); if (!(await this.confirmIfNeeded(options.force, `Add notice to channel ${options.channelId}?`))) return; const result = await this.chatService.addBulletin(options); this.displayGenericResult(result, options.output, 'Notice added successfully'); }, 'chat.notice.add'); } async cleanNotices(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId']); if (!(await this.confirmIfNeeded(options.force, `Clear all notices for channel ${options.channelId}?`))) return; const result = await this.chatService.cleanNotices({ channelId: options.channelId }); this.displayGenericResult(result ?? { success: true }, options.output, 'Notices cleared successfully'); }, 'chat.notice.clean'); } async listQa(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId']); const result = await this.chatService.listQa({ channelId: options.channelId, pageNumber: options.pageNumber || 1, pageSize: options.pageSize || 20 }); this.displayGenericResult(result, options.output); }, 'chat.qa.list'); } async updateCensorEnabled(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId']); this.validateYN('enabled', options.enabled); if (!(await this.confirmIfNeeded(options.force, `Update chat censor setting for channel ${options.channelId}?`))) return; const result = await this.chatService.updateCensorEnabled(this.compactOptions({ channelId: options.channelId, enabled: options.enabled })); this.displayGenericResult(result, options.output, 'Chat censor setting updated successfully'); }, 'chat.censor.update'); } async getAdminInfo(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId']); const result = await this.chatService.getAdminInfo({ channelId: options.channelId }); this.displayGenericResult(result, options.output); }, 'chat.role.admin-get'); } async updateAdminInfo(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId', 'nickname', 'actor', 'avatar']); if (!(await this.confirmIfNeeded(options.force, `Update admin info for channel ${options.channelId}?`))) return; const result = await this.chatService.updateAdminInfo(options); this.displayGenericResult(result, options.output, 'Admin info updated successfully'); }, 'chat.role.admin-update'); } async getTeacherInfo(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId']); const result = await this.chatService.getTeacherInfo({ channelId: options.channelId }); this.displayGenericResult(result, options.output); }, 'chat.role.teacher-get'); } async updateTeacherInfo(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId']); if (!(await this.confirmIfNeeded(options.force, `Update teacher info for channel ${options.channelId}?`))) return; const result = await this.chatService.updateTeacherInfo(options); this.displayGenericResult(result, options.output, 'Teacher info updated successfully'); }, 'chat.role.teacher-update'); } async getUserList(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['roomId']); const result = await this.chatService.getUserList(options); this.displayGenericResult(result, options.output); }, 'chat.role.user-list'); } async getRobotSetting(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId']); const result = await this.chatService.getRobotSetting({ channelId: options.channelId }); this.displayGenericResult(result, options.output); }, 'chat.robot.setting-get'); } async getRobotStats(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId']); const result = await this.chatService.getRobotStats({ channelId: options.channelId }); this.displayGenericResult(result, options.output); }, 'chat.robot.stats'); } async updateRobotSetting(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId', 'robotNumber', 'addRobotModel']); if (!(await this.confirmIfNeeded(options.force, `Update robot setting for channel ${options.channelId}?`))) return; const result = await this.chatService.updateRobotSetting(options); this.displayGenericResult(result ?? { success: true }, options.output, 'Robot setting updated successfully'); }, 'chat.robot.setting-update'); } async updateRobotListSetting(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId', 'robotNumber', 'addRobotModel']); this.validateYN('robotRandomMemberEnabled', options.robotRandomMemberEnabled); if (!(await this.confirmIfNeeded(options.force, `Update robot list setting for channel ${options.channelId}?`))) return; const result = await this.chatService.updateRobotListSetting(options); this.displayGenericResult(result ?? { success: true }, options.output, 'Robot list setting updated successfully'); }, 'chat.robot.list-update'); } async pauseRobot(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId']); if (!(await this.confirmIfNeeded(options.force, `Pause robot growth for channel ${options.channelId}?`))) return; const result = await this.chatService.pauseRobot({ channelId: options.channelId }); this.displayGenericResult(result ?? { success: true }, options.output, 'Robot paused successfully'); }, 'chat.robot.pause'); } async batchUpdateChatEnabled(options) { return this.executeWithErrorHandling(async () => { if (!options.channelIds || options.channelIds.length === 0) { throw new errors_1.PolyVValidationError('channelIds is required', 'channelIds', options.channelIds, 'validation_failed'); } this.validateYN('chatEnabled', options.chatEnabled); if (!(await this.confirmIfNeeded(options.force, `Update chat switch for channel(s) ${options.channelIds.join(',')}?`))) return; const result = await this.chatService.batchUpdateChatEnabled({ channelIds: options.channelIds, chatEnabled: options.chatEnabled, }); this.displayGenericResult(result ?? { success: true }, options.output, 'Chat switch updated successfully'); }, 'chat.enabled.update'); } async logoutWatchViewer(options) { return this.executeWithErrorHandling(async () => { this.validateRequiredOptions(options, ['channelId']); if (!(await this.confirmIfNeeded(options.force, `Log out viewer from watch page for channel ${options.channelId}?`))) return; const result = await this.chatService.logoutWatchViewer({ channelId: options.channelId, ...(options.token ? { token: options.token } : {}), }); this.displayGenericResult(result ?? { success: true }, options.output, 'Watch viewer logged out successfully'); }, 'chat.viewer.logout'); } validateRequiredOptions(options, fields) { const missing = fields.filter((field) => { const value = options[field]; return value === undefined || value === null || (typeof value === 'string' && value.trim() === ''); }); if (missing.length > 0) { throw new errors_1.PolyVValidationError(`Missing required options: ${missing.join(', ')}`, 'options', options, 'validation_failed'); } if (options.output && !['table', 'json'].includes(options.output)) { throw new errors_1.PolyVValidationError('output must be either "table" or "json"', 'output', options.output, 'validation_failed'); } } compactOptions(options) { return Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined)); } validateContentOrImage(options) { if (!options.content && !options.imgUrl) { throw new errors_1.PolyVValidationError('content or imgUrl is required', 'content', options, 'validation_failed'); } } validateYN(field, value) { if (value !== undefined && value !== 'Y' && value !== 'N') { throw new errors_1.PolyVValidationError(`${field} must be Y or N`, field, value, 'validation_failed'); } } async confirmIfNeeded(force, message) { if (force) { return true; } const confirmed = await (0, confirmation_1.confirmDeletion)(message, 'yes'); if (!confirmed) { this.displayInfo('Operation cancelled'); } return confirmed; } displayGenericResult(result, format, successMessage) { if (successMessage && format !== 'json') { this.displaySuccess(successMessage); } if (result !== undefined) { this.displayData(result, format || 'table'); } else if (format === 'json') { this.displayData({ success: true }, 'json'); } } displaySendResult(result, format) { const anyResult = result; const success = typeof anyResult['success'] === 'boolean' ? anyResult['success'] : anyResult['code'] === 200 || anyResult['status'] === 'success'; const data = { success, message: anyResult['message'] ?? result.message ?? '', data: anyResult['data'] ?? result.data, }; if (format === 'json') { this.displayData(data, 'json'); } else { this.displaySuccess(`Admin message sent successfully`, data, 'table'); } } displayListResult(result, options) { const messages = result.contents || []; const page = options.page || 1; const size = options.size || 20; if (messages.length === 0) { this.displayInfo(`No chat messages found for channel ${options.channelId}`); return; } const fromItem = (page - 1) * size + 1; const toItem = Math.min(fromItem + messages.length - 1, fromItem + size - 1); this.displayInfo(`Showing messages ${fromItem}-${toItem} (page ${page}, size ${size})`); if (options.output === 'json') { this.displayData(messages, 'json'); } else { this.displayMessagesTable(messages); } } displayMessagesTable(messages) { const tableData = messages.map((msg) => ({ 'Message ID': msg.id || '-', 'Content': this.truncateContent(msg.content || '', 50), 'Time': msg.time ? new Date(msg.time).toLocaleString() : '-', 'Sender': msg.user?.nick || '-', 'User Type': msg.user?.userType || '-', })); this.displayAsTable(tableData); } displayDeleteResult(options) { const data = { channelId: options.channelId, deleted: true, timestamp: new Date().toISOString(), ...(options.clear ? { cleared: 'all messages' } : { messageId: options.messageId }), }; if (options.output === 'json') { this.displayData(data, 'json'); } else { if (options.clear) { this.displaySuccess(`All chat messages cleared successfully`, data, 'table'); } else { this.displaySuccess(`Message ${options.messageId} deleted successfully`, data, 'table'); } } } truncateContent(content, maxLength) { if (content.length <= maxLength) { return content; } return content.substring(0, maxLength - 3) + '...'; } async banUser(options) { return this.executeWithErrorHandling(async () => { this.validateBanOptions(options); let result; if (options.global) { result = await this.chatService.updateBannedViewer({ viewerIds: options.userIds, banned: 'Y' }); this.displayBanResult(options, result, true); } else { result = await this.chatService.updateBannedUser({ channelId: options.channelId, userIds: options.userIds.join(','), toBanned: 'Y' }); this.displayBanResult(options, result, false); } }, 'chat.ban'); } async unbanUser(options) { return this.executeWithErrorHandling(async () => { this.validateBanOptions(options); let result; if (options.global) { result = await this.chatService.updateBannedViewer({ viewerIds: options.userIds, banned: 'N' }); this.displayUnbanResult(options, result, true); } else { result = await this.chatService.updateBannedUser({ channelId: options.channelId, userIds: options.userIds.join(','), toBanned: 'N' }); this.displayUnbanResult(options, result, false); } }, 'chat.unban'); } async kickUser(options) { return this.executeWithErrorHandling(async () => { this.validateKickOptions(options); let result; if (options.global) { result = await this.chatService.forbidKickUsers({ viewerIds: options.viewerIds, nickNames: options.nickNames }); } else { result = await this.chatService.forbidChannelKickUsers({ channelId: options.channelId, viewerIds: options.viewerIds, nickNames: options.nickNames }); } this.displayKickResult(options, result); }, 'chat.kick'); } async unkickUser(options) { return this.executeWithErrorHandling(async () => { this.validateKickOptions(options); let result; if (options.global) { result = await this.chatService.forbidUnkickUsers({ viewerIds: options.viewerIds, nickNames: options.nickNames }); } else { result = await this.chatService.forbidChannelUnkickUsers({ channelId: options.channelId, viewerIds: options.viewerIds, nickNames: options.nickNames }); } this.displayUnkickResult(options, result); }, 'chat.unkick'); } async listBanned(options) { return this.executeWithErrorHandling(async () => { this.validateBannedListOptions(options); let result; if (options.type === 'badword') { result = await this.chatService.getChannelBannedList({ channelId: options.channelId, type: 'badword' }); } else { result = await this.chatService.getChannelBannedUserList({ channelId: options.channelId, type: options.type }); } this.displayBannedListResult(options, result); }, 'chat.banned.list'); } async listKicked(options) { return this.executeWithErrorHandling(async () => { this.validateKickedListOptions(options); const result = await this.chatService.getChannelKickedUserList({ channelId: options.channelId }); this.displayKickedListResult(options, result); }, 'chat.kicked.list'); } validateSendOptions(options) { const errors = []; if (!options.channelId || options.channelId.trim() === '') { errors.push('channelId is required'); } if (!options.msg && !options.imgUrl) { errors.push('msg or imgUrl is required'); } if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Chat send options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateListOptions(options) { const errors = []; if (!options.channelId || options.channelId.trim() === '') { errors.push('channelId is required'); } if (options.page !== undefined) { if (typeof options.page !== 'number' || !Number.isInteger(options.page) || options.page < 1) { errors.push('page must be a positive integer'); } } if (options.size !== undefined) { if (typeof options.size !== 'number' || !Number.isInteger(options.size) || options.size < 1 || options.size > 100) { errors.push('pageSize must be an integer between 1 and 100'); } } if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Chat list options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateDeleteOptions(options) { const errors = []; if (!options.channelId || options.channelId.trim() === '') { errors.push('channelId is required'); } if (!options.clear && !options.messageId) { errors.push('messageId is required when --clear is not specified'); } if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Chat delete options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateBanOptions(options) { const errors = []; if (!options.global && (!options.channelId || options.channelId.trim() === '')) { errors.push('channelId is required when --global is not specified'); } if (!options.userIds || options.userIds.length === 0) { errors.push('userIds is required'); } if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Chat ban options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateKickOptions(options) { const errors = []; if (!options.global && (!options.channelId || options.channelId.trim() === '')) { errors.push('channelId is required when --global is not specified'); } if (!options.viewerIds && !options.nickNames) { errors.push('viewerIds and nickNames are required'); } if (options.viewerIds && options.nickNames && options.viewerIds.length !== options.nickNames.length) { errors.push('viewerIds and nickNames must have the same length'); } if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Chat kick options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateBannedListOptions(options) { const errors = []; if (!options.channelId || options.channelId.trim() === '') { errors.push('channelId is required'); } if (!['userId', 'ip', 'badword'].includes(options.type)) { errors.push('type must be one of: userId, ip, badword'); } if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Chat banned list options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } validateKickedListOptions(options) { const errors = []; if (!options.channelId || options.channelId.trim() === '') { errors.push('channelId is required'); } if (options.output && !['table', 'json'].includes(options.output)) { errors.push('output must be either "table" or "json"'); } if (errors.length > 0) { throw new errors_1.PolyVValidationError(`Chat kicked list options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } displayBanResult(options, result, isGlobal) { if (options.output === 'json') { this.displayData({ channelId: options.channelId, userIds: options.userIds, global: isGlobal, result }, 'json'); } else { const scopeText = isGlobal ? 'globally' : `in channel ${options.channelId}`; this.displaySuccess(`Users ${options.userIds.join(', ')} banned ${scopeText} successfully`); } } displayUnbanResult(options, result, isGlobal) { if (options.output === 'json') { this.displayData({ channelId: options.channelId, userIds: options.userIds, global: isGlobal, result }, 'json'); } else { const scopeText = isGlobal ? 'globally' : `in channel ${options.channelId}`; this.displaySuccess(`Users ${options.userIds.join(', ')} unbanned ${scopeText} successfully`); } } displayKickResult(options, result) { if (options.output === 'json') { this.displayData({ channelId: options.channelId, viewerIds: options.viewerIds, nickNames: options.nickNames, global: options.global, result }, 'json'); } else { const scopeText = options.global ? 'globally' : `in channel ${options.channelId}`; this.displaySuccess(`Users kicked ${scopeText} successfully`); } } displayUnkickResult(options, result) { if (options.output === 'json') { this.displayData({ channelId: options.channelId, viewerIds: options.viewerIds, nickNames: options.nickNames, global: options.global, result }, 'json'); } else { const scopeText = options.global ? 'globally' : `in channel ${options.channelId}`; this.displaySuccess(`Users unkicked ${scopeText} successfully`); } } displayBannedListResult(options, result) { if (options.output === 'json') { this.displayData({ channelId: options.channelId, type: options.type, data: result.data || [] }, 'json'); } else { const data = result.data || []; if (data.length === 0) { this.displayInfo(`No banned ${options.type} found in channel ${options.channelId}`); return; } if (options.type === 'badword') { this.displayAsTable(data.map((word) => ({ Badword: word }))); } else { this.displayAsTable(data.map((item) => ({ [options.type === 'userId' ? 'User ID' : 'IP']: item }))); } } } displayKickedListResult(options, result) { if (options.output === 'json') { this.displayData({ channelId: options.channelId, data: result.data || [] }, 'json'); } else { const data = result.data || []; if (data.length === 0) { this.displayInfo(`No kicked users found in channel ${options.channelId}`); return; } this.displayAsTable(data.map((user) => ({ 'User ID': user.userId || 'N/A', 'Nickname': user.nick || 'N/A', 'IP': user.clientIp || 'N/A', 'User Type': user.userType || 'N/A', 'Room ID': user.roomId || 'N/A' }))); } } } exports.ChatHandler = ChatHandler; //# sourceMappingURL=chat.handler.js.map