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

@@ -11,6 +11,16 @@ export default defineNuxtConfig({
'@vueuse/nuxt',
'@nuxt/image-edge'
],
app: {
head: {
link: [
{ rel: "apple-touch-icon", sizes: "180x180", href: "/apple-touch-icon.png" },
{ rel: "icon", sizes: "32x32", type: "image/png", href: "/favicon-32x32.png" },
{ rel: "icon", sizes: "16x16", type: "image/png", href: "/favicon-16x16.png" },
{ rel: "manifest", href: "/site.webmanifest" },
]
}
},
runtimeConfig: {
discordId: '',
discordSecret: '',

View File

@@ -52,9 +52,11 @@
<script setup>
definePageMeta({
middleware: ["auth"]
middleware: ["auth"],
})
useHead({ title: 'Polarcraft' })
const user = useState('user')
const refreshMinecraftUsername = async () => {

View File

@@ -20,5 +20,7 @@ definePageMeta({
layout: 'blank'
})
useHead({ title: 'Login | Polarcraft' })
const config = useRuntimeConfig()
</script>

View File

@@ -8,4 +8,6 @@
definePageMeta({
middleware: ["auth"]
})
useHead({ title: 'Map | Polarcraft' })
</script>

View File

@@ -8,4 +8,6 @@
definePageMeta({
middleware: ["auth"]
})
useHead({ title: 'Player Stores | Polarcraft' })
</script>

View File

@@ -14,4 +14,6 @@ const user = useState('user')
definePageMeta({
middleware: ["auth"]
})
useHead({ title: 'Team | Polarcraft' })
</script>

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 825 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -0,0 +1 @@
{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}

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 })

View File

@@ -61,3 +61,13 @@ export const applyUsername = async (user) => {
body: { nickname: discordUsername, discordId: user.discord.id }
})
}
export const getUsernameWithTeam = async (user) => {
const teamsColl = db.collection('teams')
const team = user.team ? await teamsColl.findOne({ _id: new ObjectId(user.team.id) }): undefined;
const username = user.team ? user.username + ` [<color:${team.color}>${team.name}</color>]` : user.username;
const usernameWithoutStyle = user.team ? user.username + ` [${team.name}]` : user.username;
return { username: username, usernameWithoutStyle: usernameWithoutStyle, team: team }
}