From da2a88246c1aadc57141726af3a8ea848d28d638 Mon Sep 17 00:00:00 2001
From: Macintosh II <95250141+mctaylors@users.noreply.github.com>
Date: Mon, 14 Aug 2023 10:45:56 +0300
Subject: [PATCH] Add failed embed for /listremind (#88)
Without this embed, if there are no reminders created by the user, the
bot will endlessly think because StringBuilder will be empty and normal
embed will not be shown.
---
locale/Messages.resx | 3 +++
locale/Messages.ru.resx | 3 +++
locale/Messages.tt-ru.resx | 3 +++
src/Commands/RemindCommandGroup.cs | 19 +++++++++++++++++--
src/Messages.Designer.cs | 6 ++++++
5 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/locale/Messages.resx b/locale/Messages.resx
index cf3de28..82392a8 100644
--- a/locale/Messages.resx
+++ b/locale/Messages.resx
@@ -591,4 +591,7 @@
Reminder deleted
+
+ You don't have any reminders created!
+
diff --git a/locale/Messages.ru.resx b/locale/Messages.ru.resx
index d4729d1..7b5b3d4 100644
--- a/locale/Messages.ru.resx
+++ b/locale/Messages.ru.resx
@@ -591,4 +591,7 @@
Напоминание удалено
+
+ У вас нет созданных напоминаний!
+
diff --git a/locale/Messages.tt-ru.resx b/locale/Messages.tt-ru.resx
index ec1c886..bb8c204 100644
--- a/locale/Messages.tt-ru.resx
+++ b/locale/Messages.tt-ru.resx
@@ -591,4 +591,7 @@
напоминалка уничтожена
+
+ ты еще не крафтил напоминалки
+
diff --git a/src/Commands/RemindCommandGroup.cs b/src/Commands/RemindCommandGroup.cs
index 8e8b820..263d1ba 100644
--- a/src/Commands/RemindCommandGroup.cs
+++ b/src/Commands/RemindCommandGroup.cs
@@ -61,14 +61,29 @@ public class RemindCommandGroup : CommandGroup
return Result.FromError(userResult);
}
+ var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken);
+ if (!currentUserResult.IsDefined(out var currentUser))
+ {
+ return Result.FromError(currentUserResult);
+ }
+
var data = await _guildData.GetData(guildId, CancellationToken);
Messages.Culture = GuildSettings.Language.Get(data.Settings);
- return await ListRemindersAsync(data.GetOrCreateMemberData(userId), user, CancellationToken);
+ return await ListRemindersAsync(data.GetOrCreateMemberData(userId), user, currentUser, CancellationToken);
}
- private async Task ListRemindersAsync(MemberData data, IUser user, CancellationToken ct)
+ private async Task ListRemindersAsync(MemberData data, IUser user, IUser currentUser, CancellationToken ct)
{
+ if (data.Reminders.Count == 0)
+ {
+ var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.NoRemindersFound, currentUser)
+ .WithColour(ColorsList.Red)
+ .Build();
+
+ return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct);
+ }
+
var builder = new StringBuilder();
for (var i = 0; i < data.Reminders.Count; i++)
{
diff --git a/src/Messages.Designer.cs b/src/Messages.Designer.cs
index b4509e8..0fee435 100644
--- a/src/Messages.Designer.cs
+++ b/src/Messages.Designer.cs
@@ -995,5 +995,11 @@ namespace Boyfriend {
return ResourceManager.GetString("ReminderDeleted", resourceCulture);
}
}
+
+ internal static string NoRemindersFound {
+ get {
+ return ResourceManager.GetString("NoRemindersFound", resourceCulture);
+ }
+ }
}
}