add try catch failure response handling
This commit is contained in:
@@ -46,6 +46,8 @@ public class MareModule : InteractionModuleBase
|
||||
|
||||
[SlashCommand("register", "Starts the registration process for the Mare Synchronos server of this Discord")]
|
||||
public async Task Register([Summary("overwrite", "Overwrites your old account")] bool overwrite = false)
|
||||
{
|
||||
await TryRespondAsync(async () =>
|
||||
{
|
||||
if (overwrite)
|
||||
{
|
||||
@@ -53,32 +55,41 @@ public class MareModule : InteractionModuleBase
|
||||
}
|
||||
|
||||
await RespondWithModalAsync<LodestoneModal>("register_modal").ConfigureAwait(false);
|
||||
});
|
||||
}
|
||||
|
||||
[SlashCommand("setvanityuid", "Sets your Vanity UID.")]
|
||||
public async Task SetVanityUid([Summary("vanity_uid", "Desired Vanity UID")] string vanityUid)
|
||||
{
|
||||
await TryRespondAsync(async () =>
|
||||
{
|
||||
EmbedBuilder eb = new();
|
||||
|
||||
eb = await HandleVanityUid(eb, Context.User.Id, vanityUid);
|
||||
|
||||
await RespondAsync(embeds: new[] { eb.Build() }, ephemeral: true).ConfigureAwait(false);
|
||||
});
|
||||
}
|
||||
|
||||
[SlashCommand("setsyncshellvanityid", "Sets a Vanity GID for a Syncshell")]
|
||||
public async Task SetSyncshellVanityId(
|
||||
[Summary("syncshell_id", "Syncshell ID")] string syncshellId,
|
||||
[Summary("vanity_syncshell_id", "Desired Vanity Syncshell ID")] string vanityId)
|
||||
{
|
||||
await TryRespondAsync(async () =>
|
||||
{
|
||||
EmbedBuilder eb = new();
|
||||
|
||||
eb = await HandleVanityGid(eb, Context.User.Id, syncshellId, vanityId);
|
||||
|
||||
await RespondAsync(embeds: new[] { eb.Build() }, ephemeral: true).ConfigureAwait(false);
|
||||
});
|
||||
}
|
||||
|
||||
[SlashCommand("verify", "Finishes the registration process for the Mare Synchronos server of this Discord")]
|
||||
public async Task Verify()
|
||||
{
|
||||
await TryRespondAsync(async () =>
|
||||
{
|
||||
EmbedBuilder eb = new();
|
||||
if (_botServices.verificationQueue.Any(u => u.Key == Context.User.Id))
|
||||
@@ -98,10 +109,13 @@ public class MareModule : InteractionModuleBase
|
||||
await DeferAsync(ephemeral: true).ConfigureAwait(false);
|
||||
_botServices.verificationQueue.Enqueue(new KeyValuePair<ulong, Action<IServiceProvider>>(Context.User.Id, async (sp) => await HandleVerifyAsync((SocketSlashCommand)Context.Interaction, sp)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[SlashCommand("verify_relink", "Finishes the relink process for your user on the Mare Synchronos server of this Discord")]
|
||||
public async Task VerifyRelink()
|
||||
{
|
||||
await TryRespondAsync(async () =>
|
||||
{
|
||||
EmbedBuilder eb = new();
|
||||
if (_botServices.verificationQueue.Any(u => u.Key == Context.User.Id))
|
||||
@@ -121,6 +135,7 @@ public class MareModule : InteractionModuleBase
|
||||
await DeferAsync(ephemeral: true).ConfigureAwait(false);
|
||||
_botServices.verificationQueue.Enqueue(new KeyValuePair<ulong, Action<IServiceProvider>>(Context.User.Id, async (sp) => await HandleVerifyRelinkAsync((SocketSlashCommand)Context.Interaction, sp)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[SlashCommand("recover", "Allows you to recover your account by generating a new secret key")]
|
||||
@@ -133,12 +148,15 @@ public class MareModule : InteractionModuleBase
|
||||
public async Task UserInfo(
|
||||
[Summary("discord_user", "ADMIN ONLY: Discord User to check for")] IUser? discordUser = null,
|
||||
[Summary("uid", "ADMIN ONLY: UID to check for")] string? uid = null)
|
||||
{
|
||||
await TryRespondAsync(async () =>
|
||||
{
|
||||
EmbedBuilder eb = new();
|
||||
|
||||
eb = await HandleUserInfo(eb, Context.User.Id, discordUser?.Id ?? null, uid);
|
||||
|
||||
await RespondAsync(embeds: new[] { eb.Build() }, ephemeral: true).ConfigureAwait(false);
|
||||
});
|
||||
}
|
||||
|
||||
[SlashCommand("relink", "Allows you to link a new Discord account to an existing Mare account")]
|
||||
@@ -149,23 +167,48 @@ public class MareModule : InteractionModuleBase
|
||||
|
||||
[ModalInteraction("recover_modal")]
|
||||
public async Task RecoverModal(LodestoneModal modal)
|
||||
{
|
||||
await TryRespondAsync(async () =>
|
||||
{
|
||||
var embed = await HandleRecoverModalAsync(modal, Context.User.Id).ConfigureAwait(false);
|
||||
await RespondAsync(embeds: new Embed[] { embed }, ephemeral: true).ConfigureAwait(false);
|
||||
});
|
||||
}
|
||||
|
||||
[ModalInteraction("register_modal")]
|
||||
public async Task RegisterModal(LodestoneModal modal)
|
||||
{
|
||||
await TryRespondAsync(async () =>
|
||||
{
|
||||
var embed = await HandleRegisterModalAsync(modal, Context.User.Id).ConfigureAwait(false);
|
||||
await RespondAsync(embeds: new Embed[] { embed }, ephemeral: true).ConfigureAwait(false);
|
||||
});
|
||||
}
|
||||
|
||||
[ModalInteraction("relink_modal")]
|
||||
public async Task RelinkModal(LodestoneModal modal)
|
||||
{
|
||||
await TryRespondAsync(async () =>
|
||||
{
|
||||
var embed = await HandleRelinkModalAsync(modal, Context.User.Id).ConfigureAwait(false);
|
||||
await RespondAsync(embeds: new Embed[] { embed }, ephemeral: true).ConfigureAwait(false);
|
||||
});
|
||||
}
|
||||
|
||||
private async Task TryRespondAsync(Action act)
|
||||
{
|
||||
try
|
||||
{
|
||||
act();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
EmbedBuilder eb = new();
|
||||
eb.WithTitle("An error occured");
|
||||
eb.WithDescription("Please report this error to bug-reports: " + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine);
|
||||
|
||||
await RespondAsync(embeds: new Embed[] { eb.Build() }, ephemeral: true).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<EmbedBuilder> HandleUserInfo(EmbedBuilder eb, ulong id, ulong? optionalUser = null, string? uid = null)
|
||||
|
||||
Reference in New Issue
Block a user