Skip to content

Commit

Permalink
hot fixed issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JayNightmare committed Oct 3, 2024
1 parent 0d3c838 commit c3a9b31
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 43 deletions.
2 changes: 1 addition & 1 deletion bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ client.on('guildMemberAdd', async (member) => {
const welcomeEmbed = new EmbedBuilder()
.setTitle(`YAY! Welcome to ${member.guild.name} ${member.user.displayName}!`)
.setDescription(`
Yayyy! ${member.user} -sama has joined the fight to defend Earth with Son Goku and Sailor Moon.
Yayyy! ${member.user}-sama has joined the fight to defend Earth with Son Goku and Sailor Moon.
\nWe now have ${member.guild.memberCount} warriors to join the fight! But are you a Saiyan, a Senshi, or both?
\n\n${member.user}-sama, please select your roles to identify your training grounds, your identification, and other things Goku and Usagi will need to know (they are a bit clueless).`)
.setColor(0x008080)
Expand Down
14 changes: 11 additions & 3 deletions commands/admin_commands/admin_commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ module.exports = {

// Fetch the bans from the guild
try {
await interaction.deferReply({ ephemeral: true });

const bans = await interaction.guild.bans.fetch();
const bannedUser = bans.get(user.id);

if (!bannedUser) {
return interaction.reply({ content: 'The specified user is not banned', ephemeral: true });
return interaction.editReply({ content: 'The specified user is not banned', ephemeral: true });
}

// Unban the user
Expand All @@ -81,10 +83,16 @@ module.exports = {
.setColor(0x2ECC71)
.addFields({ name: 'Reason', value: reason });

return interaction.reply({ embeds: [embed] });
return interaction.editReply({ embeds: [embed] });
} catch (err) {
console.error('Error unbanning user:', err);
return interaction.reply({ content: 'An error occurred while trying to unban the user', ephemeral: true });

// Check if the interaction is already acknowledged
if (interaction.replied || interaction.deferred) {
return interaction.followUp({ content: 'An error occurred while trying to unban the user', ephemeral: true });
} else {
return interaction.reply({ content: 'An error occurred while trying to unban the user', ephemeral: true });
}
}
}
},
Expand Down
3 changes: 0 additions & 3 deletions commands/community_commands/community_commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ module.exports = {

const userId = user.id;

console.log(`Part 1: Updated by ${user.username}`);
await updateUserBio(serverId, userId, bio);
console.log(`Part 2: Updated by ${user.username}`);
// Confirmation message
const confirmEmbed = new EmbedBuilder()
.setColor(0x00FF00)
.setTitle("Bio Updated")
Expand Down
37 changes: 29 additions & 8 deletions commands/milestone_commands/milestone_commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,48 @@ module.exports = {
const guildId = interaction.guild.id;

try {
// Fetch the user's highest role
const member = interaction.guild.members.cache.get(interaction.user.id);
const highestRole = member.roles.highest;

// Check if a milestone for this level exists in the database
const existingMilestone = await MilestoneLevel.findOne({
where: {
guildId,
level
}
});

if (!existingMilestone) { return interaction.reply({ content: `No milestone for level ${level} exists.`, ephemeral: true }); }

// Remove milestone level from the database

if (!existingMilestone) {
return interaction.reply({ content: `No milestone for level ${level} exists.`, ephemeral: true });
}

// Fetch the role associated with the milestone level
const roleToRemove = interaction.guild.roles.cache.get(existingMilestone.reward);

if (!roleToRemove) {
return interaction.reply({ content: 'The role associated with this milestone does not exist in the server.', ephemeral: true });
}

// Check if the user's highest role is above or below the milestone role
if (highestRole.position <= roleToRemove.position) {
return interaction.reply({ content: 'You cannot remove a milestone role that is higher or equal to your own highest role.', ephemeral: true });
}

// If all checks are passed, remove milestone level from the database
await existingMilestone.destroy();

const embed = new EmbedBuilder()
.setColor(0x008080)
.setTitle('Milestone Removed')
.setDescription(`Milestone for level ${level} has been removed.`)
.setTimestamp();

return interaction.reply({ embeds: embed });
} catch (error) { return interaction.reply({ content: 'An error occurred while removing the milestone. Please try again later.', ephemeral: true }); }

return interaction.reply({ embeds: [embed] });
} catch (error) {
console.error('Error removing milestone:', error);
return interaction.reply({ content: 'An error occurred while removing the milestone. Please try again later.', ephemeral: true });
}
}
},

Expand Down
78 changes: 50 additions & 28 deletions commands/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,38 +96,60 @@ async function checkAndGrantMilestoneRoles(member, guildId, level, message) {
let roleGranted = false;

// Go through each milestone and check if the user has the role
for (const milestone of milestones) {
const role = member.guild.roles.cache.get(milestone.reward);
if (!role) {
continue;
}

// Check if the member already has the role
if (!member.roles.cache.has(role.id)) {
// Add the role if missing
await member.roles.add(role);

if (rankUpChannel) {
const embed = new EmbedBuilder()
.setTitle('Transformation!')
.setDescription(`πŸŽ‰ <@${member.user.id}> has been granted <@&${role.id}> for reaching level ${milestone.level}! πŸŽ‰`)
.setColor(0x008080);

// if milestone role exists, go through for loop
if (milestones.length > 0) {
for (const milestone of milestones) {
const role = member.guild.roles.cache.get(milestone.reward);
if (!role) {
continue;
}

rankUpChannel.send({ embeds: [embed] });
// Check if the member already has the role
if (!member.roles.cache.has(role.id)) {
// Add the role if missing
await member.roles.add(role);

if (rankUpChannel) {
const embed = new EmbedBuilder()
.setTitle('πŸŽ‰ **Transformation Reached!** πŸŽ‰')
.setDescription(`
### <@${member.user.id}> has been granted <@&${role.id}> for reaching Level ${milestone.level}!
**Keep training to reach the next transformation!**
`)
.setImage(`https://tenor.com/en-GB/view/sailor-moon-anime-moon-prism-power-moon-prism-power-makeup-serena-gif-15851654.gif`)
.setColor(0x008080);

rankUpChannel.send({ embeds: [embed] });
}
} else {
if (rankUpChannel) {
const embed = new EmbedBuilder()
.setTitle('πŸŽ‰ **Transformation Reached!** πŸŽ‰')
.setDescription(`
**<@${member.user.id}> has been granted <@&${role.id}> for reaching Level ${milestone.level}!**
Keep training to reach the next transformation!
`)
.setImage(`https://tenor.com/en-GB/view/sailor-moon-anime-moon-prism-power-moon-prism-power-makeup-serena-gif-15851654.gif`)
.setColor(0x008080);

rankUpChannel.send({ embeds: [embed] });
}
}
}
} else {
// Send a message even if no milestone role was granted
if (!roleGranted && rankUpChannel) {
const embed = new EmbedBuilder()
.setTitle('Keep Training!')
.setDescription(`Great job, <@${member.user.id}>! You're currently at level ${level}. Keep training to reach the next transformation!`)
.setColor(0xFFD700);

rankUpChannel.send({ embeds: [embed] });
}
}

// Send a message even if no milestone role was granted
if (!roleGranted && rankUpChannel) {
const embed = new EmbedBuilder()
.setTitle('Keep Training!')
.setDescription(`Great job, <@${member.user.id}>! You're currently at level ${level}. Keep training to reach the next transformation!`)
.setColor(0xFFD700);

rankUpChannel.send({ embeds: [embed] });
}

} catch (err) {
console.error(`Error checking and granting milestone roles for user ${member.user.username}:`, err);
}
Expand Down

0 comments on commit c3a9b31

Please sign in to comment.