fix static methodes of ChatProvider

This commit is contained in:
HF 2020-11-06 21:10:19 +01:00
parent 9f0a78f1ea
commit a54c1b198e
2 changed files with 19 additions and 26 deletions

View File

@ -94,7 +94,7 @@ export class ChatProvider {
}, },
raw: true, raw: true,
}); });
[this.infoUserId] = infoUser; this.infoUserId = infoUser[0].id;
name = EVENT_USER_NAME; name = EVENT_USER_NAME;
const eventUser = await RegUser.findOrCreate({ const eventUser = await RegUser.findOrCreate({
attributes: [ attributes: [
@ -108,7 +108,7 @@ export class ChatProvider {
}, },
raw: true, raw: true,
}); });
[this.eventUserId] = eventUser; this.eventUserId = eventUser[0].id;
} }
userHasChannelAccess(user, cid, write = false) { userHasChannelAccess(user, cid, write = false) {
@ -173,7 +173,7 @@ export class ChatProvider {
const filter = this.filters[i]; const filter = this.filters[i];
const count = (message.match(filter.regexp) || []).length; const count = (message.match(filter.regexp) || []).length;
if (count >= filter.matches) { if (count >= filter.matches) {
ChatProvider.mute(name, channelId, 30); this.mute(name, channelId, 30);
return 'Ow no! Spam protection decided to mute you'; return 'Ow no! Spam protection decided to mute you';
} }
} }
@ -200,19 +200,19 @@ export class ChatProvider {
if (cmd === 'mute') { if (cmd === 'mute') {
const timeMin = Number(args.slice(-1)); const timeMin = Number(args.slice(-1));
if (Number.isNaN(timeMin)) { if (Number.isNaN(timeMin)) {
return ChatProvider.mute(args.join(' '), channelId); return this.mute(args.join(' '), channelId);
} }
return ChatProvider.mute( return this.mute(
args.slice(0, -1).join(' '), args.slice(0, -1).join(' '),
channelId, channelId,
timeMin, timeMin,
); );
} if (cmd === 'unmute') { } if (cmd === 'unmute') {
return ChatProvider.unmute(args.join(' '), channelId); return this.unmute(args.join(' '), channelId);
} if (cmd === 'mutec' && args[0]) { } if (cmd === 'mutec' && args[0]) {
const cc = args[0].toLowerCase(); const cc = args[0].toLowerCase();
this.mutedCountries.push(cc); this.mutedCountries.push(cc);
webSockets.broadcastChatMessage( this.broadcastChatMessage(
'info', 'info',
`Country ${cc} has been muted`, `Country ${cc} has been muted`,
channelId, channelId,
@ -225,7 +225,7 @@ export class ChatProvider {
return `Country ${cc} is not muted`; return `Country ${cc} is not muted`;
} }
this.mutedCountries = this.mutedCountries.filter((c) => c !== cc); this.mutedCountries = this.mutedCountries.filter((c) => c !== cc);
webSockets.broadcastChatMessage( this.broadcastChatMessage(
'info', 'info',
`Country ${cc} has been unmuted`, `Country ${cc} has been unmuted`,
channelId, channelId,
@ -243,14 +243,7 @@ export class ChatProvider {
return 'Your country is temporary muted from chat'; return 'Your country is temporary muted from chat';
} }
this.chatMessageBuffer.addMessage( this.broadcastChatMessage(
name,
message,
channelId,
id,
displayCountry,
);
webSockets.broadcastChatMessage(
name, name,
message, message,
channelId, channelId,
@ -288,9 +281,9 @@ export class ChatProvider {
); );
} }
static automute(name, channelId) { automute(name, channelId) {
ChatProvider.mute(name, channelId, 60); this.mute(name, channelId, 60);
webSockets.broadcastChatMessage( this.broadcastChatMessage(
'info', 'info',
`${name} has been muted for spam for 60min`, `${name} has been muted for spam for 60min`,
channelId, channelId,
@ -304,7 +297,7 @@ export class ChatProvider {
return ttl; return ttl;
} }
static async mute(plainName, channelId, timeMin = null) { async mute(plainName, channelId, timeMin = null) {
const name = (plainName.startsWith('@')) ? plainName.substr(1) : plainName; const name = (plainName.startsWith('@')) ? plainName.substr(1) : plainName;
const id = await User.name2Id(name); const id = await User.name2Id(name);
if (!id) { if (!id) {
@ -315,7 +308,7 @@ export class ChatProvider {
const ttl = timeMin * 60; const ttl = timeMin * 60;
await redis.setAsync(key, '', 'EX', ttl); await redis.setAsync(key, '', 'EX', ttl);
if (timeMin !== 600 && timeMin !== 60) { if (timeMin !== 600 && timeMin !== 60) {
webSockets.broadcastChatMessage( this.broadcastChatMessage(
'info', 'info',
`${name} has been muted for ${timeMin}min`, `${name} has been muted for ${timeMin}min`,
channelId, channelId,
@ -324,7 +317,7 @@ export class ChatProvider {
} }
} else { } else {
await redis.setAsync(key, ''); await redis.setAsync(key, '');
webSockets.broadcastChatMessage( this.broadcastChatMessage(
'info', 'info',
`${name} has been muted forever`, `${name} has been muted forever`,
channelId, channelId,
@ -335,7 +328,7 @@ export class ChatProvider {
return null; return null;
} }
static async unmute(plainName, channelId) { async unmute(plainName, channelId) {
const name = (plainName.startsWith('@')) ? plainName.substr(1) : plainName; const name = (plainName.startsWith('@')) ? plainName.substr(1) : plainName;
const id = await User.name2Id(name); const id = await User.name2Id(name);
if (!id) { if (!id) {
@ -346,7 +339,7 @@ export class ChatProvider {
if (delKeys !== 1) { if (delKeys !== 1) {
return `User ${name} is not muted`; return `User ${name} is not muted`;
} }
webSockets.broadcastChatMessage( this.broadcastChatMessage(
'info', 'info',
`${name} has been unmuted`, `${name} has been unmuted`,
channelId, channelId,

View File

@ -19,7 +19,7 @@ import DeRegisterMultipleChunks from './packets/DeRegisterMultipleChunks';
import ChangedMe from './packets/ChangedMe'; import ChangedMe from './packets/ChangedMe';
import OnlineCounter from './packets/OnlineCounter'; import OnlineCounter from './packets/OnlineCounter';
import chatProvider, { ChatProvider } from '../core/ChatProvider'; import chatProvider from '../core/ChatProvider';
import authenticateClient from './verifyClient'; import authenticateClient from './verifyClient';
import WebSocketEvents from './WebSocketEvents'; import WebSocketEvents from './WebSocketEvents';
import webSockets from './websockets'; import webSockets from './websockets';
@ -301,7 +301,7 @@ class SocketServer extends WebSocketEvents {
ws.message_repeat += 1; ws.message_repeat += 1;
if (ws.message_repeat >= 4) { if (ws.message_repeat >= 4) {
logger.info(`User ${ws.name} got automuted`); logger.info(`User ${ws.name} got automuted`);
ChatProvider.automute(ws.name, channelId); chatProvider.automute(ws.name, channelId);
ws.message_repeat = 0; ws.message_repeat = 0;
} }
} else { } else {