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

21 lines
686 B
JavaScript
Raw Normal View History

2023-05-06 13:09:46 +02:00
export default defineEventHandler(async (event) => {
const { content, uuid } = await readBody(event);
const config = useRuntimeConfig();
const coll = db.collection('users')
const doc = await coll.findOne({ 'minecraft.uuid': uuid })
await $fetch(config.discordHost + '/minecraft/sendchatmessage', {
method: 'POST',
body: {
username: doc.discord.username + ' | ' + doc.minecraft.username,
// avatarURL: 'https://cdn.discordapp.com/avatars/' + doc.discord.id + '/' + doc.discord.avatarHash + '.png',
avatarURL: 'https://api.mineatar.io/face/' + doc.minecraft.uuid + '?scale=16',
content: content,
}
})
return { code: 'success' }
});