Ephemeral messages.

This commit is contained in:
benbierens 2023-10-25 10:54:26 +02:00
parent f148598a21
commit bd9fc3a3cf
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
10 changed files with 40 additions and 30 deletions

View File

@ -22,12 +22,13 @@ namespace BiblioTech
try
{
await command.RespondAsync(StartingMessage);
await command.RespondAsync(StartingMessage, ephemeral: true);
await Invoke(new CommandContext(command, command.Data.Options));
await command.DeleteOriginalResponseAsync();
}
catch (Exception ex)
{
await command.FollowupAsync("Something failed while trying to do that...");
await command.FollowupAsync("Something failed while trying to do that...", ephemeral: true);
Console.WriteLine(ex);
}
}

View File

@ -21,12 +21,12 @@ namespace BiblioTech
var deployments = monitor.GetDeployments();
if (deployments.Length == 0)
{
await context.Command.FollowupAsync("No deployments are currently available.");
await context.Followup("No deployments are currently available.");
return;
}
if (deployments.Length > 1)
{
await context.Command.FollowupAsync("Multiple deployments are online. I don't know which one to pick!");
await context.Followup("Multiple deployments are online. I don't know which one to pick!");
return;
}

View File

@ -1,6 +1,5 @@
using BiblioTech.Options;
using CodexPlugin;
using Discord.WebSocket;
namespace BiblioTech.Commands
{
@ -38,13 +37,13 @@ namespace BiblioTech.Commands
{
if (!IsSenderAdmin(context.Command))
{
await context.Command.FollowupAsync("You're not an admin.");
await context.Followup("You're not an admin.");
return;
}
if (!IsInAdminChannel(context.Command))
{
await context.Command.FollowupAsync("Please use admin commands only in the admin channel.");
await context.Followup("Please use admin commands only in the admin channel.");
return;
}
@ -71,12 +70,12 @@ namespace BiblioTech.Commands
var userId = user.GetOptionUserId(context);
if (userId == null)
{
await context.Command.FollowupAsync("Failed to get user ID");
await context.AdminFollowup("Failed to get user ID");
return;
}
Program.UserRepo.ClearUserAssociatedAddress(userId.Value);
await context.Command.FollowupAsync("Done.");
await context.AdminFollowup("Done.");
}
}
@ -98,12 +97,12 @@ namespace BiblioTech.Commands
var userId = user.GetOptionUserId(context);
if (userId == null)
{
await context.Command.FollowupAsync("Failed to get user ID");
await context.AdminFollowup("Failed to get user ID");
return;
}
var report = Program.UserRepo.GetInteractionReport(userId.Value);
await context.Command.FollowupAsync(string.Join(Environment.NewLine, report));
await context.AdminFollowup(string.Join(Environment.NewLine, report));
}
}
@ -123,11 +122,11 @@ namespace BiblioTech.Commands
if (!deployments.Any())
{
await context.Command.FollowupAsync("No deployments available.");
await context.AdminFollowup("No deployments available.");
return;
}
await context.Command.FollowupAsync($"Deployments: {string.Join(", ", deployments.Select(FormatDeployment))}");
await context.AdminFollowup($"Deployments: {string.Join(", ", deployments.Select(FormatDeployment))}");
}
private string FormatDeployment(CodexDeployment deployment)
@ -161,11 +160,11 @@ namespace BiblioTech.Commands
var result = await monitor.DownloadDeployment(file);
if (result)
{
await context.Command.FollowupAsync("Success!");
await context.AdminFollowup("Success!");
}
else
{
await context.Command.FollowupAsync("That didn't work.");
await context.AdminFollowup("That didn't work.");
}
}
}
@ -194,11 +193,11 @@ namespace BiblioTech.Commands
var result = monitor.DeleteDeployment(str);
if (result)
{
await context.Command.FollowupAsync("Success!");
await context.AdminFollowup("Success!");
}
else
{
await context.Command.FollowupAsync("That didn't work.");
await context.AdminFollowup("That didn't work.");
}
}
}

View File

