added username system
This commit is contained in:
parent
e5644462b9
commit
1e72ecdf53
@ -1,6 +1,6 @@
|
|||||||
const { SlashCommandBuilder } = require('discord.js');
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
const { simpleEmbed } = require('../functions/embeds.js');
|
const { simpleEmbed } = require('../functions/embeds.js');
|
||||||
const { Minecraft, Users } = require('../functions/models.js');
|
const { Users } = require('../functions/models.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
|
11
discordbot/commands/dennis.js
Normal file
11
discordbot/commands/dennis.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
|
const { simpleEmbed } = require('../functions/embeds.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('dennis')
|
||||||
|
.setDescription('Dennis.'),
|
||||||
|
async execute(interaction) {
|
||||||
|
await interaction.reply({ embeds: [simpleEmbed('Dennis is koel')], ephemeral: true });
|
||||||
|
},
|
||||||
|
};
|
@ -1,6 +1,7 @@
|
|||||||
const { SlashCommandBuilder } = require('discord.js');
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
const { simpleEmbed } = require('../functions/embeds.js');
|
const { simpleEmbed } = require('../functions/embeds.js');
|
||||||
const { Minecraft, Users } = require('../functions/models.js');
|
const { Minecraft, Users } = require('../functions/models.js');
|
||||||
|
const { applyUsername } = require('../functions/utils.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@ -18,11 +19,13 @@ module.exports = {
|
|||||||
|
|
||||||
await user.save();
|
await user.save();
|
||||||
|
|
||||||
|
await applyUsername(user, interaction.member);
|
||||||
|
|
||||||
await interaction.reply({ embeds: [simpleEmbed('Successfully removed you from the whitelist')], ephemeral: true });
|
await interaction.reply({ embeds: [simpleEmbed('Successfully removed you from the whitelist')], ephemeral: true });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
||||||
await interaction.reply({ embeds: [simpleEmbed('There was an error while removing user from the whitelist')], ephemeral: true });
|
await interaction.reply({ embeds: [simpleEmbed('There was an error while removing you from the whitelist')], ephemeral: true });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
38
discordbot/commands/setusername.js
Normal file
38
discordbot/commands/setusername.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
|
const { simpleEmbed } = require('../functions/embeds.js');
|
||||||
|
const { Users } = require('../functions/models.js');
|
||||||
|
const { applyUsername } = require('../functions/utils.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('setusername')
|
||||||
|
.setDescription('Choose between Discord or Minecraft username')
|
||||||
|
.addStringOption(option => option
|
||||||
|
.setName('type')
|
||||||
|
.setDescription('Discord or Minecraft')
|
||||||
|
.setRequired(true)
|
||||||
|
.addChoices(
|
||||||
|
{ name: 'Discord', value: 'discord' },
|
||||||
|
{ name: 'Minecraft', value: 'minecraft' },
|
||||||
|
)),
|
||||||
|
|
||||||
|
async execute(interaction) {
|
||||||
|
const usernameType = interaction.options.getString('type');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const user = await Users.findOne({ where: { id: interaction.user.id } });
|
||||||
|
|
||||||
|
user.useMinecraftUsername = usernameType === 'minecraft' ? true : false;
|
||||||
|
|
||||||
|
await user.save();
|
||||||
|
|
||||||
|
await applyUsername(user, interaction.member);
|
||||||
|
|
||||||
|
await interaction.reply({ embeds: [simpleEmbed('Successfully changed your username type')], ephemeral: true });
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
await interaction.reply({ embeds: [simpleEmbed('There was an error while changing your username type')], ephemeral: true });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
@ -1,6 +1,7 @@
|
|||||||
const { SlashCommandBuilder } = require('discord.js');
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
const { simpleEmbed } = require('../functions/embeds.js');
|
const { simpleEmbed } = require('../functions/embeds.js');
|
||||||
const { Minecraft, Users } = require('../functions/models.js');
|
const { Minecraft, Users } = require('../functions/models.js');
|
||||||
|
const { applyUsername } = require('../functions/utils.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@ -15,6 +16,10 @@ module.exports = {
|
|||||||
const code = interaction.options.getString('code');
|
const code = interaction.options.getString('code');
|
||||||
|
|
||||||
if (code.length !== 6) return await interaction.reply({ embeds: [simpleEmbed('The code must be 6 digits long')], ephemeral: true });
|
if (code.length !== 6) return await interaction.reply({ embeds: [simpleEmbed('The code must be 6 digits long')], ephemeral: true });
|
||||||
|
const user = await Users.findOne({ where: { id: interaction.user.id } });
|
||||||
|
|
||||||
|
if (!user) return await interaction.reply({ embeds: [simpleEmbed('There was an error while finding the user')], ephemeral: true });
|
||||||
|
if (user.minecraftUUID) return await interaction.reply({ embeds: [simpleEmbed('You are already whitelisted')], ephemeral: true });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const minecraftCol = await Minecraft.findOne({ where: { code: code } });
|
const minecraftCol = await Minecraft.findOne({ where: { code: code } });
|
||||||
@ -23,19 +28,21 @@ module.exports = {
|
|||||||
|
|
||||||
if (minecraftCol.whitelisted) return await interaction.reply({ embeds: [simpleEmbed('Minecraft account already whitelisted')], ephemeral: true });
|
if (minecraftCol.whitelisted) return await interaction.reply({ embeds: [simpleEmbed('Minecraft account already whitelisted')], ephemeral: true });
|
||||||
|
|
||||||
const user = await Users.findOne({ where: { id: interaction.user.id } });
|
|
||||||
|
|
||||||
minecraftCol.whitelisted = true;
|
minecraftCol.whitelisted = true;
|
||||||
minecraftCol.code = '';
|
delete minecraftCol.code;
|
||||||
|
|
||||||
user.minecraftUUID = minecraftCol.uuid;
|
user.minecraftUUID = minecraftCol.uuid;
|
||||||
|
|
||||||
await minecraftCol.save();
|
await minecraftCol.save();
|
||||||
await user.save();
|
await user.save();
|
||||||
|
|
||||||
|
await applyUsername(user, interaction.member);
|
||||||
|
|
||||||
|
await interaction.reply({ embeds: [simpleEmbed('You are successfully whitelisted')], ephemeral: true });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
await interaction.reply({ embeds: [simpleEmbed('Successfully whitelisted player ...')], ephemeral: true });
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Binary file not shown.
@ -13,6 +13,13 @@ const Users = sequelize.define('users', {
|
|||||||
minecraftUUID: {
|
minecraftUUID: {
|
||||||
type: Sequelize.UUID,
|
type: Sequelize.UUID,
|
||||||
},
|
},
|
||||||
|
useMinecraftUsername: {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: false,
|
||||||
|
},
|
||||||
|
rawUsername: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
moderator: {
|
moderator: {
|
||||||
type: Sequelize.BOOLEAN,
|
type: Sequelize.BOOLEAN,
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
|
16
discordbot/functions/utils.js
Normal file
16
discordbot/functions/utils.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
const applyUsername = async (user, member) => {
|
||||||
|
let rawUsername = member.user.globalName;
|
||||||
|
|
||||||
|
if (user.useMinecraftUsername && user.minecraftUUID) {
|
||||||
|
const response = await fetch(`https://sessionserver.mojang.com/session/minecraft/profile/${user.minecraftUUID}`);
|
||||||
|
const minecraftProfile = await response.json();
|
||||||
|
|
||||||
|
rawUsername = minecraftProfile.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
await member.setNickname(rawUsername);
|
||||||
|
|
||||||
|
return rawUsername;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = { applyUsername };
|
Loading…
Reference in New Issue
Block a user