Added channel-wide !announce command

This commit is contained in:
rainbow napkin 2024-12-08 14:38:56 -05:00
parent 0182c6927e
commit 375cdfb3d8
10 changed files with 78 additions and 17 deletions

View file

@ -83,4 +83,9 @@ module.exports = class{
const user = this.server.getSocketInfo(socket);
this.server.io.in(socket.chan).emit("chatMessage", {user: user.user, flair: user.flair, highLevel: user.highLevel, msg, type});
}
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

@ -16,13 +16,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
//NPM Imports
const validator = require('validator');//No express here, so regular validator it is!
//Local Imports
const channelModel = require('../../schemas/channel/channelSchema');
module.exports = class commandPreprocessor{
constructor(server){
this.server = server;
this.commandProcessor = new commandProcessor(server, this);
}
preprocess(socket, data){
async preprocess(socket, data){
//Set socket, data, and sendFlag
this.socket = socket;
this.sendFlag = true;
@ -36,7 +40,7 @@ module.exports = class commandPreprocessor{
//split the command
this.splitCommand();
//Process the command
this.processServerCommand();
await this.processServerCommand();
//Send it as chat (assuming the flag isn't false)
this.sendChat();
}
@ -60,15 +64,15 @@ module.exports = class commandPreprocessor{
this.argumentArray = this.command.match(/\b\w+\b/g);//Match by words surrounded by borders
}
processServerCommand(){
//If the first word is '!'
if(this.commandArray[0] == '!'){
async processServerCommand(){
//If the raw message starts with '!' (skip commands that start with whitespace so people can send example commands in chat)
if(this.rawData.msg[0] == '!'){
//if it isn't just an exclimation point, and we have a real command
if(this.argumentArray != null && this.commandProcessor[this.argumentArray[0]] != null){
if(this.argumentArray != null && this.commandProcessor[this.argumentArray[0].toLowerCase()] != null){
//disable chat
this.sendFlag = false;
//Process the command
this.commandProcessor[this.argumentArray[0]]();
await this.commandProcessor[this.argumentArray[0].toLowerCase()]();
}
}
}
@ -89,12 +93,23 @@ class commandProcessor{
}
whisper(){
//Ensure we don't double dip
this.sendFlag = false;
//splice out our whisper
this.preprocessor.commandArray.splice(0,2);
//send it
this.server.chatHandler.relayChat(this.preprocessor.socket, this.preprocessor.commandArray.join(''), 'whisper');
return;
}
async announce(){
const chanDB = await channelModel.findOne({name: this.preprocessor.socket.chan});
//Check if the user has permission, and publicly shame them if they don't (lmao)
if(!(this.preprocessor.sendFlag = !(await chanDB.permCheck(this.preprocessor.socket.user, 'announce')))){
//splice out our whisper
this.preprocessor.commandArray.splice(0,2);
//send it
this.server.chatHandler.relayChannelAnnouncement(this.preprocessor.socket, this.preprocessor.commandArray.join(''));
}
}
}

View file

@ -58,6 +58,12 @@ const channelPermissionSchema = new mongoose.Schema({
default: "admin",
required: true
},
announce: {
type: mongoose.SchemaTypes.String,
enum: rankEnum,
default: "admin",
required: true
},
deleteChannel: {
type: mongoose.SchemaTypes.String,
enum: rankEnum,

View file

@ -111,6 +111,12 @@ module.exports.channelPermissionValidator = {
options: module.exports.isRank
},
},
'channelPermissionsMap.announce': {
optional: true,
custom: {
options: module.exports.isRank
},
},
'channelPermissionsMap.deleteChannel': {
optional: true,
custom: {

View file

@ -122,7 +122,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.-->
<%- include('partial/scripts', {user}); %>
<script src="/lib/socket.io/socket.io.min.js"></script>
<script src="/js/channel/commandPreprocessor.js"></script>
<script src="/js/channel/chatPreprocessor.js"></script>
<script src="/js/channel/chatPostprocessor.js"></script>
<script src="/js/channel/chat.js"></script>
<script src="/js/channel/userlist.js"></script>
<script src="/js/channel/player.js"></script>