UNPKG

qq-official-bot

Version:
92 lines (91 loc) 2.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReactionService = void 0; class ReactionService { constructor(bot) { this.bot = bot; } /** * 对频道消息进行表态 */ async addGuildMessageReaction(channelId, messageId, type, id) { try { const result = await this.bot.request.put(`/channels/${channelId}/messages/${messageId}/reactions/${type}/${id}`); return { success: true, data: result.status === 204 }; } catch (error) { return { success: false, error: { code: error.status || 500, message: error.message } }; } } /** * 删除频道消息表态 */ async deleteGuildMessageReaction(channelId, messageId, type, id) { try { const result = await this.bot.request.delete(`/channels/${channelId}/messages/${messageId}/reactions/${type}/${id}`); return { success: true, data: result.status === 204 }; } catch (error) { return { success: false, error: { code: error.status || 500, message: error.message } }; } } /** * 获取表态用户列表 */ async getGuildMessageReactionMembers(channelId, messageId, type, id) { try { const result = await this._getGuildMessageReactionMembers(channelId, messageId, type, id); return { success: true, data: result }; } catch (error) { return { success: false, error: { code: error.status || 500, message: error.message } }; } } /** * 私有方法:获取表态用户列表的实现 */ async _getGuildMessageReactionMembers(channelId, messageId, type, id, cookies) { const formatUser = (users) => { return users.map(({ id, username, avatar, bot, public_flag }) => ({ id, username, avatar, bot, public_flag })); }; const { data: { users, cookie, is_end } } = await this.bot.request.get(`/channels/${channelId}/messages/${messageId}/reactions/${type}/${id}`, { params: { cookie: cookies } }); if (is_end) return formatUser(users); return [...formatUser(users), ...await this._getGuildMessageReactionMembers(channelId, messageId, type, id, cookie)]; } } exports.ReactionService = ReactionService;