Added lastactive command to get the last time BossmanJack did something observed by the bot

This commit is contained in:
barelyprofessional
2025-10-04 14:10:25 -05:00
parent a92d1dc3c1
commit ff5484c0c9
4 changed files with 93 additions and 2 deletions

View File

@@ -1,7 +1,11 @@
using System.Reflection;
using System.Text.RegularExpressions;
using Humanizer;
using Humanizer.Localisation;
using KfChatDotNetBot.Extensions;
using KfChatDotNetBot.Models;
using KfChatDotNetBot.Models.DbModels;
using KfChatDotNetBot.Settings;
using KfChatDotNetWsClient.Models.Events;
namespace KfChatDotNetBot.Commands;
@@ -62,4 +66,35 @@ public class GetVersionCommand : ICommand
}
await botInstance.SendChatMessageAsync($"Bot compiled against {version.Split('+')[1]}", true);
}
}
public class GetLastActivity : ICommand
{
public List<Regex> Patterns => [
new Regex("^lastactivity", RegexOptions.IgnoreCase)
];
public string? HelpText => "When was Bossman last active?";
public UserRight RequiredRight => UserRight.Loser;
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
public RateLimitOptionsModel? RateLimitOptions => new RateLimitOptionsModel
{
MaxInvocations = 3,
Window = TimeSpan.FromSeconds(10)
};
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
{
var lastActive = await SettingsProvider.GetValueAsync(BuiltIn.Keys.BossmanLastSighting);
if (lastActive.Value == null)
{
await botInstance.SendChatMessageAsync($"{user.FormatUsername()}, I don't know.", true);
return;
}
var activity = lastActive.JsonDeserialize<LastSightingModel>();
var elapsed = DateTimeOffset.UtcNow - activity!.When;
await botInstance.SendChatMessageAsync(
$"{user.FormatUsername()}, BossmanJack was last seen {elapsed.Humanize(maxUnit: TimeUnit.Day, minUnit: TimeUnit.Second, precision: 2)} {activity.Activity}",
true);
}
}