聊天:添加屏蔽
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { CHANNEL_PREFIX, MSG_SOURCE, CHANNEL_TYPE } from './../../../consts/constModules/chatConst';
|
||||
import { CHANNEL_PREFIX, MSG_SOURCE, getChannelType } from './../../../consts/constModules/chatConst';
|
||||
import { Application, BackendSession, HandlerService, } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { DEFAULT_MSG_PER_PAGE, STATUS, TASK_TYPE } from '../../../consts';
|
||||
@@ -99,10 +99,10 @@ export class ChatHandler {
|
||||
await pushGroupMsgToRoom(msgData);
|
||||
|
||||
// 任务
|
||||
await checkTaskWithArgs(roleId, sid, TASK_TYPE.CHAT, [CHANNEL_TYPE.get(channel)]);
|
||||
await checkTaskWithArgs(roleId, sid, TASK_TYPE.CHAT, [getChannelType(channel)]);
|
||||
|
||||
//活动任务
|
||||
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.CHAT, 1, { chatType: CHANNEL_TYPE.get(channel) })
|
||||
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.CHAT, 1, { chatType: getChannelType(channel) })
|
||||
|
||||
return resResult(STATUS.SUCCESS, msgData);
|
||||
}
|
||||
@@ -125,9 +125,9 @@ export class ChatHandler {
|
||||
if (!msgData) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
// 任务
|
||||
await checkTaskWithArgs(roleId, sid, TASK_TYPE.CHAT, [CHANNEL_TYPE.get('private')]);
|
||||
await checkTaskWithArgs(roleId, sid, TASK_TYPE.CHAT, [getChannelType('private')]);
|
||||
//活动任务
|
||||
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.CHAT, 1, { chatType: CHANNEL_TYPE.get('private') })
|
||||
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.CHAT, 1, { chatType: getChannelType('private') })
|
||||
|
||||
return resResult(STATUS.SUCCESS, msgData);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import {Application, RouteRecord, FrontendOrBackendSession, HandlerCallback, pinus} from "pinus";
|
||||
// import { checkEvent } from '../../../services/eventSercive';
|
||||
import { refresh } from '../../../services/refreshService';
|
||||
import { checkFilterWords, getWorldChannelSid } from "../../../services/chatService";
|
||||
import { checkPrivateChat, checkGuildChat, checkOtherChat, getWorldChannelSid } from "../../../services/chatService";
|
||||
import { resResult, checkWhiteListWithUid } from "../../../pubUtils/util";
|
||||
import { STATUS } from "../../../consts";
|
||||
import { CHANNEL_PREFIX, STATUS } from "../../../consts";
|
||||
import { UserModel } from "../../../db/User";
|
||||
import { SERVER_DEBUG_MODE } from "../../../pubUtils/dicParam";
|
||||
export function globalFilter(app: Application) {
|
||||
return new Filter(app);
|
||||
}
|
||||
@@ -31,15 +32,39 @@ Filter.prototype.before = async function (routeRecord: RouteRecord, msg: any, se
|
||||
}
|
||||
|
||||
let hasBlockWords = false;
|
||||
if(pinus.app.get('env') == 'production') {
|
||||
if(routeRecord.route == 'guild.guildHandler.createGuild') {
|
||||
hasBlockWords = await checkFilterWords(msg.name);
|
||||
} 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(pinus.app.get('env') == 'production') {
|
||||
// if(routeRecord.route == 'guild.guildHandler.createGuild') {
|
||||
// hasBlockWords = await checkFilterWords(msg.name);
|
||||
// } 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(SERVER_DEBUG_MODE.CHECK_WORD == 1) {
|
||||
switch(routeRecord.route) {
|
||||
case 'chat.chatHandler.sendPrivateMessage':
|
||||
{
|
||||
let result = await checkPrivateChat(roleId, msg.targetRoleId, msg.content);
|
||||
if(!result) hasBlockWords = true;
|
||||
break;
|
||||
}
|
||||
case 'chat.chatHandler.sendGroupMessage':
|
||||
{
|
||||
if(msg.channel == CHANNEL_PREFIX.GUILD) {
|
||||
const guildCode = session.get('guildCode');
|
||||
let result = await checkGuildChat(roleId, guildCode, msg.content);
|
||||
if(!result) hasBlockWords = true;
|
||||
break;
|
||||
} else {
|
||||
let result = await checkOtherChat(roleId, msg.channel, msg.content);
|
||||
if(!result) hasBlockWords = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(hasBlockWords) return next(new Error(), resResult(STATUS.BLOCK_WORDS));
|
||||
|
||||
next(null);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { CHAT_SYSTEM } from './../pubUtils/dicParam';
|
||||
import { PrivateChatRec } from './../db/ChatInfo';
|
||||
import { RoleModel } from './../db/Role';
|
||||
import { RoleModel, RoleType } from './../db/Role';
|
||||
import { GroupMessageModel } from './../db/GroupMessage';
|
||||
import { CounterModel } from './../db/Counter';
|
||||
import { STATUS } from './../consts/statusCode';
|
||||
@@ -8,13 +8,16 @@ import { PrivateMessageModel, PrivateMessageParam, PrivateMessageType } from './
|
||||
import { GroupMessageParam, GroupMessageType } from '../db/GroupMessage';
|
||||
import { genCode, resResult } from '../pubUtils/util';
|
||||
import { pinus } from 'pinus';
|
||||
import { CHANNEL_PREFIX, MSG_CODE_LEN, MSG_STATUS, ON_PRIVATE_MSG_ROUTE, MSG_TYPE, MSG_SOURCE } from '../consts';
|
||||
import { CHANNEL_PREFIX, MSG_CODE_LEN, MSG_STATUS, ON_PRIVATE_MSG_ROUTE, MSG_TYPE, MSG_SOURCE, getSdkChannelId, SDK_37_CONST, SDK_37_ADDR } from '../consts';
|
||||
import { getAllServers, getRoleOnlineInfo } from './redisService';
|
||||
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';
|
||||
import { Chat37Params } from '../domain/sdk';
|
||||
import { UserModel } from '../db/User';
|
||||
import { request37CheckChat } from '../pubUtils/httpUtil';
|
||||
|
||||
export * from './chatChannelService';
|
||||
export * from './sysChatService';
|
||||
@@ -378,6 +381,7 @@ export async function createAccuseData(roleId: string, roleName: string, targetR
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
const client = new FCClient('1475752363809339', {
|
||||
accessKeyID: 'LTAI5tFTwE7vwH5HGL7eV8xr',
|
||||
accessKeySecret: 'HZznAZfOrmXttBMevhA55jQX3OGw9j',
|
||||
@@ -399,6 +403,44 @@ export async function checkFilterWords(word: string) {
|
||||
|
||||
return hasBlock;
|
||||
}
|
||||
*/
|
||||
|
||||
export async function checkPrivateChat(roleId: string, targetRoleId: string, message: string) {
|
||||
let body = new Chat37Params(message, getSdkChannelId('private'));
|
||||
let myRole = await RoleModel.findByRoleId(roleId);
|
||||
let myUser = await UserModel.findUserByUid(myRole.userInfo.uid);
|
||||
if(myUser.channelType == '37') {
|
||||
body.setByMyRole(myRole, myUser);
|
||||
let targetRole = await RoleModel.findByRoleId(targetRoleId);
|
||||
let targetUser = await UserModel.findUserByUid(targetRole.userInfo.uid);
|
||||
body.setByTargetRole(targetRole, targetUser);
|
||||
return await request37CheckChat(SDK_37_ADDR.CHECK_CHAT, body, SDK_37_CONST.CHAT_KEY);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function checkGuildChat(roleId: string, guildCode: string, message: string) {
|
||||
let body = new Chat37Params(message, getSdkChannelId(CHANNEL_PREFIX.GUILD));
|
||||
let myRole = await RoleModel.findByRoleId(roleId);
|
||||
let myUser = await UserModel.findUserByUid(myRole.userInfo.uid);
|
||||
if(myUser.channelType == '37') {
|
||||
body.setByMyRole(myRole, myUser);
|
||||
body.setByGuild(guildCode);
|
||||
return await request37CheckChat(SDK_37_ADDR.CHECK_CHAT, body, SDK_37_CONST.CHAT_KEY);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function checkOtherChat(roleId: string, channelPrefix: string, message: string) {
|
||||
let body = new Chat37Params(message, getSdkChannelId(channelPrefix));
|
||||
let myRole = await RoleModel.findByRoleId(roleId);
|
||||
let myUser = await UserModel.findUserByUid(myRole.userInfo.uid);
|
||||
if(myUser.channelType == '37') {
|
||||
body.setByMyRole(myRole, myUser);
|
||||
return await request37CheckChat(SDK_37_ADDR.CHECK_CHAT, body, SDK_37_CONST.CHAT_KEY);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function pushCurrentTime(time: number) {
|
||||
let serverlists = await getAllServers()
|
||||
|
||||
@@ -28,7 +28,7 @@ export async function GTAuth() {
|
||||
timestamp,
|
||||
appkey: APP_KEY,
|
||||
};
|
||||
let result = await httpRequest(url, HTTP_METHOD.POST, headers, body)
|
||||
let result = await httpRequest(url, HTTP_METHOD.POST, body, headers)
|
||||
if (result.code == 0) {
|
||||
console.log('GETUI_TOKEN', result.data.token)
|
||||
return await ServerTempModel.updateGetuiData(result.data.token, result.data.expire_time);
|
||||
@@ -151,7 +151,7 @@ export async function request(url: string, method: string, headers: any, body: a
|
||||
}
|
||||
|
||||
headers = { ...headers, 'content-type': 'application/json;charset=utf-8', 'token': tokenData.getuiToken };
|
||||
let result = await httpRequest(url, method, headers, body)
|
||||
let result = await httpRequest(url, method, body, headers)
|
||||
if (result.code == 10001) {
|
||||
if (await GTAuth()) {
|
||||
console.log('token success11')
|
||||
|
||||
Reference in New Issue
Block a user