云函数:屏蔽词
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": {
|
||||
|
||||
@@ -9,6 +9,7 @@ export const STATUS = {
|
||||
REDLOCK_ERR: { code: 6, simStr: 'redlock错误' },
|
||||
SERVER_MAINTENANCE: { code: 7, simStr: '服务器维护中' },
|
||||
VERSION_ERR: { code: 8, simStr: '版本号太低,请更新' },
|
||||
BLOCK_WORDS: { code: 9, simStr: '内容有不合法词汇' },
|
||||
GLOBAL_ERR: { code: 1003, simStr: '服务器内部错误' },
|
||||
|
||||
// 账号相关状态 10000 - 19999
|
||||
|
||||
@@ -6,6 +6,13 @@ import { genCode, aesEncryptcfb, aesDecryptcfb } from '../pubUtils/util';
|
||||
const bcrypt = require('bcrypt');
|
||||
const SALT_WORK_FACTOR = 5
|
||||
|
||||
class PlatForm {
|
||||
@prop({ required: true })
|
||||
platform: string; // 平台:ios, android, web, pc
|
||||
@prop({ required: true })
|
||||
unionId: string; // 用户标识
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户字段接口
|
||||
*/
|
||||
@@ -77,11 +84,8 @@ export default class User extends BaseModel {
|
||||
|
||||
@prop({ required: true })
|
||||
platform: string;
|
||||
@prop({ required: true, default: [] })
|
||||
platforms: [{
|
||||
platform: string; // 平台:ios, android, web, pc
|
||||
unionId: string; // 用户标识
|
||||
}];
|
||||
@prop({ required: true, default: [], type: PlatForm })
|
||||
platforms: PlatForm[];
|
||||
|
||||
@prop({ required: true, type: String, default: [], _id: false })
|
||||
device: string[];
|
||||
|
||||
2
web-server/typings/config/plugin.d.ts
vendored
2
web-server/typings/config/plugin.d.ts
vendored
@@ -16,7 +16,6 @@ import 'egg-jsonp';
|
||||
import 'egg-view';
|
||||
import 'egg-view-nunjucks';
|
||||
import 'egg-cors';
|
||||
import 'egg-alinode';
|
||||
import { EggPluginItem } from 'egg';
|
||||
declare module 'egg' {
|
||||
interface EggPlugin {
|
||||
@@ -34,7 +33,6 @@ declare module 'egg' {
|
||||
view?: EggPluginItem;
|
||||
nunjucks?: EggPluginItem;
|
||||
cors?: EggPluginItem;
|
||||
alinode?: EggPluginItem;
|
||||
xtransit?: EggPluginItem;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user