From 918bd474045e48c8018960e7d7fc925988074a02 Mon Sep 17 00:00:00 2001 From: barelyprofessional <150058423+barelyprofessional@users.noreply.github.com> Date: Sat, 8 Feb 2025 23:37:43 +0800 Subject: [PATCH] Added a command to retrieve the last stream time based on the Twitch view logging --- KfChatDotNetBot/Commands/MemeCommands.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/KfChatDotNetBot/Commands/MemeCommands.cs b/KfChatDotNetBot/Commands/MemeCommands.cs index 0de8574..1b1e34e 100644 --- a/KfChatDotNetBot/Commands/MemeCommands.cs +++ b/KfChatDotNetBot/Commands/MemeCommands.cs @@ -331,4 +331,28 @@ public class BassmanJack : ICommand // ReSharper disable once StringLiteralTypo await botInstance.SendChatMessageAsync("[img]https://i.postimg.cc/SRstzMQt/boss-soy-koi.gif[/img]", true); } +} + +public class LastStreamCommand : ICommand +{ + public List Patterns => [new Regex("^laststream")]; + public string? HelpText => "How long ago did Austin Gambles last stream (on Twitch)?"; + public UserRight RequiredRight => UserRight.Guest; + public TimeSpan Timeout => TimeSpan.FromSeconds(10); + public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx) + { + await using var db = new ApplicationDbContext(); + var latest = db.TwitchViewCounts.OrderByDescending(x => x.Id).FirstOrDefault(); + if (latest == null) + { + await botInstance.SendChatMessageAsync("The Twitch view counts table is empty", true); + return; + } + + var timespan = DateTimeOffset.UtcNow - latest.Time; + var agt = TimeZoneInfo.ConvertTime(latest.Time, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")); + // The table doesn't contain the name of the person so we'll just have to assume it's his Twitch username + var username = await Helpers.GetValue(BuiltIn.Keys.TwitchBossmanJackUsername); + await botInstance.SendChatMessageAsync($"{username.Value} last streamed on Twitch approximately {timespan.Humanize(precision: 2, minUnit: TimeUnit.Minute, maxUnit: TimeUnit.Hour)} ago at {agt:dddd h:mm tt} AGT", true); + } } \ No newline at end of file