UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

436 lines 18.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChatServiceSdk = void 0; const errors_1 = require("../utils/errors"); const sdk_1 = require("../sdk"); const fs_1 = require("fs"); const path_1 = require("path"); const buffer_1 = require("buffer"); function compactParams(params) { return Object.fromEntries(Object.entries(params).filter(([, value]) => value !== undefined)); } class ChatServiceSdk { constructor(authConfig, serviceConfig) { this.authConfig = authConfig; this.config = serviceConfig; } async sendAdminMessage(options) { this.validateSendOptions(options); const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); const params = { channelId: options.channelId, }; if (options.msg) params.msg = options.msg; if (options.imgUrl) params.imgUrl = options.imgUrl; if (options.pic) params.pic = options.pic; if (options.nickName) params.nickName = options.nickName; if (options.actor) params.actor = options.actor; if (options.adminIndex !== undefined) params.adminIndex = options.adminIndex; return await client.chat.sendAdminMsg(params); } async listMessages(options) { this.validateListOptions(options); const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); const params = { channelId: options.channelId, }; if (options.startDay) params.startDay = options.startDay; if (options.endDay) params.endDay = options.endDay; if (options.page !== undefined) params.page = options.page; if (options.size !== undefined) params.pageSize = options.size; if (options.userType) params.userType = options.userType; if (options.status) params.status = options.status; return await client.chat.getHistoryPage(params); } async deleteMessage(options) { this.validateDeleteOptions(options); const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); if (options.clear) { await client.chat.cleanChat({ channelId: options.channelId, }); } else if (options.messageId) { await client.chat.delChat({ channelId: options.channelId, id: options.messageId, }); } } async updateBannedUser(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.updateBannedUser({ channelId: options.channelId, userIds: options.userIds, toBanned: options.toBanned, }); } async updateBannedViewer(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.updateBannedViewer({ viewerIds: options.viewerIds, banned: options.banned, }); } async forbidChannelKickUsers(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.forbidChannelKickUsers({ channelId: options.channelId }, { viewerIds: options.viewerIds, nickNames: options.nickNames }); } async forbidKickUsers(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.forbidKickUsers({ viewerIds: options.viewerIds, nickNames: options.nickNames, }); } async forbidChannelUnkickUsers(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.forbidChannelUnkickUsers({ channelId: options.channelId }, { viewerIds: options.viewerIds, nickNames: options.nickNames }); } async forbidUnkickUsers(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.forbidUnkickUsers({ viewerIds: options.viewerIds, nickNames: options.nickNames, }); } async getChannelBannedUserList(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.getChannelBannedUserList({ channelId: options.channelId, type: options.type, }); } async getChannelBannedList(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); const params = { channelId: options.channelId, }; if (options.type) { params.type = options.type; } return await client.chat.getChannelBannedList(params); } async getChannelKickedUserList(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.getChannelKickedUserList({ channelId: options.channelId, }); } async getGroupLoginTimes(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.other.getGroupLoginTimes({ channelId: options.channelId, }); } async sendChat(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.sendChat(compactParams({ channelId: options.channelId, userId: options.userId, content: options.content, imgUrl: options.imgUrl, })); } async sendHiddenByAdmin(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.sendHiddenByAdmin(compactParams({ channelId: options.channelId, content: options.content, role: options.role, })); } async countOnlineUser(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.countOnlineUser(options); } async getChatOnlineCount(channelId) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.channel.getChatOnlineCount(channelId); } async removeChatContents(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.channel.removeChatContents(options); } async getSpeakList(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.getSpeakList(compactParams({ startTime: options.startTime, endTime: options.endTime, cursor: options.cursor, size: options.size, })); } async alertToSpecial(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.alertToSpecial(compactParams({ channelId: options.channelId, title: options.title, message: options.message, })); } async messageAudit(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.messageAudit(compactParams({ channelId: options.channelId, messages: options.messages, })); } async sendCustomMessage(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.v4Chat.sendCustomMessage(compactParams({ channelId: options.channelId, content: options.content, imgUrl: options.imgUrl, joinHistoryList: options.joinHistoryList, watchType: options.watchType, important: options.important, })); } async sendCustomMessageEncode(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.v4Chat.sendCustomMessageEncode(compactParams({ channelId: options.channelId, content: options.content, imgUrl: options.imgUrl, joinHistoryList: options.joinHistoryList, watchType: options.watchType, })); } async emitByUserId(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.other.emitByUserId(compactParams({ roomId: options.roomId, userIds: options.userIds, payload: options.payload, })); } async getUserBadwordList() { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.getUserBadwordList(); } async addBadwords(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.addBadwords(compactParams({ userId: options.userId, words: options.words, channelId: options.channelId, })); } async deleteUserBadword(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.deleteUserBadword(options); } async addBannedIp(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.addBannedIp(options); } async getUserBannedList(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.getUserBannedList(compactParams({ page: options.page, size: options.size, })); } async getForbidUserList(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.getForbidUserList(compactParams({ viewerId: options.viewerId, nickName: options.nickName, pageNumber: options.pageNumber, pageSize: options.pageSize, })); } async deleteChannelBanned(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.deleteChannelBanned(compactParams({ channelId: options.channelId, type: options.type, content: options.content, })); } async listBulletins(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.v4Chat.listBulletins(compactParams({ channelId: options.channelId, pageNumber: options.pageNumber, pageSize: options.pageSize, sort: options.sort, })); } async addBulletin(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.v4Chat.addBulletin(compactParams({ channelId: options.channelId, content: options.content, isTop: options.isTop, isPop: options.isPop, })); } async cleanNotices(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.v4Chat.cleanNotices(options); } async listQa(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.v4Chat.listQa(compactParams({ channelId: options.channelId, pageNumber: options.pageNumber, pageSize: options.pageSize, })); } async updateCensorEnabled(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.updateCensorEnabled(compactParams({ channelId: options.channelId, enabled: options.enabled, })); } async getAdminInfo(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.getAdminInfo(options.channelId); } async updateAdminInfo(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.updateAdminInfo({ channelId: options.channelId, nickname: options.nickname, actor: options.actor, avatar: this.readFile(options.avatar), }); } async getTeacherInfo(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.getTeacherInfo(options); } async updateTeacherInfo(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.updateTeacherInfo(compactParams({ channelId: options.channelId, nickname: options.nickname, actor: options.actor, passwd: options.passwd, avatar: options.avatar, })); } async getUserList(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.chat.getUserList(compactParams({ roomId: options.roomId, page: options.page, len: options.len, toGetSubRooms: options.toGetSubRooms, })); } async getRobotSetting(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.v4Chat.getRobotSetting(options); } async getRobotStats(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.v4Robot.getRobotStats(options); } async updateRobotSetting(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.v4Robot.updateRobotSetting(compactParams({ channelId: options.channelId, robotNumber: options.robotNumber, addRobotModel: options.addRobotModel, changeTime: options.changeTime, virtualBookingNumber: options.virtualBookingNumber, })); } async updateRobotListSetting(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.v4Chat.updateRobotListSetting(compactParams({ channelId: options.channelId, robotNumber: options.robotNumber, addRobotModel: options.addRobotModel, changeTime: options.changeTime, virtualBookingNumber: options.virtualBookingNumber, robotList: options.robotList, robotRandomMemberEnabled: options.robotRandomMemberEnabled, })); } async pauseRobot(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.v4Robot.pauseRobot(options); } async batchUpdateChatEnabled(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.v4Channel.batchUpdateChatEnabled({ channelIds: options.channelIds, chatEnabled: options.chatEnabled, }); } async logoutWatchViewer(options) { const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl); return await client.v4Channel.logoutWatchViewer(compactParams({ channelId: options.channelId, token: options.token, })); } 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 && (typeof options.page !== 'number' || options.page < 1)) { errors.push('page must be a positive integer'); } if (options.size !== undefined && (typeof options.size !== 'number' || options.size < 1 || options.size > 100)) { errors.push('pageSize must be an integer between 1 and 100'); } 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 (errors.length > 0) { throw new errors_1.PolyVValidationError(`Chat delete options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed'); } } readFile(filePath) { const data = (0, fs_1.readFileSync)(filePath); if (typeof File !== 'undefined') { return new File([data], (0, path_1.basename)(filePath)); } return new buffer_1.Blob([data]); } } exports.ChatServiceSdk = ChatServiceSdk; //# sourceMappingURL=chat.service.sdk.js.map