From bd476253d745e40d7fcd6e445f53b79f4a3677b0 Mon Sep 17 00:00:00 2001 From: Larry Date: Sat, 13 Jan 2024 14:20:56 -0700 Subject: [PATCH 1/4] Push a fake change --- DiscordPlayerCountBot/ViewModels/Steam/SteamViewModel.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/DiscordPlayerCountBot/ViewModels/Steam/SteamViewModel.cs b/DiscordPlayerCountBot/ViewModels/Steam/SteamViewModel.cs index 7fb44da..4bccadb 100644 --- a/DiscordPlayerCountBot/ViewModels/Steam/SteamViewModel.cs +++ b/DiscordPlayerCountBot/ViewModels/Steam/SteamViewModel.cs @@ -4,6 +4,5 @@ public class SteamViewModel : BaseViewModel { public string Map { get; set; } public string Gametype { get; set; } - } } From d109a91261229e95e699981a7ddcad490de6681f Mon Sep 17 00:00:00 2001 From: Larry Date: Sat, 13 Jan 2024 14:25:47 -0700 Subject: [PATCH 2/4] Add sunmoon tag and time tag --- DiscordPlayerCountBot/Bot/BotInformation.cs | 2 ++ .../Providers/BattleMetricsProvider.cs | 13 ++++++++++- .../Providers/SteamProvider.cs | 22 ++++++++++++++++++- .../BattleMetrics/BattleMetricsViewModel.cs | 1 + .../ViewModels/Steam/SteamViewModel.cs | 2 ++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/DiscordPlayerCountBot/Bot/BotInformation.cs b/DiscordPlayerCountBot/Bot/BotInformation.cs index 085b629..4b4b345 100644 --- a/DiscordPlayerCountBot/Bot/BotInformation.cs +++ b/DiscordPlayerCountBot/Bot/BotInformation.cs @@ -12,6 +12,8 @@ public class BotInformation public int ProviderType { get; set; } = 0; public ulong? ChannelID { get; set; } public string? StatusFormat { get; set; } + public int? SunriseHour { get; set; } + public int? SunsetHour { get; set; } public Tuple GetAddressAndPort() { diff --git a/DiscordPlayerCountBot/Providers/BattleMetricsProvider.cs b/DiscordPlayerCountBot/Providers/BattleMetricsProvider.cs index 13f361a..77b30f2 100644 --- a/DiscordPlayerCountBot/Providers/BattleMetricsProvider.cs +++ b/DiscordPlayerCountBot/Providers/BattleMetricsProvider.cs @@ -21,7 +21,18 @@ public BattleMetricsProvider(BotInformation info) : base(info) HandleLastException(information); - return server.GetViewModel(); + var model = server.GetViewModel(); + + if (!string.IsNullOrEmpty(model.Time) && TimeOnly.TryParse(model.Time, out var time)) + { + if (information.SunriseHour.HasValue && information.SunsetHour.HasValue) + model.SunMoon = time.Hour > information.SunriseHour && time.Hour < information.SunsetHour ? "☀️" : "🌙"; + + if (!information.SunriseHour.HasValue || !information.SunsetHour.HasValue) + model.SunMoon = time.Hour > 6 && time.Hour < 20 ? "☀️" : "🌙"; + } + + return model; } catch (Exception e) { diff --git a/DiscordPlayerCountBot/Providers/SteamProvider.cs b/DiscordPlayerCountBot/Providers/SteamProvider.cs index 69f2f3b..b4e8be2 100644 --- a/DiscordPlayerCountBot/Providers/SteamProvider.cs +++ b/DiscordPlayerCountBot/Providers/SteamProvider.cs @@ -21,7 +21,7 @@ public SteamProvider(BotInformation info) : base(info) HandleLastException(information); - return new SteamViewModel() + var model = new SteamViewModel() { Address = addressAndPort.Item1, Port = addressAndPort.Item2, @@ -31,6 +31,26 @@ public SteamProvider(BotInformation info) : base(info) Gametype = response.gametype, Map = response.map }; + + var serverTime = model.Gametype.Split(",") + .Where(entry => entry.Contains(':') && entry.Length == 5) + .FirstOrDefault(); + + if (!string.IsNullOrEmpty(serverTime)) + { + if (TimeOnly.TryParse(serverTime, out var time)) + { + if (information.SunriseHour.HasValue && information.SunsetHour.HasValue) + model.SunMoon = time.Hour > information.SunriseHour && time.Hour < information.SunsetHour ? "☀️" : "🌙"; + + if (!information.SunriseHour.HasValue || !information.SunsetHour.HasValue) + model.SunMoon = time.Hour > 6 && time.Hour < 20 ? "☀️" : "🌙"; + + model.Time = serverTime; + } + } + + return model; } catch (Exception e) { diff --git a/DiscordPlayerCountBot/ViewModels/BattleMetrics/BattleMetricsViewModel.cs b/DiscordPlayerCountBot/ViewModels/BattleMetrics/BattleMetricsViewModel.cs index 8745aa8..61a3d86 100644 --- a/DiscordPlayerCountBot/ViewModels/BattleMetrics/BattleMetricsViewModel.cs +++ b/DiscordPlayerCountBot/ViewModels/BattleMetrics/BattleMetricsViewModel.cs @@ -6,5 +6,6 @@ public class BattleMetricsViewModel : BaseViewModel public string Time { get; set; } public string GameMode { get; set; } public int Rank { get; set; } + public string SunMoon { get; set; } } } \ No newline at end of file diff --git a/DiscordPlayerCountBot/ViewModels/Steam/SteamViewModel.cs b/DiscordPlayerCountBot/ViewModels/Steam/SteamViewModel.cs index 4bccadb..4bd8ce2 100644 --- a/DiscordPlayerCountBot/ViewModels/Steam/SteamViewModel.cs +++ b/DiscordPlayerCountBot/ViewModels/Steam/SteamViewModel.cs @@ -4,5 +4,7 @@ public class SteamViewModel : BaseViewModel { public string Map { get; set; } public string Gametype { get; set; } + public string Time { get; set; } + public string SunMoon { get; set; } } } From c0a38223b60c852a737e4ce65f81275dcfd48077 Mon Sep 17 00:00:00 2001 From: Larry Date: Sat, 13 Jan 2024 14:30:55 -0700 Subject: [PATCH 3/4] fix linting error --- DiscordPlayerCountBot/DiscordClient.cs | 8 ++++---- DiscordPlayerCountBot/DiscordPlayerCountBot.csproj | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/DiscordPlayerCountBot/DiscordClient.cs b/DiscordPlayerCountBot/DiscordClient.cs index 58cf4ad..a6034c8 100644 --- a/DiscordPlayerCountBot/DiscordClient.cs +++ b/DiscordPlayerCountBot/DiscordClient.cs @@ -25,10 +25,10 @@ public static async Task SetChannelName(this IDiscordClient socket, ulong? chann if (channel != null) { - if (channel is ITextChannel && channel is not IVoiceChannel) - { - gameStatus = gameStatus.Replace('/', '-').Replace(' ', '-').Replace(':', '-'); - } + if (channel is ITextChannel && channel is not IVoiceChannel) + { + gameStatus = gameStatus.Replace('/', '-').Replace(' ', '-').Replace(':', '-'); + } //Keep in mind there is a massive rate limit on this call that is specific to discord, and not Discord.Net //2x per 10 minutes diff --git a/DiscordPlayerCountBot/DiscordPlayerCountBot.csproj b/DiscordPlayerCountBot/DiscordPlayerCountBot.csproj index bb34664..94d7fda 100644 --- a/DiscordPlayerCountBot/DiscordPlayerCountBot.csproj +++ b/DiscordPlayerCountBot/DiscordPlayerCountBot.csproj @@ -6,6 +6,7 @@ enable enable win-x64 + true From 66da2d3eb1892ff6182e196c744ee4426c1a6fe2 Mon Sep 17 00:00:00 2001 From: Larry Date: Sat, 13 Jan 2024 14:32:49 -0700 Subject: [PATCH 4/4] fix lint --- DiscordPlayerCountBot/DiscordClient.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/DiscordPlayerCountBot/DiscordClient.cs b/DiscordPlayerCountBot/DiscordClient.cs index a6034c8..a909922 100644 --- a/DiscordPlayerCountBot/DiscordClient.cs +++ b/DiscordPlayerCountBot/DiscordClient.cs @@ -23,17 +23,20 @@ public static async Task SetChannelName(this IDiscordClient socket, ulong? chann throw new ArgumentException($"[Bot] - Invalid Channel Id: {channelId}, Channel was not found."); } + /* + * Keep in mind there is a massive rate limit on this call that is specific to discord, and not Discord.Net + * 2x per 10 minutes + * https://discord.com/developers/docs/topics/rate-limits + * https://www.reddit.com/r/Discord_Bots/comments/qzrl5h/channel_name_edit_rate_limit/ + */ + if (channel != null) { - if (channel is ITextChannel && channel is not IVoiceChannel) - { - gameStatus = gameStatus.Replace('/', '-').Replace(' ', '-').Replace(':', '-'); - } + if (channel is ITextChannel && channel is not IVoiceChannel) + { + gameStatus = gameStatus.Replace('/', '-').Replace(' ', '-').Replace(':', '-'); + } - //Keep in mind there is a massive rate limit on this call that is specific to discord, and not Discord.Net - //2x per 10 minutes - //https://discord.com/developers/docs/topics/rate-limits - //https://www.reddit.com/r/Discord_Bots/comments/qzrl5h/channel_name_edit_rate_limit/ await channel.ModifyAsync(prop => prop.Name = gameStatus); } }