1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-05-13 17:26:08 +03:00

Merge branch 'master' into guild-data-load-errors

Signed-off-by: Macintosh II <95250141+mctaylors@users.noreply.github.com>
This commit is contained in:
Macintxsh 2023-10-26 18:12:25 +03:00 committed by GitHub
commit 29a3c863f8
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 75 additions and 13 deletions

View file

@ -477,8 +477,8 @@
<data name="ReminderPosition" xml:space="preserve"> <data name="ReminderPosition" xml:space="preserve">
<value>Position in list: {0}</value> <value>Position in list: {0}</value>
</data> </data>
<data name="ReminderWillBeSentOn" xml:space="preserve"> <data name="ReminderTime" xml:space="preserve">
<value>The reminder will be sent on: {0}</value> <value>Reminder send time: {0}</value>
</data> </data>
<data name="ReminderText" xml:space="preserve"> <data name="ReminderText" xml:space="preserve">
<value>Reminder text: {0}</value> <value>Reminder text: {0}</value>
@ -576,6 +576,9 @@
<data name="DataLoadFailedDescription" xml:space="preserve"> <data name="DataLoadFailedDescription" xml:space="preserve">
<value>This will lead to unexpected behavior. Data will no longer be saved</value> <value>This will lead to unexpected behavior. Data will no longer be saved</value>
</data> </data>
<data name="CommandExecutionFailed" xml:space="preserve">
<value>An error occurred during command execution, try again later.</value>
</data>
<data name="ContactDevelopers" xml:space="preserve"> <data name="ContactDevelopers" xml:space="preserve">
<value>Contact the developers if the problem occurs again.</value> <value>Contact the developers if the problem occurs again.</value>
</data> </data>

View file

@ -477,8 +477,8 @@
<data name="ReminderPosition" xml:space="preserve"> <data name="ReminderPosition" xml:space="preserve">
<value>Позиция в списке: {0}</value> <value>Позиция в списке: {0}</value>
</data> </data>
<data name="ReminderWillBeSentOn" xml:space="preserve"> <data name="ReminderTime" xml:space="preserve">
<value>Напоминание будет отправлено: {0}</value> <value>Время отправки напоминания: {0}</value>
</data> </data>
<data name="ReminderText" xml:space="preserve"> <data name="ReminderText" xml:space="preserve">
<value>Текст напоминания: {0}</value> <value>Текст напоминания: {0}</value>
@ -576,6 +576,9 @@
<data name="DataLoadFailedDescription" xml:space="preserve"> <data name="DataLoadFailedDescription" xml:space="preserve">
<value>Это может привести к неожиданному поведению. Данные больше не будут сохраняться.</value> <value>Это может привести к неожиданному поведению. Данные больше не будут сохраняться.</value>
</data> </data>
<data name="CommandExecutionFailed" xml:space="preserve">
<value>Произошла ошибка при выполнении команды, повтори попытку позже.</value>
</data>
<data name="ContactDevelopers" xml:space="preserve"> <data name="ContactDevelopers" xml:space="preserve">
<value>Обратись к разработчикам, если проблема возникнет снова.</value> <value>Обратись к разработчикам, если проблема возникнет снова.</value>
</data> </data>

View file

@ -477,8 +477,8 @@
<data name="ReminderPosition" xml:space="preserve"> <data name="ReminderPosition" xml:space="preserve">
<value>номер в списке: {0}</value> <value>номер в списке: {0}</value>
</data> </data>
<data name="ReminderWillBeSentOn" xml:space="preserve"> <data name="ReminderTime" xml:space="preserve">
<value>я пну тебе это: {0}</value> <value>время отправки: {0}</value>
</data> </data>
<data name="ReminderText" xml:space="preserve"> <data name="ReminderText" xml:space="preserve">
<value>че там в напоминалке: {0}</value> <value>че там в напоминалке: {0}</value>
@ -576,6 +576,9 @@
<data name="DataLoadFailedDescription" xml:space="preserve"> <data name="DataLoadFailedDescription" xml:space="preserve">
<value>возможно всё съедет с крыши, но знай, что я больше ничё не сохраню.</value> <value>возможно всё съедет с крыши, но знай, что я больше ничё не сохраню.</value>
</data> </data>
<data name="CommandExecutionFailed" xml:space="preserve">
<value>произошёл тотальный разнос в команде, удачи.</value>
</data>
<data name="ContactDevelopers" xml:space="preserve"> <data name="ContactDevelopers" xml:space="preserve">
<value>если ты это читаешь второй раз за сегодня, пиши разрабам</value> <value>если ты это читаешь второй раз за сегодня, пиши разрабам</value>
</data> </data>

View file

