Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f83ef938ab | |||
| 0b5cc49e6e | |||
| 2dad56d17e | |||
| 5f15228e53 |
@@ -4,6 +4,12 @@ DB_HOSTNAME=database
|
||||
DB_DATABASE=chat
|
||||
DB_USERNAME=chat
|
||||
DB_PASSWORD=blastoise
|
||||
|
||||
# Select a "TZ database name" that suits your needs: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
||||
DB_TIMEZONE=Australia/Sydney
|
||||
|
||||
SECRET_ACCESS=access
|
||||
# Give this any value to enable database logging (such as "true")
|
||||
DB_LOGGING=
|
||||
|
||||
# Make sure this value matches the system that you connect to
|
||||
SECRET_ACCESS=access
|
||||
|
||||
@@ -19,6 +19,7 @@ on 'error' -> Server emits and logs an error
|
||||
on 'open chat' -> Preps the server for your messages, places you in the room 'general'
|
||||
on 'message' -> Server broadcasts to all other users in your room
|
||||
on 'disconnect' -> Server will no longer accept your messages
|
||||
on 'report' -> Report the chatlog with the index 'id'
|
||||
|
||||
|
||||
Chat Commands:
|
||||
|
||||
Generated
+12
-14
@@ -604,7 +604,6 @@
|
||||
"version": "8.2.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz",
|
||||
"integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==",
|
||||
"license": "BSD-2-Clause",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
@@ -1807,10 +1806,9 @@
|
||||
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
|
||||
},
|
||||
"node_modules/sequelize": {
|
||||
"version": "6.5.1",
|
||||
"resolved": "https://registry.npmjs.org/sequelize/-/sequelize-6.5.1.tgz",
|
||||
"integrity": "sha512-DWgaF+Vw+gWpxomyyYppUOCWzP0ReoMol8EEaDMA+cbSUevyMb74BEwSAd0c8GKgDYiOjpq4DmKBQLHtLAgS1g==",
|
||||
"license": "MIT",
|
||||
"version": "6.6.2",
|
||||
"resolved": "https://registry.npmjs.org/sequelize/-/sequelize-6.6.2.tgz",
|
||||
"integrity": "sha512-H/zrzmTK+tis9PJaSigkuXI57nKBvNCtPQol0yxCvau1iWLzSOuq8t3tMOVeQ+Ep8QH2HoD9/+FCCIAqzUr/BQ==",
|
||||
"dependencies": {
|
||||
"debug": "^4.1.1",
|
||||
"dottie": "^2.0.0",
|
||||
@@ -1880,9 +1878,9 @@
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
},
|
||||
"node_modules/sequelize/node_modules/semver": {
|
||||
"version": "7.3.4",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.4.tgz",
|
||||
"integrity": "sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==",
|
||||
"version": "7.3.5",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz",
|
||||
"integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==",
|
||||
"dependencies": {
|
||||
"lru-cache": "^6.0.0"
|
||||
},
|
||||
@@ -3722,9 +3720,9 @@
|
||||
}
|
||||
},
|
||||
"sequelize": {
|
||||
"version": "6.5.1",
|
||||
"resolved": "https://registry.npmjs.org/sequelize/-/sequelize-6.5.1.tgz",
|
||||
"integrity": "sha512-DWgaF+Vw+gWpxomyyYppUOCWzP0ReoMol8EEaDMA+cbSUevyMb74BEwSAd0c8GKgDYiOjpq4DmKBQLHtLAgS1g==",
|
||||
"version": "6.6.2",
|
||||
"resolved": "https://registry.npmjs.org/sequelize/-/sequelize-6.6.2.tgz",
|
||||
"integrity": "sha512-H/zrzmTK+tis9PJaSigkuXI57nKBvNCtPQol0yxCvau1iWLzSOuq8t3tMOVeQ+Ep8QH2HoD9/+FCCIAqzUr/BQ==",
|
||||
"requires": {
|
||||
"debug": "^4.1.1",
|
||||
"dottie": "^2.0.0",
|
||||
@@ -3755,9 +3753,9 @@
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
},
|
||||
"semver": {
|
||||
"version": "7.3.4",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.4.tgz",
|
||||
"integrity": "sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==",
|
||||
"version": "7.3.5",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz",
|
||||
"integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==",
|
||||
"requires": {
|
||||
"lru-cache": "^6.0.0"
|
||||
}
|
||||
|
||||
+21
-8
@@ -1,13 +1,13 @@
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { Op } = require('sequelize');
|
||||
const { chatlog, mute } = require('../database/models');
|
||||
const { chatlog, mute, reports } = require('../database/models');
|
||||
|
||||
const chat = io => {
|
||||
io.on('connection', socket => {
|
||||
//middleware
|
||||
socket.use((request, next) => {
|
||||
//verify request format
|
||||
if (!['open chat', 'message'].includes(request[0])) {
|
||||
if (!['open chat', 'message', 'report'].includes(request[0])) {
|
||||
return next(`Invalid request to the chat server ${request[0]}`);
|
||||
}
|
||||
return next();
|
||||
@@ -109,15 +109,15 @@ const chat = io => {
|
||||
return;
|
||||
}
|
||||
|
||||
//broadcast to this room
|
||||
socket.broadcast.to(socket.user.room).emit('message', { username: socket.user.username, text: message.text });
|
||||
|
||||
//log
|
||||
chatlog.create({
|
||||
const log = await chatlog.create({
|
||||
username: socket.user.username,
|
||||
text: message.text,
|
||||
room: socket.user.room
|
||||
});
|
||||
|
||||
//broadcast to this room (with the id)
|
||||
socket.broadcast.to(socket.user.room).emit('message', log);
|
||||
});
|
||||
|
||||
socket.on('disconnect', reason => {
|
||||
@@ -137,6 +137,19 @@ const chat = io => {
|
||||
emphasis: true
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('report', info => {
|
||||
//handle reports of malicious content
|
||||
if (!info.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
//report
|
||||
reports.create({
|
||||
reporter: socket.user.username,
|
||||
chatlogId: info.id
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -186,7 +199,7 @@ const executeCommand = (io, socket, command) => {
|
||||
}
|
||||
|
||||
case '/mute': {//NOTE: mutes globally, broadcasts only to admin's room
|
||||
if (socket.user.privilege != 'administrator' && socket.user.privilege != 'moderator') {
|
||||
if (!socket.user.admin && !socket.user.mod) {
|
||||
socket.emit('message', { emphasis: true, text: '/mute is only available to admins and mods' });
|
||||
break;
|
||||
}
|
||||
@@ -229,7 +242,7 @@ const executeCommand = (io, socket, command) => {
|
||||
}
|
||||
|
||||
case '/unmute': {
|
||||
if (socket.user.privilege != 'administrator' && socket.user.privilege != 'moderator') {
|
||||
if (!socket.user.admin && !socket.user.mod) {
|
||||
socket.emit('message', { emphasis: true, text: '/unmute is only available to admins and mods' });
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
module.exports = {
|
||||
chatlog: require('./chatlog'),
|
||||
mute: require('./mute')
|
||||
mute: require('./mute'),
|
||||
reports: require('./reports')
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
const Sequelize = require('sequelize');
|
||||
const sequelize = require('..');
|
||||
|
||||
const chatlog = require('./chatlog');
|
||||
|
||||
const reports = sequelize.define('reports', {
|
||||
id: {
|
||||
type: Sequelize.INTEGER(11),
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
unique: true
|
||||
},
|
||||
|
||||
reporter: {
|
||||
type: 'varchar(320)',
|
||||
allowNull: false
|
||||
},
|
||||
});
|
||||
|
||||
chatlog.hasMany(reports, { foreignKey: 'chatlogId', foreignKeyConstraint: true });
|
||||
|
||||
module.exports = reports;
|
||||
Reference in New Issue
Block a user