@ -29,14 +29,14 @@ namespace BiblioTech.Commands
var addr = Program.UserRepo.GetCurrentAddressForUser(userId);
if (addr == null)
{
await context.Command.FollowupAsync($"No address has been set for this user. Please use '/{userAssociateCommand.Name}' to set it first.");
await context.Followup($"No address has been set for this user. Please use '/{userAssociateCommand.Name}' to set it first.");
return;
}
var eth = gethNode.GetEthBalance(addr);
var testTokens = contracts.GetTestTokenBalance(gethNode, addr);
await context.Command.FollowupAsync($"{context.Command.User.Username} has {eth} and {testTokens}.");
await context.Followup($"{context.Command.User.Username} has {eth} and {testTokens}.");
}
}
}

View File

@ -31,7 +31,7 @@ namespace BiblioTech.Commands
var addr = Program.UserRepo.GetCurrentAddressForUser(userId);
if (addr == null)
{
await context.Command.FollowupAsync($"No address has been set for this user. Please use '/{userAssociateCommand.Name}' to set it first.");
await context.Followup($"No address has been set for this user. Please use '/{userAssociateCommand.Name}' to set it first.");
return;
}
@ -42,7 +42,7 @@ namespace BiblioTech.Commands
Program.UserRepo.AddMintEventForUser(userId, addr, sentEth, mintedTokens);
await context.Command.FollowupAsync(string.Join(Environment.NewLine, report));
await context.Followup(string.Join(Environment.NewLine, report));
}
private TestToken ProcessTokens(IGethNode gethNode, ICodexContracts contracts, EthAddress addr, List<string> report)

View File

@ -23,7 +23,7 @@ namespace BiblioTech.Commands
var currentAddress = Program.UserRepo.GetCurrentAddressForUser(userId);
if (currentAddress != null && !IsSenderAdmin(context.Command))
{
await context.Command.FollowupAsync($"You've already set your Ethereum address to {currentAddress}.");
await context.Followup($"You've already set your Ethereum address to {currentAddress}.");
return;
}
@ -32,11 +32,11 @@ namespace BiblioTech.Commands
var result = Program.UserRepo.AssociateUserWithAddress(userId, data);
if (result)
{
await context.Command.FollowupAsync("Done! Thank you for joining the test net!");
await context.Followup("Done! Thank you for joining the test net!");
}
else
{
await context.Command.FollowupAsync("That didn't work.");
await context.Followup("That didn't work.");
}
}
}

View File

@ -12,5 +12,15 @@ namespace BiblioTech.Options
public SocketSlashCommand Command { get; }
public IReadOnlyCollection<SocketSlashCommandDataOption> Options { get; }
public async Task Followup(string message)
{
await Command.FollowupAsync(message, ephemeral: true);
}
public async Task AdminFollowup(string message)
{
await Command.FollowupAsync(message);
}
}
}

View File

@ -18,13 +18,13 @@ namespace BiblioTech.Options
var ethOptionData = context.Options.SingleOrDefault(o => o.Name == Name);
if (ethOptionData == null)
{
await context.Command.FollowupAsync("EthAddress option not received.");
await context.Followup("EthAddress option not received.");
return null;
}
var ethAddressStr = ethOptionData.Value as string;
if (string.IsNullOrEmpty(ethAddressStr))
{
await context.Command.FollowupAsync("EthAddress is null or empty.");
await context.Followup("EthAddress is null or empty.");
return null;
}
@ -32,7 +32,7 @@ namespace BiblioTech.Options
!AddressUtil.Current.IsValidEthereumAddressHexFormat(ethAddressStr))
// !AddressUtil.Current.IsChecksumAddress(ethAddressStr)) - this might make a good option later, but for now it might just annoy users.
{
await context.Command.FollowupAsync("EthAddress is not valid.");
await context.Followup("EthAddress is not valid.");
return null;
}

View File

@ -14,13 +14,13 @@ namespace BiblioTech.Options
var fileOptionData = context.Options.SingleOrDefault(o => o.Name == Name);
if (fileOptionData == null)
{
await context.Command.FollowupAsync("Attachement option not received.");
await context.Followup("Attachement option not received.");
return null;
}
var attachement = fileOptionData.Value as IAttachment;
if (attachement == null)
{
await context.Command.FollowupAsync("Attachement is null or empty.");
await context.Followup("Attachement is null or empty.");
return null;
}

View File

@ -14,7 +14,7 @@ namespace BiblioTech.Options
var strData = context.Options.SingleOrDefault(o => o.Name == Name);
if (strData == null)
{
await context.Command.FollowupAsync("String option not received.");
await context.Followup("String option not received.");
return null;
}
return strData.Value as string;