云函数:屏蔽词
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {Application, RouteRecord, FrontendOrBackendSession, HandlerCallback, pinus} from "pinus";
|
||||
import { checkEvent } from '../../../services/eventSercive';
|
||||
import { refresh } from '../../../services/refreshService';
|
||||
import { getWorldChannelSid } from "../../../services/chatService";
|
||||
import { checkFilterWords, getWorldChannelSid } from "../../../services/chatService";
|
||||
import { resResult, checkWhiteListWithUid } from "../../../pubUtils/util";
|
||||
import { STATUS } from "../../../consts";
|
||||
import { UserModel } from "../../../db/User";
|
||||
@@ -30,6 +30,22 @@ Filter.prototype.before = async function (routeRecord: RouteRecord, msg: any, se
|
||||
next(new Error(), resResult(STATUS.SERVER_MAINTENANCE));
|
||||
}
|
||||
|
||||
let hasBlockWords = false;
|
||||
if(routeRecord.route == 'chat.chatHandler.send') {
|
||||
hasBlockWords = await checkFilterWords(msg.content);
|
||||
} else if(routeRecord.route == 'guild.guildHandler.sendMail') {
|
||||
hasBlockWords = await checkFilterWords(msg.info);
|
||||
} else if (routeRecord.route == 'guild.guildHandler.recruit') {
|
||||
hasBlockWords = await checkFilterWords(msg.info);
|
||||
} else if (routeRecord.route == 'role.barrageHandler.sendBarrage') {
|
||||
hasBlockWords = await checkFilterWords(msg.info);
|
||||
} else if (routeRecord.route == 'role.roleHandler.initRole') {
|
||||
hasBlockWords = await checkFilterWords(msg.roleName);
|
||||
} else if (routeRecord.route == 'role.roleHandler.rename') {
|
||||
hasBlockWords = await checkFilterWords(msg.roleName);
|
||||
}
|
||||
if(hasBlockWords) next(new Error(), resResult(STATUS.BLOCK_WORDS));
|
||||
|
||||
next(null);
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import { ChatInfoModel } from '../db/ChatInfo';
|
||||
import { channelServer } from './chatChannelService';
|
||||
import { AccuseRecModel, AccueseParam } from '../db/AccuseRec';
|
||||
import { getSimpleRoleInfo, getSimpleRoleInfos } from './roleService';
|
||||
import * as FCClient from '@alicloud/fc2';
|
||||
|
||||
export * from './chatChannelService';
|
||||
export * from './sysChatService';
|
||||
@@ -375,3 +376,25 @@ export async function createAccuseData(roleId: string, targetRoleId: string, tar
|
||||
const result = await AccuseRecModel.createRec(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
const client = new FCClient('1475752363809339', {
|
||||
accessKeyID: 'LTAI5tFTwE7vwH5HGL7eV8xr',
|
||||
accessKeySecret: 'HZznAZfOrmXttBMevhA55jQX3OGw9j',
|
||||
region: 'cn-zhangjiakou',
|
||||
});
|
||||
|
||||
export async function checkFilterWords(word: string) {
|
||||
const resp = await client.post('/proxy/bantuUtils/filterWords/check',{
|
||||
word,
|
||||
salt: "bantu1filter2word3test"
|
||||
}, {});
|
||||
let hasBlock = true;
|
||||
try {
|
||||
let data = JSON.parse(resp.data);
|
||||
hasBlock = data.status != 0;
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
return hasBlock;
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
"jenkins": "npm run build && cd dist && pinus start -D"
|
||||
},
|
||||
"dependencies": {
|
||||
"@alicloud/fc2": "^2.2.2",
|
||||
"@typegoose/typegoose": "^7.3.5",
|
||||
"@types/bluebird": "^3.5.19",
|
||||
"@types/chai": "^4.2.14",
|
||||
@@ -52,6 +53,7 @@
|
||||
"source-map-support": "^0.5.0",
|
||||
"tenpay": "^2.1.18",
|
||||
"ts-node": "^8.2.0",
|
||||
"typegoose": "^5.9.1",
|
||||
"xprofiler": "^1.2.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
Reference in New Issue
Block a user