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

23 lines
725 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();
2023-05-12 14:24:28 +02:00
const usersColl = db.collection('users')
const user = await usersColl.findOne({ 'minecraft.uuid': uuid })
const response = await getUsernameWithTeam(user);
2023-05-06 13:09:46 +02:00
await $fetch(config.discordHost + '/minecraft/sendchatmessage', {
method: 'POST',
body: {
2023-05-12 14:24:28 +02:00
username: response.usernameWithoutStyle,
2023-05-06 13:09:46 +02:00
// avatarURL: 'https://cdn.discordapp.com/avatars/' + doc.discord.id + '/' + doc.discord.avatarHash + '.png',
2023-05-12 14:24:28 +02:00
avatarURL: 'https://api.mineatar.io/face/' + user.minecraft.uuid + '?scale=16',
2023-05-06 13:09:46 +02:00
content: content,
}
})
return { code: 'success' }
});