[Activity] Add interstellar exploration formatter

This commit is contained in:
2023-03-23 10:16:25 +01:00
parent 8db87b9098
commit b6897f7327
4 changed files with 57 additions and 7 deletions

View File

@@ -10,9 +10,11 @@ namespace Cocotte.Modules.Activities;
public class ActivityFormatter
{
private readonly ActivityOptions _options;
private readonly InterstellarFormatter _interstellarFormatter;
public ActivityFormatter(IOptions<ActivityOptions> options)
public ActivityFormatter(IOptions<ActivityOptions> options, InterstellarFormatter interstellarFormatter)
{
_interstellarFormatter = interstellarFormatter;
_options = options.Value;
}
@@ -26,7 +28,7 @@ public class ActivityFormatter
ActivityName.VoidRift => "Failles du néant",
ActivityName.OriginsOfWar => "Origine de la guerre",
ActivityName.JointOperation => "Opération conjointe",
ActivityName.InterstellarExploration => "Portes interstellaires",
ActivityName.InterstellarExploration => "Porte interstellaire",
ActivityName.BreakFromDestiny => "Échapper au destin (3v3)",
ActivityName.CriticalAbyss => "Abîme critique (8v8)",
ActivityName.Event => "Event",
@@ -36,6 +38,11 @@ public class ActivityFormatter
};
}
public static string GetActivityBanner(ActivityName activityName)
{
return $"https://sage.cdn.ilysix.fr/assets/Cocotte/banner/{GetActivityCode(activityName)}.webp";
}
public EmbedBuilder ActivityEmbed(Activity activity, IReadOnlyCollection<ActivityPlayer> players)
{
// Activity full
@@ -53,23 +60,34 @@ public class ActivityFormatter
{
StagedActivity stagedActivity =>
$"{FormatActivityName(activity.Name)} ({players.Count}/{activity.MaxPlayers}) - Étage {stagedActivity.Stage}",
_ => $"{FormatActivityName(activity.Name)} ({players.Count}/{activity.MaxPlayers})"
InterstellarActivity interstellar =>
$"{FormatActivityName(activity.Name)} {_interstellarFormatter.FormatInterstellarColor(interstellar.Color)} ({players.Count}/{activity.MaxPlayers})",
_ =>
$"{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";
string bannerUrl = GetActivityBanner(activity.Name);
var color = activityFull ? Colors.CocotteOrange : Colors.CocotteBlue;
return new EmbedBuilder()
var builder = new EmbedBuilder()
.WithColor(color)
.WithTitle(title)
.WithDescription(description)
.WithImageUrl(bannerUrl)
.WithFields(playersField);
// Add material for interstellar exploration
if (activity is InterstellarActivity interstellarActivity)
{
builder.WithThumbnailUrl(_interstellarFormatter.GetColorIcon(interstellarActivity.Color));
}
return builder;
}
private static string GetActivityCode(ActivityName activityName) => activityName switch

View File

@@ -0,0 +1,30 @@
using Cocotte.Modules.Activities.Models;
namespace Cocotte.Modules.Activities;
public class InterstellarFormatter
{
public string FormatInterstellarColor(InterstellarColor color) => color switch
{
InterstellarColor.Black => "noire",
InterstellarColor.Blue => "bleue",
InterstellarColor.Green => "verte",
InterstellarColor.Red => "rouge",
_ => "N/A"
};
public string InterstellarColorEmote(InterstellarColor color) => color switch
{
InterstellarColor.Black => "<:gate_black:1088385899022258248>",
InterstellarColor.Blue => "<:gate_blue:1088385901324935200>",
InterstellarColor.Green => "<:gate_green:1088385902792945664>",
InterstellarColor.Red => "<:gate_red:1088385905405984859>",
_ => ""
};
public string GetColorIcon(InterstellarColor color)
{
return
$"https://sage.cdn.ilysix.fr/assets/Cocotte/icons/tof/gate/gate_{color.ToString().ToLowerInvariant()}.webp";
}
}

View File

@@ -48,9 +48,10 @@ IHost host = Host.CreateDefaultBuilder(args)
services.AddSingleton<IPlayerInfosRepository, MemoryPlayerInfosRepository>();
services.AddSingleton<RolesOptions>();
// Groups
// Activities
services.AddTransient<ActivityFormatter>();
services.AddSingleton<ActivityHelper>();
services.AddTransient<InterstellarFormatter>();
services.AddTransient<ActivityHelper>();
// Raids
services.AddTransient<RaidFormatter>();

View File

@@ -7,6 +7,7 @@ public class CocotteDbContext : DbContext
{
public DbSet<Activity> Activities => Set<Activity>();
public DbSet<StagedActivity> StagedActivities => Set<StagedActivity>();
public DbSet<InterstellarActivity> InterstellarActivities => Set<InterstellarActivity>();
public DbSet<ActivityPlayer> ActivityPlayers => Set<ActivityPlayer>();
public DbSet<ActivityRolePlayer> ActivityRolePlayers => Set<ActivityRolePlayer>();