云函数:屏蔽词
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import {Application, RouteRecord, FrontendOrBackendSession, HandlerCallback, pinus} from "pinus";
|
import {Application, RouteRecord, FrontendOrBackendSession, HandlerCallback, pinus} from "pinus";
|
||||||
import { checkEvent } from '../../../services/eventSercive';
|
import { checkEvent } from '../../../services/eventSercive';
|
||||||
import { refresh } from '../../../services/refreshService';
|
import { refresh } from '../../../services/refreshService';
|
||||||
import { getWorldChannelSid } from "../../../services/chatService";
|
import { checkFilterWords, getWorldChannelSid } from "../../../services/chatService";
|
||||||
import { resResult, checkWhiteListWithUid } from "../../../pubUtils/util";
|
import { resResult, checkWhiteListWithUid } from "../../../pubUtils/util";
|
||||||
import { STATUS } from "../../../consts";
|
import { STATUS } from "../../../consts";
|
||||||
import { UserModel } from "../../../db/User";
|
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));
|
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);
|
next(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { ChatInfoModel } from '../db/ChatInfo';
|
|||||||
import { channelServer } from './chatChannelService';
|
import { channelServer } from './chatChannelService';
|
||||||
import { AccuseRecModel, AccueseParam } from '../db/AccuseRec';
|
import { AccuseRecModel, AccueseParam } from '../db/AccuseRec';
|
||||||
import { getSimpleRoleInfo, getSimpleRoleInfos } from './roleService';
|
import { getSimpleRoleInfo, getSimpleRoleInfos } from './roleService';
|
||||||
|
import * as FCClient from '@alicloud/fc2';
|
||||||
|
|
||||||
export * from './chatChannelService';
|
export * from './chatChannelService';
|
||||||
export * from './sysChatService';
|
export * from './sysChatService';
|
||||||
@@ -375,3 +376,25 @@ export async function createAccuseData(roleId: string, targetRoleId: string, tar
|
|||||||
const result = await AccuseRecModel.createRec(data);
|
const result = await AccuseRecModel.createRec(data);
|
||||||
return result;
|
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"
|
"jenkins": "npm run build && cd dist && pinus start -D"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@alicloud/fc2": "^2.2.2",
|
||||||
"@typegoose/typegoose": "^7.3.5",
|
"@typegoose/typegoose": "^7.3.5",
|
||||||
"@types/bluebird": "^3.5.19",
|
"@types/bluebird": "^3.5.19",
|
||||||
"@types/chai": "^4.2.14",
|
"@types/chai": "^4.2.14",
|
||||||
@@ -52,6 +53,7 @@
|
|||||||
"source-map-support": "^0.5.0",
|
"source-map-support": "^0.5.0",
|
||||||
"tenpay": "^2.1.18",
|
"tenpay": "^2.1.18",
|
||||||
"ts-node": "^8.2.0",
|
"ts-node": "^8.2.0",
|
||||||
|
"typegoose": "^5.9.1",
|
||||||
"xprofiler": "^1.2.5"
|
"xprofiler": "^1.2.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export const STATUS = {
|
|||||||
REDLOCK_ERR: { code: 6, simStr: 'redlock错误' },
|
REDLOCK_ERR: { code: 6, simStr: 'redlock错误' },
|
||||||
SERVER_MAINTENANCE: { code: 7, simStr: '服务器维护中' },
|
SERVER_MAINTENANCE: { code: 7, simStr: '服务器维护中' },
|
||||||
VERSION_ERR: { code: 8, simStr: '版本号太低,请更新' },
|
VERSION_ERR: { code: 8, simStr: '版本号太低,请更新' },
|
||||||
|
BLOCK_WORDS: { code: 9, simStr: '内容有不合法词汇' },
|
||||||
GLOBAL_ERR: { code: 1003, simStr: '服务器内部错误' },
|
GLOBAL_ERR: { code: 1003, simStr: '服务器内部错误' },
|
||||||
|
|
||||||
// 账号相关状态 10000 - 19999
|
// 账号相关状态 10000 - 19999
|
||||||
|
|||||||
+9
-5
@@ -6,6 +6,13 @@ import { genCode, aesEncryptcfb, aesDecryptcfb } from '../pubUtils/util';
|
|||||||
const bcrypt = require('bcrypt');
|
const bcrypt = require('bcrypt');
|
||||||
const SALT_WORK_FACTOR = 5
|
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 })
|
@prop({ required: true })
|
||||||
platform: string;
|
platform: string;
|
||||||
@prop({ required: true, default: [] })
|
@prop({ required: true, default: [], type: PlatForm })
|
||||||
platforms: [{
|
platforms: PlatForm[];
|
||||||
platform: string; // 平台:ios, android, web, pc
|
|
||||||
unionId: string; // 用户标识
|
|
||||||
}];
|
|
||||||
|
|
||||||
@prop({ required: true, type: String, default: [], _id: false })
|
@prop({ required: true, type: String, default: [], _id: false })
|
||||||
device: string[];
|
device: string[];
|
||||||
|
|||||||
-2
@@ -16,7 +16,6 @@ import 'egg-jsonp';
|
|||||||
import 'egg-view';
|
import 'egg-view';
|
||||||
import 'egg-view-nunjucks';
|
import 'egg-view-nunjucks';
|
||||||
import 'egg-cors';
|
import 'egg-cors';
|
||||||
import 'egg-alinode';
|
|
||||||
import { EggPluginItem } from 'egg';
|
import { EggPluginItem } from 'egg';
|
||||||
declare module 'egg' {
|
declare module 'egg' {
|
||||||
interface EggPlugin {
|
interface EggPlugin {
|
||||||
@@ -34,7 +33,6 @@ declare module 'egg' {
|
|||||||
view?: EggPluginItem;
|
view?: EggPluginItem;
|
||||||
nunjucks?: EggPluginItem;
|
nunjucks?: EggPluginItem;
|
||||||
cors?: EggPluginItem;
|
cors?: EggPluginItem;
|
||||||
alinode?: EggPluginItem;
|
|
||||||
xtransit?: EggPluginItem;
|
xtransit?: EggPluginItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user