Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sunmoon tags time tags #65

Merged
merged 4 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DiscordPlayerCountBot/Bot/BotInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ushort> GetAddressAndPort()
{
Expand Down
19 changes: 11 additions & 8 deletions DiscordPlayerCountBot/DiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
1 change: 1 addition & 0 deletions DiscordPlayerCountBot/DiscordPlayerCountBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath></OutputPath>
Expand Down
13 changes: 12 additions & 1 deletion DiscordPlayerCountBot/Providers/BattleMetricsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
22 changes: 21 additions & 1 deletion DiscordPlayerCountBot/Providers/SteamProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
3 changes: 2 additions & 1 deletion DiscordPlayerCountBot/ViewModels/Steam/SteamViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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; }
}
}
Loading