mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Added lastactive command to get the last time BossmanJack did something observed by the bot
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user