2023-11-02 11:30:48 +00:00
|
|
|
|
using BiblioTech.Options;
|
|
|
|
|
|
|
|
|
|
namespace BiblioTech.Commands
|
|
|
|
|
{
|
2023-11-21 08:38:58 +00:00
|
|
|
|
public class SprCommand : BaseCommand
|
2023-11-02 11:30:48 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly Random random = new Random();
|
2023-11-21 08:38:58 +00:00
|
|
|
|
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.)";
|
|
|
|
|
|
2023-11-21 08:38:58 +00:00
|
|
|
|
protected override async Task Invoke(CommandContext context)
|
2023-11-02 11:30:48 +00:00
|
|
|
|
{
|
|
|
|
|
await ReplyWithRandomSpr(context);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-21 08:38:58 +00:00
|
|
|
|
public void Add(string spr)
|
2023-11-02 11:30:48 +00:00
|
|
|
|
{
|
2023-11-21 08:38:58 +00:00
|
|
|
|
if (knownSprs.Contains(spr)) return;
|
|
|
|
|
knownSprs.Add(spr);
|
|
|
|
|
}
|
2023-11-02 11:30:48 +00:00
|
|
|
|
|
2023-11-21 08:38:58 +00:00
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
|
|
|
|
knownSprs.Clear();
|
|
|
|
|
}
|
2023-11-02 11:30:48 +00:00
|
|
|
|
|
2023-11-21 08:38:58 +00:00
|
|
|
|
public string[] Get()
|
|
|
|
|
{
|
|
|
|
|
return knownSprs.ToArray();
|
2023-11-02 11:30:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task ReplyWithRandomSpr(CommandContext context)
|
|
|
|
|
{
|
2023-11-21 08:38:58 +00:00
|
|
|
|
if (!knownSprs.Any())
|
2023-11-02 11:30:48 +00:00
|
|
|
|
{
|
|
|
|
|
await context.Followup("I'm sorry, no SPRs are available... :c");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-21 08:38:58 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|