diff --git a/src/modules/bot/bot.controller.ts b/src/modules/bot/bot.controller.ts index 9fb56f8..40314f1 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();