Started work on personal emotes.

This commit is contained in:
rainbow napkin 2024-12-22 13:46:08 -05:00
parent db5fac83ab
commit a4a1f6a65b
16 changed files with 248 additions and 18 deletions

View file

@ -17,6 +17,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
//local imports
const commandPreprocessor = require('./commandPreprocessor');
const loggerUtils = require('../../utils/loggerUtils');
const linkUtils = require('../../utils/linkUtils');
const emoteValidator = require('../../validators/emoteValidator');
const {userModel} = require('../../schemas/userSchema');
module.exports = class{
@ -29,6 +31,7 @@ module.exports = class{
socket.on("chatMessage", (data) => {this.handleChat(socket, data)});
socket.on("setFlair", (data) => {this.setFlair(socket, data)});
socket.on("setHighLevel", (data) => {this.setHighLevel(socket, data)});
socket.on("addPersonalEmote", (data) => {this.addPersonalEmote(socket, data)});
}
handleChat(socket, data){
@ -79,6 +82,36 @@ module.exports = class{
}
}
async addPersonalEmote(socket, data){
//Sanatize and Validate input
const name = emoteValidator.manualName(data.name);
const link = emoteValidator.manualLink(data.link);
//If we received good input
if(link && name){
//Generate marked link object
var emote = await linkUtils.markLink(link);
//If the link we have is an image or video
if(emote.type == 'image' || emote.type == 'video'){
//Get user document from DB
const userDB = await userModel.findOne({user: socket.user.user})
//if we have a user in the DB
if(userDB != null){
//Convert marked link into emote object with 1 ez step for only $19.95
emote.name = name;
//add emote to user document emotes list
userDB.emotes.push(emote);
//Save user doc
await userDB.save();
}
}
}
}
relayUserChat(socket, msg, type, links){
const user = this.server.getSocketInfo(socket);
this.relayChat(user.user, user.flair, user.highLevel, msg, type, socket.chan, links)