cs-codex-dist-tests/Tools/BiblioTech/Commands/SprCommand.cs

49 lines
1.3 KiB
C#
Raw Normal View History

2023-11-02 11:30:48 +00:00
using BiblioTech.Options;
namespace BiblioTech.Commands
{
public class SprCommand : BaseCommand
2023-11-02 11:30:48 +00:00
{
private readonly Random random = new Random();
private readonly List<string> knownSprs = new List<string>();
2023-11-02 11:30:48 +00:00
public override string Name => "boot";
public override string StartingMessage => RandomBusyMessage.Get();
public override string Description => "Gets an SPR. (Signed peer record, used for bootstrapping.)";
protected override async Task Invoke(CommandContext context)
2023-11-02 11:30:48 +00:00
{
await ReplyWithRandomSpr(context);
}
public void Add(string spr)
2023-11-02 11:30:48 +00:00
{
if (knownSprs.Contains(spr)) return;
knownSprs.Add(spr);
}
2023-11-02 11:30:48 +00:00
public void Clear()
{
knownSprs.Clear();
}
2023-11-02 11:30:48 +00:00
public string[] Get()
{
return knownSprs.ToArray();
2023-11-02 11:30:48 +00:00
}
private async Task ReplyWithRandomSpr(CommandContext context)
{
if (!knownSprs.Any())
2023-11-02 11:30:48 +00:00
{
await context.Followup("I'm sorry, no SPRs are available... :c");
return;
}
var i = random.Next(0, knownSprs.Count);
var spr = knownSprs[i];
2023-11-08 12:33:48 +00:00
await context.Followup($"Your SPR: `{spr}`");
2023-11-02 11:30:48 +00:00
}
}
}