Team Roles Updates

This commit is contained in:
2025-11-23 13:35:43 -05:00
parent c3e52d6a03
commit 758bef92c7
8 changed files with 131 additions and 6 deletions

View File

@@ -21,6 +21,10 @@ export default class TeamManageCommand extends BotCommand {
option.setName("leader")
.setDescription("Team leader")
.setRequired(true))
.addRoleOption(option =>
option.setName("role")
.setDescription("Team role to assign to members")
.setRequired(true))
.addStringOption(option =>
option.setName("description")
.setDescription("Team description")
@@ -82,6 +86,7 @@ export default class TeamManageCommand extends BotCommand {
if (subcommand === "create") {
const name = interaction.options.getString("name", true);
const leader = interaction.options.getUser("leader", true);
const role = interaction.options.getRole("role", true);
const description = interaction.options.getString("description") || "";
const existing = await Team.findOne({ name });
@@ -92,6 +97,7 @@ export default class TeamManageCommand extends BotCommand {
const team = new Team({
name,
leaderId: leader.id,
roleId: role.id,
description,
points: 0,
memberCount: 0
@@ -104,6 +110,7 @@ export default class TeamManageCommand extends BotCommand {
.addFields(
{ name: "Team Name", value: name, inline: true },
{ name: "Leader", value: `<@${leader.id}>`, inline: true },
{ name: "Role", value: `<@&${role.id}>`, inline: true },
{ name: "Description", value: description || "None", inline: false }
)
.setTimestamp();
@@ -118,10 +125,26 @@ export default class TeamManageCommand extends BotCommand {
return interaction.reply({ content: `❌ Team **${name}** not found.`, flags: MessageFlags.Ephemeral });
}
// Remove role from all team members
const teamMembers = await User.find({ teamId: team._id });
const guild = interaction.guild;
if (guild) {
for (const user of teamMembers) {
try {
const member = await guild.members.fetch(user.userId);
if (member && member.roles.cache.has(team.roleId)) {
await member.roles.remove(team.roleId);
}
} catch (err) {
console.error(`Failed to remove role from ${user.userId}:`, err);
}
}
}
await User.updateMany({ teamId: team._id }, { $set: { teamId: null } });
await Team.deleteOne({ _id: team._id });
return interaction.reply({ content: `✅ Team **${name}** has been deleted.`, flags: MessageFlags.Ephemeral });
return interaction.reply({ content: `✅ Team **${name}** has been deleted and roles removed from members.`, flags: MessageFlags.Ephemeral });
} else if (subcommand === "change-leader") {
const name = interaction.options.getString("name", true);
@@ -147,8 +170,8 @@ export default class TeamManageCommand extends BotCommand {
const embed = new EmbedBuilder()
.setTitle("📋 All Teams")
.setColor(0x60a5fa)
.setDescription(teams.map((t, i) =>
`**${i + 1}.** ${t.name} - Leader: <@${t.leaderId}>\n` +
.setDescription(teams.map((t: any, i: number) =>
`**${i + 1}.** ${t.name} - Leader: <@${t.leaderId}> - Role: <@&${t.roleId}>\n` +
` Members: ${t.memberCount} | Points: ${t.points} (Adjusted: ${t.adjustedPoints})`
).join("\n\n"))
.setTimestamp();
@@ -164,7 +187,7 @@ export default class TeamManageCommand extends BotCommand {
return interaction.reply({ content: `❌ Team **${teamName}** not found.`, flags: MessageFlags.Ephemeral });
}
const result = await PointsManager.joinTeam(user.id, user.username, team._id.toString(), true);
const result = await PointsManager.joinTeam(user.id, user.username, team._id.toString(), true, interaction.guild || undefined);
if (result.success) {
return interaction.reply({ content: `✅ <@${user.id}> has been moved to team **${teamName}**.`, flags: MessageFlags.Ephemeral });