2025-04-11 15:19:03 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using BiblioTech.CodexChecking;
|
2025-04-10 14:54:49 +02:00
|
|
|
|
using BiblioTech.Options;
|
|
|
|
|
|
using Discord;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BiblioTech.Commands
|
|
|
|
|
|
{
|
|
|
|
|
|
public class CheckResponseHandler : ICheckResponseHandler
|
|
|
|
|
|
{
|
|
|
|
|
|
private CommandContext context;
|
|
|
|
|
|
private readonly IUser user;
|
|
|
|
|
|
|
|
|
|
|
|
public CheckResponseHandler(CommandContext context, IUser user)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.context = context;
|
|
|
|
|
|
this.user = user;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task CheckNotStarted()
|
|
|
|
|
|
{
|
|
|
|
|
|
await context.Followup("Run this command without any arguments first, to begin the check process.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task CouldNotDownloadCid()
|
|
|
|
|
|
{
|
|
|
|
|
|
await context.Followup("Could not download the CID.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task GiveCidToUser(string cid)
|
|
|
|
|
|
{
|
2025-04-11 15:19:03 +02:00
|
|
|
|
await context.Followup(
|
|
|
|
|
|
FormatCatchyMessage("[💾] Please download this CID using your Codex node.",
|
|
|
|
|
|
$"👉 `{cid}`.",
|
|
|
|
|
|
"👉 Then provide the *content of the downloaded file* as argument to this command."));
|
2025-04-10 14:54:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task GiveDataFileToUser(string fileContent)
|
|
|
|
|
|
{
|
2025-04-11 15:19:03 +02:00
|
|
|
|
await context.SendFile(fileContent,
|
|
|
|
|
|
FormatCatchyMessage("[💿] Please download the attached file.",
|
|
|
|
|
|
"👉 Upload it to your Codex node.",
|
|
|
|
|
|
"👉 Then provide the *CID* as argument to this command."));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string FormatCatchyMessage(string title, params string[] content)
|
|
|
|
|
|
{
|
|
|
|
|
|
var entries = new List<string>();
|
|
|
|
|
|
entries.Add(title);
|
|
|
|
|
|
entries.Add("```");
|
|
|
|
|
|
entries.AddRange(content);
|
|
|
|
|
|
entries.Add("```");
|
|
|
|
|
|
return string.Join(Environment.NewLine, entries.ToArray());
|
2025-04-10 14:54:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task GiveRoleReward()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2025-04-16 15:17:40 +02:00
|
|
|
|
await Program.RoleDriver.RunRoleGiver(async r =>
|
|
|
|
|
|
{
|
2025-04-17 09:35:13 +02:00
|
|
|
|
await r.GiveAltruisticRole(user.Id);
|
|
|
|
|
|
await r.GiveActiveP2pParticipant(user.Id);
|
2025-04-16 15:17:40 +02:00
|
|
|
|
});
|
2025-04-10 14:54:49 +02:00
|
|
|
|
await context.Followup($"Congratulations! You've been granted the Altruistic Mode role!");
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
await Program.AdminChecker.SendInAdminChannel($"Failed to grant Altruistic Mode role to user <@{user.Id}>: {ex.Message}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task InvalidData()
|
|
|
|
|
|
{
|
|
|
|
|
|
await context.Followup("The received data didn't match. Check has failed.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-23 09:04:23 +02:00
|
|
|
|
public async Task NowCompleted(string checkName)
|
2025-04-10 14:54:49 +02:00
|
|
|
|
{
|
2025-04-23 09:04:23 +02:00
|
|
|
|
// check if eth address is known for user.
|
|
|
|
|
|
var data = Program.UserRepo.GetUser(user);
|
|
|
|
|
|
if (data.CurrentAddress == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
await context.Followup($"Successfully completed the check!{Environment.NewLine}" +
|
|
|
|
|
|
$"You haven't yet set your ethereum address. Consider using '/set' to set it.{Environment.NewLine}" +
|
|
|
|
|
|
$"(You can find your address in the 'eth.address' file of your Codex node.)");
|
|
|
|
|
|
|
|
|
|
|
|
await Program.AdminChecker.SendInAdminChannel($"User <@{user.Id}> has completed check: {checkName}" +
|
|
|
|
|
|
$" - EthAddress not set for user. User was reminded.");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
await context.Followup("Successfully completed the check!");
|
|
|
|
|
|
await Program.AdminChecker.SendInAdminChannel($"User <@{user.Id}> has completed check: {checkName}");
|
|
|
|
|
|
}
|
2025-04-10 14:54:49 +02:00
|
|
|
|
}
|
2025-04-11 08:32:18 +02:00
|
|
|
|
|
|
|
|
|
|
public async Task ToAdminChannel(string msg)
|
|
|
|
|
|
{
|
|
|
|
|
|
await Program.AdminChecker.SendInAdminChannel(msg);
|
|
|
|
|
|
}
|
2025-04-10 14:54:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|