Per-Channel Emotes Implemented.

This commit is contained in:
rainbow napkin 2024-12-21 11:01:00 -05:00
parent 163cecf9f0
commit c3d016e1af
14 changed files with 483 additions and 20 deletions

View file

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

View file

@ -23,6 +23,7 @@ const server = require('../../server');
const statModel = require('../statSchema');
const {userModel} = require('../userSchema');
const permissionModel = require('../permissionSchema');
const emoteModel = require('../emoteSchema');
const channelPermissionSchema = require('./channelPermissionSchema');
const channelBanSchema = require('./channelBanSchema');
const { exceptionHandler, errorHandler } = require('../../utils/loggerUtils');
@ -76,6 +77,23 @@ const channelSchema = new mongoose.Schema({
type: mongoose.SchemaTypes.String,
required: true
}],
//Not re-using the site-wide schema because post save should call different functions
emotes: [{
name:{
type: mongoose.SchemaTypes.String,
required: true
},
link:{
type: mongoose.SchemaTypes.String,
required: true
},
type:{
type: mongoose.SchemaTypes.String,
required: true,
enum: emoteModel.typeEnum,
default: emoteModel.typeEnum[0]
}
}],
//Thankfully we don't have to keep track of alts, ips, or deleted users so this should be a lot easier than site-wide bans :P
banList: [channelBanSchema]
});
@ -160,6 +178,17 @@ channelSchema.pre('save', async function (next){
}
}
if(this.isModified('emotes')){
//Get the active Channel object from the application side of the house
const activeChannel = server.channelManager.activeChannels.get(this.name);
//If the channel is active
if(activeChannel != null){
//Broadcast the emote list
activeChannel.broadcastChanEmotes(this);
}
}
next();
});
@ -439,6 +468,24 @@ channelSchema.methods.checkBanByUserDoc = async function(userDB){
return foundBan;
}
channelSchema.methods.getEmotes = function(){
//Create an empty array to hold our emote list
const emoteList = [];
//For each channel emote
this.emotes.forEach((emote) => {
//Push an object with select information from the emote to the emote list
emoteList.push({
name: emote.name,
link: emote.link,
type: emote.type
});
});
//return the emote list
return emoteList;
}
channelSchema.methods.getChanBans = async function(){
//Create an empty list to hold our found bans
var banList = [];