refactor: return CataloggerError as Results instead of throwing in commands
This commit is contained in:
parent
84c3b42874
commit
8a4e3ff184
11 changed files with 57 additions and 36 deletions
|
|
@ -50,15 +50,15 @@ public class ChannelCommandsComponents(
|
|||
public async Task<Result> OnMenuSelectionAsync(IReadOnlyList<string> values)
|
||||
{
|
||||
if (contextInjection.Context is not IInteractionCommandContext ctx)
|
||||
throw new CataloggerError("No context");
|
||||
return CataloggerError.Result("No context");
|
||||
if (!ctx.TryGetUserID(out var userId))
|
||||
throw new CataloggerError("No user ID in context");
|
||||
return CataloggerError.Result("No user ID in context");
|
||||
if (!ctx.Interaction.Message.TryGet(out var msg))
|
||||
throw new CataloggerError("No message ID in context");
|
||||
return CataloggerError.Result("No message ID in context");
|
||||
if (!ctx.TryGetGuildID(out var guildId))
|
||||
throw new CataloggerError("No guild ID in context");
|
||||
return CataloggerError.Result("No guild ID in context");
|
||||
if (!guildCache.TryGet(guildId, out var guild))
|
||||
throw new CataloggerError("Guild not in cache");
|
||||
return CataloggerError.Result("Guild not in cache");
|
||||
var guildChannels = channelCache.GuildChannels(guildId).ToList();
|
||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ public class ChannelCommandsComponents(
|
|||
var state = values[0];
|
||||
|
||||
if (!Enum.TryParse<LogChannelType>(state, out var logChannelType))
|
||||
throw new CataloggerError($"Invalid config-channels state {state}");
|
||||
return CataloggerError.Result($"Invalid config-channels state {state}");
|
||||
|
||||
var channelId = WebhookExecutorService.GetDefaultLogChannel(guildConfig, logChannelType);
|
||||
string? channelMention;
|
||||
|
|
@ -147,15 +147,15 @@ public class ChannelCommandsComponents(
|
|||
public async Task<Result> OnButtonPressedAsync(string state)
|
||||
{
|
||||
if (contextInjection.Context is not IInteractionCommandContext ctx)
|
||||
throw new CataloggerError("No context");
|
||||
return CataloggerError.Result("No context");
|
||||
if (!ctx.TryGetUserID(out var userId))
|
||||
throw new CataloggerError("No user ID in context");
|
||||
return CataloggerError.Result("No user ID in context");
|
||||
if (!ctx.Interaction.Message.TryGet(out var msg))
|
||||
throw new CataloggerError("No message ID in context");
|
||||
return CataloggerError.Result("No message ID in context");
|
||||
if (!ctx.TryGetGuildID(out var guildId))
|
||||
throw new CataloggerError("No guild ID in context");
|
||||
return CataloggerError.Result("No guild ID in context");
|
||||
if (!guildCache.TryGet(guildId, out var guild))
|
||||
throw new CataloggerError("Guild not in cache");
|
||||
return CataloggerError.Result("Guild not in cache");
|
||||
var guildChannels = channelCache.GuildChannels(guildId).ToList();
|
||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||
|
||||
|
|
@ -179,9 +179,9 @@ public class ChannelCommandsComponents(
|
|||
);
|
||||
case "reset":
|
||||
if (lease.Data.CurrentPage == null)
|
||||
throw new CataloggerError("CurrentPage was null in reset button callback");
|
||||
return CataloggerError.Result("CurrentPage was null in reset button callback");
|
||||
if (!Enum.TryParse<LogChannelType>(lease.Data.CurrentPage, out var channelType))
|
||||
throw new CataloggerError(
|
||||
return CataloggerError.Result(
|
||||
$"Invalid config-channels CurrentPage: '{lease.Data.CurrentPage}'"
|
||||
);
|
||||
|
||||
|
|
@ -281,15 +281,15 @@ public class ChannelCommandsComponents(
|
|||
public async Task<Result> OnMenuSelectionAsync(IReadOnlyList<IPartialChannel> channels)
|
||||
{
|
||||
if (contextInjection.Context is not IInteractionCommandContext ctx)
|
||||
throw new CataloggerError("No context");
|
||||
return CataloggerError.Result("No context");
|
||||
if (!ctx.TryGetUserID(out var userId))
|
||||
throw new CataloggerError("No user ID in context");
|
||||
return CataloggerError.Result("No user ID in context");
|
||||
if (!ctx.Interaction.Message.TryGet(out var msg))
|
||||
throw new CataloggerError("No message ID in context");
|
||||
return CataloggerError.Result("No message ID in context");
|
||||
if (!ctx.TryGetGuildID(out var guildId))
|
||||
throw new CataloggerError("No guild ID in context");
|
||||
return CataloggerError.Result("No guild ID in context");
|
||||
if (!guildCache.TryGet(guildId, out var guild))
|
||||
throw new CataloggerError("Guild not in cache");
|
||||
return CataloggerError.Result("Guild not in cache");
|
||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||
var channelId = channels[0].ID.ToUlong();
|
||||
|
||||
|
|
@ -305,7 +305,7 @@ public class ChannelCommandsComponents(
|
|||
}
|
||||
|
||||
if (!Enum.TryParse<LogChannelType>(lease.Data.CurrentPage, out var channelType))
|
||||
throw new CataloggerError(
|
||||
return CataloggerError.Result(
|
||||
$"Invalid config-channels CurrentPage '{lease.Data.CurrentPage}'"
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue