improved communication system

This commit is contained in:
2023-05-12 14:24:28 +02:00
parent d066915ec7
commit 0c7e6d8ee1
22 changed files with 139 additions and 12 deletions

View File

@@ -3,15 +3,17 @@ export default defineEventHandler(async (event) => {
const config = useRuntimeConfig();
const coll = db.collection('users')
const doc = await coll.findOne({ 'minecraft.uuid': uuid })
const usersColl = db.collection('users')
const user = await usersColl.findOne({ 'minecraft.uuid': uuid })
const response = await getUsernameWithTeam(user);
await $fetch(config.discordHost + '/minecraft/sendchatmessage', {
method: 'POST',
body: {
username: doc.discord.username + ' | ' + doc.minecraft.username,
username: response.usernameWithoutStyle,
// avatarURL: 'https://cdn.discordapp.com/avatars/' + doc.discord.id + '/' + doc.discord.avatarHash + '.png',
avatarURL: 'https://api.mineatar.io/face/' + doc.minecraft.uuid + '?scale=16',
avatarURL: 'https://api.mineatar.io/face/' + user.minecraft.uuid + '?scale=16',
content: content,
}
})

View File

@@ -1,10 +1,21 @@
import { getUsernameWithTeam } from "~/server/utils/auth";
export default defineEventHandler(async (event) => {
const { discordId, content } = await readBody(event);
const coll = db.collection('users');
const doc = await coll.findOne({ 'discord.id': discordId });
const user = await coll.findOne({ 'discord.id': discordId });
await sendRconCommand(`tellraw @a {"text":"(DC) ${doc.discord.username} > ${content}"}`)
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' }
});

View File

@@ -1,12 +1,22 @@
import { getUsernameWithTeam } from "~/server/utils/auth";
export default defineEventHandler(async (event) => {
const { uuid } = await readBody(event)
const coll = db.collection('whitelist')
const usersColl = db.collection('users')
const doc = await coll.findOne({ uuid: uuid })
if (doc && !doc.verified) return { code: doc.code, verified: false }
if (doc && doc.verified) return { verified: true }
if (doc && doc.verified) {
const user = await usersColl.findOne({ 'minecraft.uuid': uuid });
const response = await getUsernameWithTeam(user);
return { verified: true, username: response.username, usernameWithoutStyle: response.usernameWithoutStyle }
}
await coll.createIndex({ code: 1 }, { unique: true })