[Activity] Cleanup embed and code
This commit is contained in:
@@ -22,13 +22,13 @@ public class ActivityFormatter
|
||||
{
|
||||
ActivityName.Abyss => "Abîme du Néant",
|
||||
ActivityName.Raids => "Raids",
|
||||
ActivityName.FrontierClash => "Conflit Frontalier",
|
||||
ActivityName.VoidRift => "Failles du Néant",
|
||||
ActivityName.OriginsOfWar => "Origine de la Guerre",
|
||||
ActivityName.JointOperation => "Opération Conjointe",
|
||||
ActivityName.InterstellarExploration => "Exploration Interstellaire",
|
||||
ActivityName.BreakFromDestiny => "Échapper au Destin (3v3)",
|
||||
ActivityName.CriticalAbyss => "Abîme Critique (8v8)",
|
||||
ActivityName.FrontierClash => "Conflit frontalier",
|
||||
ActivityName.VoidRift => "Failles du néant",
|
||||
ActivityName.OriginsOfWar => "Origine de la guerre",
|
||||
ActivityName.JointOperation => "Opération conjointe",
|
||||
ActivityName.InterstellarExploration => "Exploration interstellaire",
|
||||
ActivityName.BreakFromDestiny => "Échapper au destin (3v3)",
|
||||
ActivityName.CriticalAbyss => "Abîme critique (8v8)",
|
||||
ActivityName.Event => "Event",
|
||||
ActivityName.Fishing => "Pêche",
|
||||
ActivityName.MirroriaRace => "Course Mirroria",
|
||||
@@ -38,10 +38,13 @@ public class ActivityFormatter
|
||||
|
||||
public EmbedBuilder ActivityEmbed(Activity activity, IReadOnlyCollection<ActivityPlayer> players)
|
||||
{
|
||||
// Compute padding using player with longest name
|
||||
var namePadding = players.Count > 0 ? players.Max(p => p.Name.Length) : 0;
|
||||
|
||||
// Players field
|
||||
var playersField = new EmbedFieldBuilder()
|
||||
.WithName("Joueurs inscrits")
|
||||
.WithValue($"{(!players.Any() ? "*Aucun joueur inscrit*" : string.Join("\n", players.Select(FormatActivityPlayer)))}");
|
||||
.WithValue($"{(!players.Any() ? "*Aucun joueur inscrit*" : string.Join("\n\n", players.Select(p => FormatActivityPlayer(p, namePadding))))}");
|
||||
|
||||
var title = activity switch
|
||||
{
|
||||
@@ -50,12 +53,16 @@ public class ActivityFormatter
|
||||
_ => $"{FormatActivityName(activity.Name)} ({players.Count}/{activity.MaxPlayers})"
|
||||
};
|
||||
|
||||
string description = string.IsNullOrWhiteSpace(activity.Description)
|
||||
? $"Rejoignez l'activité de {MentionUtils.MentionUser(activity.CreatorDiscordId)}"
|
||||
: activity.Description;
|
||||
|
||||
string bannerUrl = $"https://sage.cdn.ilysix.fr/assets/Cocotte/banner/{GetActivityCode(activity.Name)}.webp";
|
||||
|
||||
return new EmbedBuilder()
|
||||
.WithColor(Colors.CocotteBlue)
|
||||
.WithTitle(title)
|
||||
.WithDescription($"{activity.Description}")
|
||||
.WithDescription(description)
|
||||
.WithImageUrl(bannerUrl)
|
||||
.WithFields(playersField);
|
||||
}
|
||||
@@ -65,7 +72,7 @@ public class ActivityFormatter
|
||||
ActivityName.Abyss => "VA",
|
||||
ActivityName.OriginsOfWar => "OOW",
|
||||
ActivityName.Raids => "RD",
|
||||
ActivityName.FrontierClash => "FC",
|
||||
ActivityName.FrontierClash => "FCH",
|
||||
ActivityName.VoidRift => "VR",
|
||||
ActivityName.JointOperation => "JO",
|
||||
ActivityName.InterstellarExploration => "IE",
|
||||
@@ -77,9 +84,9 @@ public class ActivityFormatter
|
||||
_ => "NA"
|
||||
};
|
||||
|
||||
public string FormatActivityPlayer(ActivityPlayer player) => player switch
|
||||
public string FormatActivityPlayer(ActivityPlayer player, int namePadding) => player switch
|
||||
{
|
||||
ActivityRolePlayer rolePlayer => $"{player.Name} - {RolesToEmotes(rolePlayer.Roles)}",
|
||||
ActivityRolePlayer rolePlayer => $"` {player.Name.PadRight(namePadding)} ` **―** {RolesToEmotes(rolePlayer.Roles)}",
|
||||
_ => $"{player.Name})"
|
||||
};
|
||||
|
||||
|
||||
@@ -45,9 +45,9 @@ public partial class ActivityModule : InteractionModuleBase<SocketInteractionCon
|
||||
}
|
||||
|
||||
[SlashCommand("abime", "Créer un groupe pour l'Abîme du Néant")]
|
||||
public async Task ActivityAbyss([Summary("étage", "A quel étage êtes vous")] uint stage, [Summary("description", "Message accompagnant la demande de groupe")] string description = "")
|
||||
public async Task ActivityAbyss([Summary("étage", "A quel étage êtes vous")] [MinValue(1), MaxValue(6)] uint stage, [Summary("description", "Message accompagnant la demande de groupe")] string description = "")
|
||||
{
|
||||
const ActivityName activityName = ActivityName.OriginsOfWar;
|
||||
const ActivityName activityName = ActivityName.Abyss;
|
||||
var activityType = ActivityHelper.ActivityNameToType(activityName);
|
||||
var maxPlayers = ActivityHelper.ActivityTypeToMaxPlayers(activityType);
|
||||
|
||||
@@ -59,6 +59,7 @@ public partial class ActivityModule : InteractionModuleBase<SocketInteractionCon
|
||||
Description = description,
|
||||
Type = activityType,
|
||||
Name = activityName,
|
||||
RoleEnabled = true,
|
||||
MaxPlayers = maxPlayers,
|
||||
Stage = stage
|
||||
};
|
||||
@@ -103,8 +104,8 @@ public partial class ActivityModule : InteractionModuleBase<SocketInteractionCon
|
||||
});
|
||||
}
|
||||
|
||||
[ComponentInteraction("activity join_role:*", ignoreGroupNames: true)]
|
||||
private async Task JoinActivityRole(ulong activityId)
|
||||
[ComponentInteraction("activity join:*", ignoreGroupNames: true)]
|
||||
private async Task JoinActivity(ulong activityId)
|
||||
{
|
||||
var user = (SocketGuildUser)Context.User;
|
||||
|
||||
@@ -120,7 +121,7 @@ public partial class ActivityModule : InteractionModuleBase<SocketInteractionCon
|
||||
}
|
||||
|
||||
// If player is already registered
|
||||
if (await _activitiesRepository.FindActivityRolePlayer(activityId, user.Id) is not null)
|
||||
if (await _activitiesRepository.FindActivityPlayer(activityId, user.Id) is not null)
|
||||
{
|
||||
await RespondAsync(
|
||||
ephemeral: true,
|
||||
@@ -143,17 +144,21 @@ public partial class ActivityModule : InteractionModuleBase<SocketInteractionCon
|
||||
|
||||
_logger.LogTrace("Player {Player} joined activity {Id}", user.DisplayName, activityId);
|
||||
|
||||
var roles = _activityHelper.GetPlayerRoles(user.Roles);
|
||||
var activityRolePlayer = new ActivityRolePlayer
|
||||
var activityPlayer = activity.RoleEnabled ? new ActivityRolePlayer
|
||||
{
|
||||
Activity = activity,
|
||||
DiscordId = user.Id,
|
||||
Name = user.DisplayName,
|
||||
Roles = roles
|
||||
Roles = _activityHelper.GetPlayerRoles(user.Roles)
|
||||
} : new ActivityPlayer
|
||||
{
|
||||
Activity = activity,
|
||||
DiscordId = user.Id,
|
||||
Name = user.DisplayName
|
||||
};
|
||||
|
||||
// Add player to activity
|
||||
activity.ActivityPlayers.Add(activityRolePlayer);
|
||||
activity.ActivityPlayers.Add(activityPlayer);
|
||||
await _activitiesRepository.SaveChanges();
|
||||
|
||||
// Update activity embed
|
||||
@@ -165,8 +170,8 @@ public partial class ActivityModule : InteractionModuleBase<SocketInteractionCon
|
||||
);
|
||||
}
|
||||
|
||||
[ComponentInteraction("activity leave_role:*", ignoreGroupNames: true)]
|
||||
private async Task LeaveActivityRole(ulong activityId)
|
||||
[ComponentInteraction("activity leave:*", ignoreGroupNames: true)]
|
||||
private async Task LeaveActivity(ulong activityId)
|
||||
{
|
||||
var user = (IGuildUser)Context.User;
|
||||
|
||||
@@ -206,14 +211,6 @@ public partial class ActivityModule : InteractionModuleBase<SocketInteractionCon
|
||||
);
|
||||
}
|
||||
|
||||
// [ComponentInteraction("activity event_join:*", ignoreGroupNames: true)]
|
||||
// private async Task JoinEventActivity(ulong activityId)
|
||||
// {
|
||||
// _logger.LogTrace("Player {Player} joined activity {Id}", ((IGuildUser)Context.User).DisplayName, activityId);
|
||||
//
|
||||
// await RespondAsync(activityId.ToString());
|
||||
// }
|
||||
|
||||
private async Task UpdateActivityEmbed(Activity activity)
|
||||
{
|
||||
// Get channel
|
||||
@@ -239,13 +236,15 @@ public partial class ActivityModule : InteractionModuleBase<SocketInteractionCon
|
||||
.AddRow(new ActionRowBuilder()
|
||||
.WithButton(new ButtonBuilder()
|
||||
.WithLabel("Rejoindre l'activité")
|
||||
.WithCustomId($"activity join_role:{activityId}")
|
||||
.WithCustomId($"activity join:{activityId}")
|
||||
.WithEmote(":white_check_mark:".ToEmote())
|
||||
.WithStyle(ButtonStyle.Primary)
|
||||
)
|
||||
.WithButton(new ButtonBuilder()
|
||||
.WithLabel("Se désinscrire de l'activité")
|
||||
.WithCustomId($"activity leave_role:{activityId}")
|
||||
.WithStyle(ButtonStyle.Danger)
|
||||
.WithCustomId($"activity leave:{activityId}")
|
||||
.WithEmote(":x:".ToEmote())
|
||||
.WithStyle(ButtonStyle.Secondary)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,21 +17,11 @@ public class ActivitiesRepository
|
||||
return await _cocotteDbContext.Activities.FindAsync(activityId);
|
||||
}
|
||||
|
||||
public async Task<StagedActivity?> FindStagedActivity(ulong activityId)
|
||||
{
|
||||
return await _cocotteDbContext.StagedActivities.FindAsync(activityId);
|
||||
}
|
||||
|
||||
public async Task<ActivityPlayer?> FindActivityPlayer(ulong activityId, ulong playerId)
|
||||
{
|
||||
return await _cocotteDbContext.ActivityPlayers.FindAsync(activityId, playerId);
|
||||
}
|
||||
|
||||
public async Task<ActivityRolePlayer?> FindActivityRolePlayer(ulong activityId, ulong playerId)
|
||||
{
|
||||
return await _cocotteDbContext.ActivityRolePlayers.FindAsync(activityId, playerId);
|
||||
}
|
||||
|
||||
public async Task<int> ActivityPlayerCount(Activity activity) =>
|
||||
await _cocotteDbContext.ActivityPlayers.Where(player => player.ActivityId == activity.ActivityId).CountAsync();
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ public abstract class Activity
|
||||
public string? Description { get; init; }
|
||||
public required ActivityType Type { get; init; }
|
||||
public required ActivityName Name { get; init; }
|
||||
public required bool RoleEnabled { get; init; }
|
||||
public required uint MaxPlayers { get; set; }
|
||||
|
||||
public List<ActivityPlayer> ActivityPlayers { get; init; } = new();
|
||||
|
||||
Reference in New Issue
Block a user