warn before overwriting gamertag link

This commit is contained in:
SowinskiBraeden committed 2023-05-04 14:00:46 -07:00
1 parent cf504889ed
commit 1baec1b0ed
3 files changed
+141 -1

No files matched your search

+70
View File
@@ -56,6 +56,26 @@ module.exports = {
let playerStat = GuildDB.playerstats.find(stat => stat.gamertag == args[1].value ); let playerStat = GuildDB.playerstats.find(stat => stat.gamertag == args[1].value );
if (playerStat == undefined) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** This gamertag \` ${args[1].value} \` cannot be found, the gamertag may be incorrect or this player has not logged onto the server before for at least \` 5 minutes \`.`)] }); if (playerStat == undefined) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** This gamertag \` ${args[1].value} \` cannot be found, the gamertag may be incorrect or this player has not logged onto the server before for at least \` 5 minutes \`.`)] });
if (client.exists(playerStat.discordID)) {
const warnGTOverwrite = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription(`**Notice:**\n> The gamertag has previously been linked to <@${playerStat.discordID}>. Are you sure you would like to change this?`)
const opt = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId(`AdminOverwriteGamertag-yes-${args[1].value}-${args[0].value}-${interaction.member.user.id}`)
.setLabel("Yes")
.setStyle(ButtonStyle.Success),
new ButtonBuilder()
.setCustomId(`AdminOverwriteGamertag-no-${args[1].value}-${args[0].value}-${interaction.member.user.id}`)
.setLabel("No")
.setStyle(ButtonStyle.Secondary)
)
return interaction.send({ embeds: [warnGTOverwrite], components: [opt] });
}
playerStat.discordID = args[0].value; playerStat.discordID = args[0].value;
let playerStatIndex = GuildDB.playerstats.indexOf(playerStat); let playerStatIndex = GuildDB.playerstats.indexOf(playerStat);
@@ -85,4 +105,54 @@ module.exports = {
return interaction.send({ embeds: [connectedEmbed] }) return interaction.send({ embeds: [connectedEmbed] })
}, },
}, },
Interactions: {
AdminOverwriteGamertag: {
run: async(client, interaction, GuildDB) => {
if (!interaction.customId.endsWith(interaction.member.user.id))
return interaction.reply({ content: 'This interaction is not for you', flags: (1 << 6) });
if (interaction.customId.split('-')[1]=='yes') {
let playerStat = GuildDB.playerstats.find(stat => stat.gamertag == interaction.customId.split('-')[3]);
playerStat.discordID = interaction.customId.split('-')[2];
let playerStatIndex = GuildDB.playerstats.indexOf(playerStat);
GuildDB.playerstats[playerStatIndex] = playerStat;
client.dbo.collection("guilds").updateOne({ 'server.serverID': GuildDB.serverID }, {
$set: {
'server.playerstats': GuildDB.playerstats,
}
});
let member = interaction.guild.members.cache.get(interaction.member.user.id);
if (client.exists(GuildDB.linkedGamertagRole)) {
let role = interaction.guild.roles.cache.get(GuildDB.linkedGamertagRole);
member.roles.add(role);
}
if (client.exists(GuildDB.memberRole)) {
let role = interaction.guild.roles.cache.get(GuildDB.memberRole);
member.roles.add(role);
}
let connectedEmbed = new EmbedBuilder()
.setColor(client.config.Colors.Default)
.setDescription(`Successfully connected \` ${playerStat.gamertag} \` as <@${interaction.customId.split('-')[2]}>'s gamertag.`);
return interaction.update({ embeds: [connectedEmbed], components: [] });
} else {
const cancel = new EmbedBuilder()
.setColor(client.config.Colors.Default)
.setDescription('**Canceled**\n> The gamertag link will not be overwritten');
return interaction.update({ embeds: [cancel], components: [] });
}
}
}
}
} }
+70
View File
@@ -41,6 +41,26 @@ module.exports = {
let playerStat = GuildDB.playerstats.find(stat => stat.gamertag == args[0].value ); let playerStat = GuildDB.playerstats.find(stat => stat.gamertag == args[0].value );
if (playerStat == undefined) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** This gamertag \` ${args[0].value} \` cannot be found, the gamertag may be incorrect or this player has not logged onto the server before for at least \` 5 minutes \`.`)] }); if (playerStat == undefined) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** This gamertag \` ${args[0].value} \` cannot be found, the gamertag may be incorrect or this player has not logged onto the server before for at least \` 5 minutes \`.`)] });
if (client.exists(playerStat.discordID)) {
const warnGTOverwrite = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription(`**Notice:**\n> The gamertag has previously been linked to <@${playerStat.discordID}>. Are you sure you would like to change this?`)
const opt = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId(`OverwriteGamertag-yes-${args[0].value}-${interaction.member.user.id}`)
.setLabel("Yes")
.setStyle(ButtonStyle.Success),
new ButtonBuilder()
.setCustomId(`OverwriteGamertag-no-${args[0].value}-${interaction.member.user.id}`)
.setLabel("No")
.setStyle(ButtonStyle.Secondary)
)
return interaction.send({ embeds: [warnGTOverwrite], components: [opt] });
}
playerStat.discordID = interaction.member.user.id; playerStat.discordID = interaction.member.user.id;
let playerStatIndex = GuildDB.playerstats.indexOf(playerStat); let playerStatIndex = GuildDB.playerstats.indexOf(playerStat);
@@ -70,4 +90,54 @@ module.exports = {
return interaction.send({ embeds: [connectedEmbed] }) return interaction.send({ embeds: [connectedEmbed] })
}, },
}, },
Interactions: {
OverwriteGamertag: {
run: async(client, interaction, GuildDB) => {
if (!interaction.customId.endsWith(interaction.member.user.id))
return interaction.reply({ content: 'This interaction is not for you', flags: (1 << 6) });
if (interaction.customId.split('-')[1]=='yes') {
let playerStat = GuildDB.playerstats.find(stat => stat.gamertag == interaction.customId.split('-')[2]);
playerStat.discordID = interaction.member.user.id;
let playerStatIndex = GuildDB.playerstats.indexOf(playerStat);
GuildDB.playerstats[playerStatIndex] = playerStat;
client.dbo.collection("guilds").updateOne({ 'server.serverID': GuildDB.serverID }, {
$set: {
'server.playerstats': GuildDB.playerstats,
}
});
let member = interaction.guild.members.cache.get(interaction.member.user.id);
if (client.exists(GuildDB.linkedGamertagRole)) {
let role = interaction.guild.roles.cache.get(GuildDB.linkedGamertagRole);
member.roles.add(role);
}
if (client.exists(GuildDB.memberRole)) {
let role = interaction.guild.roles.cache.get(GuildDB.memberRole);
member.roles.add(role);
}
let connectedEmbed = new EmbedBuilder()
.setColor(client.config.Colors.Default)
.setDescription(`Successfully connected \` ${playerStat.gamertag} \` as your gamertag.`);
return interaction.update({ embeds: [connectedEmbed], components: [] });
} else {
const cancel = new EmbedBuilder()
.setColor(client.config.Colors.Default)
.setDescription('**Canceled**\n> The gamertag link will not be overwritten');
return interaction.update({ embeds: [cancel], components: [] });
}
}
}
}
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "dayz-armbands", "name": "dayz-armbands",
"version": "6.6.4", "version": "6.6.5",
"description": "A General Purpose Discord Bot for DayZ Servers.", "description": "A General Purpose Discord Bot for DayZ Servers.",
"main": "index.js", "main": "index.js",
"nodemonConfig": { "nodemonConfig": {