Procházet zdrojové kódy

Fixed punishment system.

KrisVos130 před 8 roky
rodič
revize
ec5078ae75

+ 6 - 5
backend/logic/actions/punishments.js

@@ -8,10 +8,11 @@ const 	hooks 	    = require('./hooks'),
 	 	db 	        = require('../db'),
 		punishments = require('../punishments');
 
-cache.sub('ip.ban', ip => {
-	utils.socketsFromIP(ip, sockets => {
+cache.sub('ip.ban', data => {
+	utils.socketsFromIP(data.ip, sockets => {
 		sockets.forEach(socket => {
-			socket.emit('keep.event:banned');
+			socket.emit('keep.event:banned', data.punishment);
+			socket.disconnect(true);
 		});
 	});
 });
@@ -100,8 +101,8 @@ module.exports = {
 				punishments.addPunishment('banUserIp', value, reason, expiresAt, userId, next)
 			},
 
-			(next) => {
-				cache.pub('ip.ban', value);
+			(punishment, next) => {
+				cache.pub('ip.ban', {ip: value, punishment});
 				next();
 			},
 		], (err) => {

+ 6 - 5
backend/logic/actions/users.js

@@ -62,10 +62,11 @@ cache.sub('user.unlinkGitHub', userId => {
 	});
 });
 
-cache.sub('user.ban', userId => {
-	utils.socketsFromUser(userId, sockets => {
+cache.sub('user.ban', data => {
+	utils.socketsFromUser(data.userId, sockets => {
 		sockets.forEach(socket => {
-			socket.emit('keep.event:banned');
+			socket.emit('keep.event:banned', data.punishment);
+			socket.disconnect(true);
 		});
 	});
 });
@@ -1087,8 +1088,8 @@ module.exports = {
 				punishments.addPunishment('banUserId', value, reason, expiresAt, userId, next)
 			},
 
-			(next) => {
-				cache.pub('user.ban', value);
+			(punishment, next) => {
+				cache.pub('user.ban', {userId: value, punishment});
 				next();
 			},
 		], (err) => {

+ 2 - 2
backend/logic/cache/schemas/punishment.js

@@ -1,5 +1,5 @@
 'use strict';
 
-module.exports = punishment => {
-	return punishment;
+module.exports = (punishment, punishmentId) => {
+	return { type: punishment.type, value: punishment.value, reason: punishment.reason, expiresAt: new Date(punishment.expiresAt).getTime(), punishmentId };
 };

+ 7 - 5
backend/logic/punishments.js

@@ -42,7 +42,7 @@ module.exports = {
 			(punishments, next) => {
 				async.each(punishments, (punishment, next) => {
 					if (punishment.active === false || punishment.expiresAt < Date.now()) return next();
-					cache.hset('punishments', punishment._id, cache.schemas.punishment(punishment), next);
+					cache.hset('punishments', punishment._id, cache.schemas.punishment(punishment, punishment._id), next);
 				}, next);
 			}
 		], (err) => {
@@ -182,15 +182,17 @@ module.exports = {
 			},
 
 			(punishment, next) => {
-				cache.hset('punishments', punishment._id, { type, value, reason, expiresAt }, next);
+				cache.hset('punishments', punishment._id, cache.schemas.punishment(punishment, punishment._id), (err) => {
+					next(err, punishment);
+				});
 			},
 
 			(punishment, next) => {
 				// DISCORD MESSAGE
-				next();
+				next(null, punishment);
 			}
-		], (err) => {
-			cb(err);
+		], (err, punishment) => {
+			cb(err, punishment);
 		});
 	},