improved communication system

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

BIN
assets/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 KiB

BIN
assets/logo-zoomed.xcf Normal file

Binary file not shown.

View File

@ -0,0 +1,70 @@
const { SlashCommandBuilder, PermissionsBitField, ChannelType, ButtonStyle, ButtonBuilder, ActionRowBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('ticket')
.setDescription('Commands for managing a ticket')
.addSubcommand(subcommand => subcommand
.setName('create')
.setDescription('Create a ticket with you and moderators'))
.addSubcommand(subcommand => subcommand
.setName('close')
.setDescription('Close current ticket')),
async execute({ interaction, createEmbed }) {
if (interaction.options.getSubcommand() === 'create') {
await interaction.reply({ embeds: [createEmbed.basic('Creating ticket channel...')], fetchReply: true, ephemeral: true });
const ticketChannel = await interaction.member.guild.channels.create({
name: `ticket-${interaction.user.username}`,
type: ChannelType.GuildText,
parent: process.env.TICKET_CATEGORY_ID,
permissionOverwrites: [
{
id: interaction.guild.id,
deny: [PermissionsBitField.Flags.ViewChannel],
},
{
id: process.env.MODERATOR_ROLE_ID,
allow: [PermissionsBitField.Flags.ViewChannel],
},
{
id: interaction.user.id,
allow: [PermissionsBitField.Flags.ViewChannel],
},
],
});
await ticketChannel.send({ embeds: [createEmbed.basic(`${interaction.user} created a ticket`)]});
interaction.editReply({ embeds: [createEmbed.basic(`${ticketChannel} has been created`)], emphemeral: true });
} else if (interaction.options.getSubcommand() === 'close') {
if (!interaction.channel.name.startsWith('ticket')) return interaction.reply({ embeds: [createEmbed.basic('You must execute this command inside a ticket channel')], emphemeral: true });
const cancelRow = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('cancel')
.setLabel('Cancel')
.setStyle(ButtonStyle.Danger),
);
const closeMessage = await interaction.reply({ embeds: [createEmbed.basic(`Closing ticket in 10 seconds...`)], components: [cancelRow]});
const collector = closeMessage.createMessageComponentCollector();
const timeout = setTimeout(() => {
try {
interaction.channel.delete()
} catch {}
}, 10000)
collector.on('collect', async () => {
clearTimeout(timeout);
await closeMessage.edit({ embeds: [createEmbed.basic('Ticket closing has been stopped')], components: [] });
});
}
},
};

View File

@ -43,7 +43,7 @@ public class PolarcraftMod implements ModInitializer {
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
ServerPlayerEntity player = (ServerPlayerEntity) handler.player;
verifyFunction.onPlayerJoin(player);
verifyFunction.onPlayerJoin(player, server);
});
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {

View File

@ -14,11 +14,12 @@ import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
public class verifyFunction {
public static void onPlayerJoin(ServerPlayerEntity player) {
public static void onPlayerJoin(ServerPlayerEntity player, MinecraftServer server) {
UUID uuid = player.getUuid();
try {
@ -55,7 +56,9 @@ public class verifyFunction {
player.networkHandler.disconnect(Text.literal("Whitelist yourself by using this code: " + code));
} else {
messageFunctions.sendGameMessage(player.getUuid(), player.getDisplayName().getString() + " joined the game");
server.getCommandManager().executeWithPrefix(server.getCommandSource(), "/lp user " + player.getUuid() + " meta set display " + "\"" + jsonResponse.get("username").getAsString() + "\"");
messageFunctions.sendGameMessage(player.getUuid(), jsonResponse.get("usernameWithoutStyle").getAsString() + " joined the game");
}
} catch (IOException e) {
player.networkHandler.disconnect(Text.literal("There was an error while verifing your account"));

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