build chat system

This commit is contained in:
2023-05-06 13:09:46 +02:00
parent 5aa8dce299
commit 8d358e694e
9 changed files with 165 additions and 4 deletions

View File

@@ -0,0 +1,20 @@
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' }
});

View File

@@ -0,0 +1,10 @@
export default defineEventHandler(async (event) => {
const { discordId, content } = await readBody(event);
const coll = db.collection('users');
const doc = await coll.findOne({ 'discord.id': discordId });
await sendRconCommand(`tellraw @a {"text":"(DC) ${doc.discord.username} > ${content}"}`)
return { whoo: 'hi' }
});

View File

@@ -0,0 +1,18 @@
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/sendgamemessage', {
method: 'POST',
body: {
avatarURL: 'https://api.mineatar.io/face/' + doc.minecraft.uuid + '?scale=16',
content: content,
}
})
return { code: 'success' }
});