improved team system

This commit is contained in:
Xeovalyte 2023-05-11 19:46:59 +02:00
parent 51705f8651
commit d066915ec7
9 changed files with 178 additions and 2 deletions

BIN
assets/logo-zoomed.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 899 KiB

BIN
assets/logo.blend Normal file

Binary file not shown.

BIN
assets/logo.blend1 Normal file

Binary file not shown.

BIN
assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 984 KiB

BIN
assets/server-icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@ -26,9 +26,13 @@ require('./functions/player.js').registerEvents({ client, createEmbed });
const app = express();
app.use(express.json());
const messageRoute = require('./routes/Message');
const minecraftRoute = require('./routes/Minecraft');
const userRoute = require('./routes/User');
const teamRoute = require('./routes/Team');
app.use('/minecraft', messageRoute);
app.use('/minecraft', minecraftRoute);
app.use('/user', userRoute);
app.use('/team', teamRoute);
app.listen('4000', () => {
log.Info('Express app running');

145
discord-bot/routes/Team.js Normal file
View File

@ -0,0 +1,145 @@
const express = require('express');
const index = require('../index');
const { PermissionsBitField, ChannelType } = require('discord.js');
const router = express.Router();
router.post('/createchannels', async (req, res) => {
const { name, discordId } = req.body;
if (!name || !discordId ) return res.status(400).send({ error: 'Name en discordId zijn vereist' });
try {
const guild = await index.client.guilds.fetch(process.env.GUILD_ID);
const category = await guild.channels.fetch(process.env.TEAM_CATEGORY_ID);
const member = await guild.members.fetch(discordId)
const textChannel = await guild.channels.create({
name: name,
type: ChannelType.GuildText,
parent: category,
permissionOverwrites: [
{
id: guild.id,
deny: [PermissionsBitField.Flags.ViewChannel],
},
{
id: member.id,
allow: [PermissionsBitField.Flags.ViewChannel]
}
]
});
const voiceChannel = await guild.channels.create({
name: name,
type: ChannelType.GuildVoice,
parent: category,
permissionOverwrites: [
{
id: guild.id,
deny: [PermissionsBitField.Flags.ViewChannel],
},
{
id: member.id,
allow: [PermissionsBitField.Flags.ViewChannel]
}
]
});
res.send({ textChannel, voiceChannel });
} catch (e) {
console.log(e);
return res.status(500).send({ error: 'Error tijdens het maken van discord channels' })
}
});
router.post('/deletechannels', async (req, res) => {
const { textChannelId, voiceChannelId } = req.body;
if (!textChannelId, !voiceChannelId ) return res.status(400).send({ error: 'textChannelId en voiceChannelId zijn vereist' });
try {
const guild = await index.client.guilds.fetch(process.env.GUILD_ID);
const textChannel = await guild.channels.fetch(textChannelId);
const voiceChannel = await guild.channels.fetch(voiceChannelId);
await textChannel.delete()
await voiceChannel.delete()
res.send({ status: 'success' });
} catch (e) {
console.log(e);
return res.status(500).send({ error: 'Error tijdens het verwijderen van discord channels' })
}
});
router.post('/removeteammember', async (req, res) => {
const { textChannelId, voiceChannelId, discordId } = req.body;
if (!textChannelId, !voiceChannelId, !discordId ) return res.status(400).send({ error: 'textChannelId, voiceChannelId en discordId zijn vereist' });
try {
const guild = await index.client.guilds.fetch(process.env.GUILD_ID);
const member = await guild.members.fetch(discordId)
const textChannel = await guild.channels.fetch(textChannelId);
const voiceChannel = await guild.channels.fetch(voiceChannelId);
await textChannel.permissionOverwrites.delete(member)
await voiceChannel.permissionOverwrites.delete(member)
res.send({ status: 'success' });
} catch (e) {
console.log(e);
return res.status(500).send({ error: 'Error tijdens het verwijderen van een team member' })
}
});
router.post('/addteammember', async (req, res) => {
const { textChannelId, voiceChannelId, discordId } = req.body;
if (!textChannelId, !voiceChannelId, !discordId ) return res.status(400).send({ error: 'textChannelId, voiceChannelId en discordId zijn vereist' });
try {
const guild = await index.client.guilds.fetch(process.env.GUILD_ID);
const member = await guild.members.fetch(discordId)
const textChannel = await guild.channels.fetch(textChannelId);
const voiceChannel = await guild.channels.fetch(voiceChannelId);
await textChannel.permissionOverwrites.edit(member, { ViewChannel: true })
await voiceChannel.permissionOverwrites.edit(member, { ViewChannel: true })
res.send({ status: 'success' });
} catch (e) {
console.log(e);
return res.status(500).send({ error: 'Error tijdens het toevoegen van team member' })
}
});
router.post('/edit', async (req, res) => {
const { textChannelId, voiceChannelId, name } = req.body;
if (!textChannelId, !voiceChannelId, !name ) return res.status(400).send({ error: 'textChannelId, voiceChannelId en name zijn vereist' });
try {
const guild = await index.client.guilds.fetch(process.env.GUILD_ID);
const textChannel = await guild.channels.fetch(textChannelId);
const voiceChannel = await guild.channels.fetch(voiceChannelId);
await textChannel.edit({ name: name })
await voiceChannel.edit({ name: name })
res.send({ status: 'success' });
} catch (e) {
console.log(e);
return res.status(500).send({ error: 'Error tijds het veranderen van Discord channel naam' })
}
});
module.exports = router;

View File

@ -0,0 +1,27 @@
const express = require('express');
const index = require('../index')
const router = express.Router();
router.post('/changenickname', async (req, res) => {
const { nickname, discordId } = req.body;
if (!nickname || !discordId ) return res.status(400).send({ error: 'Nickname en discordId zijn vereist' });
const nick = nickname.length > 32 ? nickname.slice(0, 32) : nickname
try {
const guild = await index.client.guilds.fetch(process.env.GUILD_ID);
const member = await guild.members.fetch(discordId)
await member.edit({ nick: nick })
} catch (e) {
console.log(e);
return res.status(500).send({ error: 'Error tijds het veranderen van de nickname' })
}
res.send({ status: 'success' });
});
module.exports = router;