Skip to content

Commit

Permalink
Merge pull request #65 from GravityWolfNotAmused/sunmoon-tags-time-tags
Browse files Browse the repository at this point in the history
Sunmoon tags time tags
  • Loading branch information
GravityWolfNotAmused committed Jan 13, 2024
2 parents 0e1a9da + 66da2d3 commit 88dd8db
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 11 deletions.
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; }
}
}

0 comments on commit 88dd8db

Please sign in to comment.