From 5f6c61649f727718b948b50948fc24bd2c4516f8 Mon Sep 17 00:00:00 2001 From: Jerry Date: Tue, 6 May 2025 13:55:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96=E7=BE=A4?= =?UTF-8?q?=E8=81=8A=E6=B6=88=E6=81=AF=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/bot/bot.controller.ts | 34 +++++++++++++++++++++++++++++++ src/modules/bot/bot.service.ts | 17 ++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/modules/bot/bot.controller.ts b/src/modules/bot/bot.controller.ts index 9fb56f8..2646b40 100644 --- a/src/modules/bot/bot.controller.ts +++ b/src/modules/bot/bot.controller.ts @@ -2,6 +2,7 @@ import express from 'express'; import response from '../../utils/core/response'; import BotService from './bot.service'; import tools from '../../utils/modules/tools'; +import logger from '../../utils/core/logger'; class BotController { private readonly router: express.Router; @@ -17,6 +18,7 @@ class BotController { private init(): void { this.router.post(`/getBotId`, this.postBotsId); + this.router.post('/getBotInfo', this.postGroupInfo); } /** @@ -37,6 +39,38 @@ class BotController { await response.error(res, `请求失败..`, 500, err); } }; + + /** + * 获取群聊信息 + * @example req示例 + * ```json + * { + * token: "114514", + * botId: "114514", + * groupId: "114514" + * } + * ``` + * @param req + * @param res + */ + private postGroupInfo = async (req: express.Request, res: express.Response): Promise => { + try { + const token = req.body.token; + if (tools.checkToken(token.toString())) { + const botId = req.body.botId; + const groupId = req.body.groupId; + let returnData = await BotService.getGroupInfo({ botId: botId, groupId: groupId }); + if (returnData) { + await response.success(res, returnData); + logger.debug(returnData); + } + } else { + await tools.tokenCheckFailed(res, token); + } + } catch (e) { + await response.error(res); + } + }; } export default new BotController(); diff --git a/src/modules/bot/bot.service.ts b/src/modules/bot/bot.service.ts index 5c3db77..27ed9e2 100644 --- a/src/modules/bot/bot.service.ts +++ b/src/modules/bot/bot.service.ts @@ -3,6 +3,7 @@ import paths from '../../utils/core/path'; import fs from 'fs/promises'; import path from 'path'; import redisService from '../../services/redis/redis'; +import wsClientManager from '../../services/ws/wsClientManager'; class BotService { /** @@ -45,6 +46,22 @@ class BotService { logger.debug(uins); return uins; } + + public async getGroupInfo(data: { botId: string; groupId: string }) { + logger.debug('GetGroupInfo..'); + let sendData = { + type: 'getGroupInfo', + data: data, + }; + // TO DO 自动寻找botId对应的Client + const returnData = await wsClientManager.sendAndWait('test', sendData); + if (returnData) { + return returnData; + } else { + logger.warn(`未查询到${data.groupId}的信息..`); + return undefined; + } + } } export default new BotService();