@ -1,8 +1,12 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Octobot.Extensions; using Octobot.Extensions;
using Remora.Discord.API.Abstractions.Rest;
using Remora.Discord.Commands.Contexts; using Remora.Discord.Commands.Contexts;
using Remora.Discord.Commands.Feedback.Services;
using Remora.Discord.Commands.Services; using Remora.Discord.Commands.Services;
using Remora.Discord.Extensions.Embeds;
using Remora.Discord.Extensions.Formatting;
using Remora.Results; using Remora.Results;
namespace Octobot.Commands.Events; namespace Octobot.Commands.Events;
@ -14,10 +18,15 @@ namespace Octobot.Commands.Events;
public class ErrorLoggingPostExecutionEvent : IPostExecutionEvent public class ErrorLoggingPostExecutionEvent : IPostExecutionEvent
{ {
private readonly ILogger<ErrorLoggingPostExecutionEvent> _logger; private readonly ILogger<ErrorLoggingPostExecutionEvent> _logger;
private readonly FeedbackService _feedback;
private readonly IDiscordRestUserAPI _userApi;
public ErrorLoggingPostExecutionEvent(ILogger<ErrorLoggingPostExecutionEvent> logger) public ErrorLoggingPostExecutionEvent(ILogger<ErrorLoggingPostExecutionEvent> logger, FeedbackService feedback,
IDiscordRestUserAPI userApi)
{ {
_logger = logger; _logger = logger;
_feedback = feedback;
_userApi = userApi;
} }
/// <summary> /// <summary>
@ -28,11 +37,34 @@ public class ErrorLoggingPostExecutionEvent : IPostExecutionEvent
/// <param name="commandResult">The result whose success is checked.</param> /// <param name="commandResult">The result whose success is checked.</param>
/// <param name="ct">The cancellation token for this operation. Unused.</param> /// <param name="ct">The cancellation token for this operation. Unused.</param>
/// <returns>A result which has succeeded.</returns> /// <returns>A result which has succeeded.</returns>
public Task<Result> AfterExecutionAsync( public async Task<Result> AfterExecutionAsync(
ICommandContext context, IResult commandResult, CancellationToken ct = default) ICommandContext context, IResult commandResult, CancellationToken ct = default)
{ {
_logger.LogResult(commandResult, $"Error in slash command execution for /{context.Command.Command.Node.Key}."); _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);
} }
} }

View file

@ -92,7 +92,7 @@ public class RemindCommandGroup : CommandGroup
builder.Append("- ").AppendLine(string.Format(Messages.ReminderPosition, Markdown.InlineCode((i + 1).ToString()))) 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.ReminderText, Markdown.InlineCode(reminder.Text)))
.Append(" - ") .Append(" - ")
.AppendLine(string.Format(Messages.ReminderWillBeSentOn, Markdown.Timestamp(reminder.At))); .AppendLine(string.Format(Messages.ReminderTime, Markdown.Timestamp(reminder.At)));
} }
var embed = new EmbedBuilder().WithSmallTitle( var embed = new EmbedBuilder().WithSmallTitle(
@ -155,7 +155,7 @@ public class RemindCommandGroup : CommandGroup
var builder = new StringBuilder().Append("- ").AppendLine(string.Format( var builder = new StringBuilder().Append("- ").AppendLine(string.Format(
Messages.ReminderText, Markdown.InlineCode(text))) 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( var embed = new EmbedBuilder().WithSmallTitle(
string.Format(Messages.ReminderCreated, executor.GetTag()), executor) string.Format(Messages.ReminderCreated, executor.GetTag()), executor)
@ -210,9 +210,16 @@ public class RemindCommandGroup : CommandGroup
return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct); 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); data.Reminders.RemoveAt(index);
var embed = new EmbedBuilder().WithSmallTitle(Messages.ReminderDeleted, bot) var embed = new EmbedBuilder().WithSmallTitle(Messages.ReminderDeleted, bot)
.WithDescription(description.ToString())
.WithColour(ColorsList.Green) .WithColour(ColorsList.Green)
.Build(); .Build();

View file

@ -26,6 +26,11 @@ public static class LoggerExtensions
if (result.Error is ExceptionError exe) if (result.Error is ExceptionError exe)
{ {
if (exe.Exception is TaskCanceledException)
{
return;
}
logger.LogError(exe.Exception, "{ErrorMessage}", message); logger.LogError(exe.Exception, "{ErrorMessage}", message);
return; return;
} }

View file

@ -786,9 +786,9 @@ namespace Octobot {
} }
} }
internal static string ReminderWillBeSentOn { internal static string ReminderTime {
get { get {
return ResourceManager.GetString("ReminderWillBeSentOn", resourceCulture); return ResourceManager.GetString("ReminderTime", resourceCulture);
} }
} }
@ -1012,6 +1012,15 @@ namespace Octobot {
return ResourceManager.GetString("DataLoadFailedDescription", resourceCulture); return ResourceManager.GetString("DataLoadFailedDescription", resourceCulture);
} }
} }
internal static string CommandExecutionFailed
{
get
{
return ResourceManager.GetString("CommandExecutionFailed", resourceCulture);
}
}
internal static string ContactDevelopers internal static string ContactDevelopers
{ {
get get