From 79d9f16a8b082108f07c27266a4e8f91057f65f1 Mon Sep 17 00:00:00 2001 From: Eveldee Date: Thu, 23 Mar 2023 11:04:34 +0100 Subject: [PATCH] [Activity] Add CDN refresh --- .../Modules/Activities/ActivityFormatter.cs | 2 +- .../Activities/InterstellarFormatter.cs | 4 ++-- Cocotte/Utils/CdnUtils.cs | 19 +++++++++++++++++++ Cocotte/Utils/EmbedUtils.cs | 8 ++++---- 4 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 Cocotte/Utils/CdnUtils.cs diff --git a/Cocotte/Modules/Activities/ActivityFormatter.cs b/Cocotte/Modules/Activities/ActivityFormatter.cs index a4c1290..9940b73 100644 --- a/Cocotte/Modules/Activities/ActivityFormatter.cs +++ b/Cocotte/Modules/Activities/ActivityFormatter.cs @@ -40,7 +40,7 @@ public class ActivityFormatter public static string GetActivityBanner(ActivityName activityName) { - return $"https://sage.cdn.ilysix.fr/assets/Cocotte/banner/{GetActivityCode(activityName)}.webp"; + return CdnUtils.GetAsset($"banner/{GetActivityCode(activityName)}.webp"); } public EmbedBuilder ActivityEmbed(Activity activity, IReadOnlyCollection players) diff --git a/Cocotte/Modules/Activities/InterstellarFormatter.cs b/Cocotte/Modules/Activities/InterstellarFormatter.cs index f7ddadb..baf3d41 100644 --- a/Cocotte/Modules/Activities/InterstellarFormatter.cs +++ b/Cocotte/Modules/Activities/InterstellarFormatter.cs @@ -1,4 +1,5 @@ using Cocotte.Modules.Activities.Models; +using Cocotte.Utils; namespace Cocotte.Modules.Activities; @@ -24,7 +25,6 @@ public class InterstellarFormatter public string GetColorIcon(InterstellarColor color) { - return - $"https://sage.cdn.ilysix.fr/assets/Cocotte/icons/tof/gate/gate_{color.ToString().ToLowerInvariant()}.webp"; + return CdnUtils.GetAsset($"icons/tof/gate/gate_{color.ToString().ToLowerInvariant()}.webp"); } } \ No newline at end of file diff --git a/Cocotte/Utils/CdnUtils.cs b/Cocotte/Utils/CdnUtils.cs new file mode 100644 index 0000000..05a0824 --- /dev/null +++ b/Cocotte/Utils/CdnUtils.cs @@ -0,0 +1,19 @@ +namespace Cocotte.Utils; + +public class CdnUtils +{ + /// + /// Use this to force discord media cache to fetch new content from CDN + /// + private const string QuerySuffix = $"?q={RandomSuffix}"; + + /// + /// Needs to be updated each time a media is updated on the CDN + /// + private const string RandomSuffix = "a57z45a"; + + public static string GetAsset(string assetName) + { + return $"https://sage.cdn.ilysix.fr/assets/Cocotte/{assetName}{QuerySuffix}"; + } +} \ No newline at end of file diff --git a/Cocotte/Utils/EmbedUtils.cs b/Cocotte/Utils/EmbedUtils.cs index 279461e..8c2109a 100644 --- a/Cocotte/Utils/EmbedUtils.cs +++ b/Cocotte/Utils/EmbedUtils.cs @@ -10,7 +10,7 @@ public static class EmbedUtils .WithColor(Colors.ErrorColor) .WithAuthor(a => a .WithName(title) - .WithIconUrl("https://sage.cdn.ilysix.fr/assets/Cocotte/icons/error.webp") + .WithIconUrl(CdnUtils.GetAsset("icons/error.webp")) ) .WithDescription(message); } @@ -21,7 +21,7 @@ public static class EmbedUtils .WithColor(Colors.InfoColor) .WithAuthor(a => a .WithName(title) - .WithIconUrl("https://sage.cdn.ilysix.fr/assets/Cocotte/icons/info.webp") + .WithIconUrl(CdnUtils.GetAsset("icons/info.webp")) ) .WithDescription(message); } @@ -32,7 +32,7 @@ public static class EmbedUtils .WithColor(Colors.SuccessColor) .WithAuthor(a => a .WithName(title) - .WithIconUrl("https://sage.cdn.ilysix.fr/assets/Cocotte/icons/success.webp") + .WithIconUrl(CdnUtils.GetAsset("icons/success.webp")) ) .WithDescription(message); } @@ -43,7 +43,7 @@ public static class EmbedUtils .WithColor(Colors.WarningColor) .WithAuthor(a => a .WithName(title) - .WithIconUrl("https://sage.cdn.ilysix.fr/assets/Cocotte/icons/warning.webp") + .WithIconUrl(CdnUtils.GetAsset("icons/warning.webp")) ) .WithDescription(message); }