Polarcraft/web/server/api/minecraft/message/chattominecraft.js

22 lines
728 B
JavaScript

import { getUsernameWithTeam } from "~/server/utils/auth";
export default defineEventHandler(async (event) => {
const { discordId, content } = await readBody(event);
const coll = db.collection('users');
const user = await coll.findOne({ 'discord.id': discordId });
const response = await getUsernameWithTeam(user)
let tellraw;
if (user.team) {
tellraw = `["",{"text":"DC","color":"gray"},{"text":" ${user.username} ["},{"text":"${response.team.name}","color":"${response.team.color}"},{"text":"] > ${content}"}]`
} else {
tellraw = `["",{"text":"DC","color":"gray"},{"text":" ${user.username} > ${content}"}]`
}
await sendRconCommand(`tellraw @a ${tellraw}`)
return { status: 'success' }
});