diff --git a/locale/Messages.resx b/locale/Messages.resx index dc84b10..a9367f7 100644 --- a/locale/Messages.resx +++ b/locale/Messages.resx @@ -477,8 +477,8 @@ Position in list: {0} - - The reminder will be sent on: {0} + + Reminder send time: {0} Reminder text: {0} @@ -576,6 +576,9 @@ This will lead to unexpected behavior. Data will no longer be saved + + An error occurred during command execution, try again later. + Contact the developers if the problem occurs again. diff --git a/locale/Messages.ru.resx b/locale/Messages.ru.resx index e7c724e..d0cbd79 100644 --- a/locale/Messages.ru.resx +++ b/locale/Messages.ru.resx @@ -477,8 +477,8 @@ Позиция в списке: {0} - - Напоминание будет отправлено: {0} + + Время отправки напоминания: {0} Текст напоминания: {0} @@ -576,6 +576,9 @@ Это может привести к неожиданному поведению. Данные больше не будут сохраняться. + + Произошла ошибка при выполнении команды, повтори попытку позже. + Обратись к разработчикам, если проблема возникнет снова. diff --git a/locale/Messages.tt-ru.resx b/locale/Messages.tt-ru.resx index d0a10be..3bed232 100644 --- a/locale/Messages.tt-ru.resx +++ b/locale/Messages.tt-ru.resx @@ -477,8 +477,8 @@ номер в списке: {0} - - я пну тебе это: {0} + + время отправки: {0} че там в напоминалке: {0} @@ -576,6 +576,9 @@ возможно всё съедет с крыши, но знай, что я больше ничё не сохраню. + + произошёл тотальный разнос в команде, удачи. + если ты это читаешь второй раз за сегодня, пиши разрабам diff --git a/src/Commands/Events/ErrorLoggingPostExecutionEvent.cs b/src/Commands/Events/ErrorLoggingPostExecutionEvent.cs index d6a66cc..a6daaf0 100644 --- a/src/Commands/Events/ErrorLoggingPostExecutionEvent.cs +++ b/src/Commands/Events/ErrorLoggingPostExecutionEvent.cs @@ -1,8 +1,12 @@ using JetBrains.Annotations; using Microsoft.Extensions.Logging; using Octobot.Extensions; +using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.Commands.Contexts; +using Remora.Discord.Commands.Feedback.Services; using Remora.Discord.Commands.Services; +using Remora.Discord.Extensions.Embeds; +using Remora.Discord.Extensions.Formatting; using Remora.Results; namespace Octobot.Commands.Events; @@ -14,10 +18,15 @@ namespace Octobot.Commands.Events; public class ErrorLoggingPostExecutionEvent : IPostExecutionEvent { private readonly ILogger _logger; + private readonly FeedbackService _feedback; + private readonly IDiscordRestUserAPI _userApi; - public ErrorLoggingPostExecutionEvent(ILogger logger) + public ErrorLoggingPostExecutionEvent(ILogger logger, FeedbackService feedback, + IDiscordRestUserAPI userApi) { _logger = logger; + _feedback = feedback; + _userApi = userApi; } /// @@ -28,11 +37,34 @@ public class ErrorLoggingPostExecutionEvent : IPostExecutionEvent /// The result whose success is checked. /// The cancellation token for this operation. Unused. /// A result which has succeeded. - public Task AfterExecutionAsync( + public async Task AfterExecutionAsync( ICommandContext context, IResult commandResult, CancellationToken ct = default) { _logger.LogResult(commandResult, $"Error in slash command execution for /{context.Command.Command.Node.Key}."); - return Task.FromResult(Result.FromSuccess()); + var result = commandResult; + while (result.Inner is not null) + { + result = result.Inner; + } + + if (result.IsSuccess) + { + return Result.FromSuccess(); + } + + var botResult = await _userApi.GetCurrentUserAsync(ct); + if (!botResult.IsDefined(out var bot)) + { + return Result.FromError(botResult); + } + + var embed = new EmbedBuilder().WithSmallTitle(Messages.CommandExecutionFailed, bot) + .WithDescription(Markdown.InlineCode(result.Error.Message)) + .WithFooter(Messages.ContactDevelopers) + .WithColour(ColorsList.Red) + .Build(); + + return await _feedback.SendContextualEmbedResultAsync(embed, ct); } } diff --git a/src/Commands/RemindCommandGroup.cs b/src/Commands/RemindCommandGroup.cs index 4a4f6a1..eb46d7c 100644 --- a/src/Commands/RemindCommandGroup.cs +++ b/src/Commands/RemindCommandGroup.cs @@ -92,7 +92,7 @@ public class RemindCommandGroup : CommandGroup builder.Append("- ").AppendLine(string.Format(Messages.ReminderPosition, Markdown.InlineCode((i + 1).ToString()))) .Append(" - ").AppendLine(string.Format(Messages.ReminderText, Markdown.InlineCode(reminder.Text))) .Append(" - ") - .AppendLine(string.Format(Messages.ReminderWillBeSentOn, Markdown.Timestamp(reminder.At))); + .AppendLine(string.Format(Messages.ReminderTime, Markdown.Timestamp(reminder.At))); } var embed = new EmbedBuilder().WithSmallTitle( @@ -155,7 +155,7 @@ public class RemindCommandGroup : CommandGroup var builder = new StringBuilder().Append("- ").AppendLine(string.Format( Messages.ReminderText, Markdown.InlineCode(text))) - .Append("- ").Append(string.Format(Messages.ReminderWillBeSentOn, Markdown.Timestamp(remindAt))); + .Append("- ").Append(string.Format(Messages.ReminderTime, Markdown.Timestamp(remindAt))); var embed = new EmbedBuilder().WithSmallTitle( string.Format(Messages.ReminderCreated, executor.GetTag()), executor) @@ -210,9 +210,16 @@ public class RemindCommandGroup : CommandGroup return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct); } + var reminder = data.Reminders[index]; + + var description = new StringBuilder() + .Append("- ").AppendLine(string.Format(Messages.ReminderText, Markdown.InlineCode(reminder.Text))) + .Append("- ").AppendLine(string.Format(Messages.ReminderTime, Markdown.Timestamp(reminder.At))); + data.Reminders.RemoveAt(index); var embed = new EmbedBuilder().WithSmallTitle(Messages.ReminderDeleted, bot) + .WithDescription(description.ToString()) .WithColour(ColorsList.Green) .Build(); diff --git a/src/Extensions/LoggerExtensions.cs b/src/Extensions/LoggerExtensions.cs index fd4aeb7..3805cea 100644 --- a/src/Extensions/LoggerExtensions.cs +++ b/src/Extensions/LoggerExtensions.cs @@ -26,6 +26,11 @@ public static class LoggerExtensions if (result.Error is ExceptionError exe) { + if (exe.Exception is TaskCanceledException) + { + return; + } + logger.LogError(exe.Exception, "{ErrorMessage}", message); return; } diff --git a/src/Messages.Designer.cs b/src/Messages.Designer.cs index 1693bb1..e2184d7 100644 --- a/src/Messages.Designer.cs +++ b/src/Messages.Designer.cs @@ -786,9 +786,9 @@ namespace Octobot { } } - internal static string ReminderWillBeSentOn { + internal static string ReminderTime { get { - return ResourceManager.GetString("ReminderWillBeSentOn", resourceCulture); + return ResourceManager.GetString("ReminderTime", resourceCulture); } } @@ -1012,6 +1012,15 @@ namespace Octobot { return ResourceManager.GetString("DataLoadFailedDescription", resourceCulture); } } + + internal static string CommandExecutionFailed + { + get + { + return ResourceManager.GetString("CommandExecutionFailed", resourceCulture); + } + } + internal static string ContactDevelopers { get