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.
This commit is contained in:
Macintxsh 2023-08-14 10:45:56 +03:00 committed by GitHub
parent 87dbb07dec
commit da2a88246c
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 2 deletions

View file

@ -591,4 +591,7 @@
<data name="ReminderDeleted" xml:space="preserve">
<value>Reminder deleted</value>
</data>
<data name="NoRemindersFound" xml:space="preserve">
<value>You don't have any reminders created!</value>
</data>
</root>

View file

@ -591,4 +591,7 @@
<data name="ReminderDeleted" xml:space="preserve">
<value>Напоминание удалено</value>
</data>
<data name="NoRemindersFound" xml:space="preserve">
<value>У вас нет созданных напоминаний!</value>
</data>
</root>

View file

@ -591,4 +591,7 @@
<data name="ReminderDeleted" xml:space="preserve">
<value>напоминалка уничтожена</value>
</data>
<data name="NoRemindersFound" xml:space="preserve">
<value>ты еще не крафтил напоминалки</value>
</data>
</root>

View file

@ -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<Result> ListRemindersAsync(MemberData data, IUser user, CancellationToken ct)
private async Task<Result> 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++)
{

View file

@ -995,5 +995,11 @@ namespace Boyfriend {
return ResourceManager.GetString("ReminderDeleted", resourceCulture);
}
}
internal static string NoRemindersFound {
get {
return ResourceManager.GetString("NoRemindersFound", resourceCulture);
}
}
}
}