mirror of
https://github.com/crystelf/crystelf-core.git
synced 2025-07-04 06:39:18 +00:00
新增获取群聊消息路由
This commit is contained in:
parent
952f9711eb
commit
5f6c61649f
@ -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<void> => {
|
||||
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();
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user