Added !serverannounce command.

This commit is contained in:
rainbow napkin 2024-12-08 15:09:25 -05:00
parent 375cdfb3d8
commit df18b4d783
4 changed files with 35 additions and 0 deletions

View file

@ -84,6 +84,11 @@ module.exports = class{
this.server.io.in(socket.chan).emit("chatMessage", {user: user.user, flair: user.flair, highLevel: user.highLevel, msg, type});
}
relayServerAnnouncement(msg){
//This codebase is always at a 10
this.server.io.emit("chatMessage", {user: "Server", flair: "", highLevel: 10, msg, type: "announcement"});
}
relayChannelAnnouncement(socket, msg){
//This codebase is always at a 10
this.server.io.in(socket.chan).emit("chatMessage", {user: "Channel", flair: "", highLevel: 10, msg, type: "announcement"});

View file

@ -18,6 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
const validator = require('validator');//No express here, so regular validator it is!
//Local Imports
const permissionModel = require('../../schemas/permissionSchema');
const channelModel = require('../../schemas/channel/channelSchema');
module.exports = class commandPreprocessor{
@ -112,4 +113,14 @@ class commandProcessor{
this.server.chatHandler.relayChannelAnnouncement(this.preprocessor.socket, this.preprocessor.commandArray.join(''));
}
}
async serverannounce(){
//Check if the user has permission, and publicly shame them if they don't (lmao)
if(!(this.preprocessor.sendFlag = !(await permissionModel.permCheck(this.preprocessor.socket.user, 'announce')))){
//splice out our whisper
this.preprocessor.commandArray.splice(0,2);
//send it
this.server.chatHandler.relayServerAnnouncement(this.preprocessor.commandArray.join(''));
}
}
}

View file

@ -18,6 +18,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
const {mongoose} = require('mongoose');
//Local Imports
//const {userModel} = require('./userSchema');
const userSchema = require('./userSchema');
const channelPermissionSchema = require('./channel/channelPermissionSchema');
//This originally belonged to the permissionSchema, but this avoids circular dependencies.
@ -43,6 +45,12 @@ const permissionSchema = new mongoose.Schema({
default: "admin",
required: true
},
announce: {
type: mongoose.SchemaTypes.String,
enum: rankEnum,
default: "admin",
required: true
},
banUser: {
type: mongoose.SchemaTypes.String,
enum: rankEnum,
@ -105,6 +113,11 @@ permissionSchema.statics.rankToNum = function(rank){
}
permissionSchema.statics.permCheck = async function(user, perm){
const userDB = await userSchema.userModel.findOne({user: user.user});
return await this.permCheckByUserDoc(userDB, perm);
}
permissionSchema.statics.permCheckByUserDoc = async function(user, perm){
//Get permission list
const perms = await this.getPerms();

View file

@ -46,6 +46,12 @@ module.exports.permissionsValidator = {
options: module.exports.isRank
},
},
'permissionsMap.announce': {
optional: true,
custom: {
options: module.exports.isRank
},
},
'permissionsMap.banUser': {
optional: true,
custom: {