2023-05-12 14:24:28 +02:00
|
|
|
import { getUsernameWithTeam } from "~/server/utils/auth";
|
|
|
|
|
2023-05-06 13:09:46 +02:00
|
|
|
export default defineEventHandler(async (event) => {
|
|
|
|
const { discordId, content } = await readBody(event);
|
|
|
|
|
|
|
|
const coll = db.collection('users');
|
2023-05-12 14:24:28 +02:00
|
|
|
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}"}]`
|
|
|
|
}
|
2023-05-06 13:09:46 +02:00
|
|
|
|
2023-05-12 14:24:28 +02:00
|
|
|
await sendRconCommand(`tellraw @a ${tellraw}`)
|
2023-05-06 13:09:46 +02:00
|
|
|
|
2023-05-09 16:01:19 +02:00
|
|
|
return { status: 'success' }
|
2023-05-06 13:09:46 +02:00
|
|
|
});
|