1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-05-03 20:49:54 +03:00

/remind: Switch away from zero-based numbering and rename index (#155)

Signed-off-by: Macintosh II <mctaylxrs@outlook.com>
This commit is contained in:
Macintxsh 2023-10-06 17:17:48 +03:00 committed by GitHub
parent a70c228bc4
commit d1e3558bc6
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 24 deletions

View file

@ -88,7 +88,7 @@ public class RemindCommandGroup : CommandGroup
for (var i = 0; i < data.Reminders.Count; i++)
{
var reminder = data.Reminders[i];
builder.Append("- ").AppendLine(string.Format(Messages.ReminderIndex, Markdown.InlineCode(i.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.ReminderWillBeSentOn, Markdown.Timestamp(reminder.At)));
@ -142,8 +142,9 @@ public class RemindCommandGroup : CommandGroup
Snowflake channelId, IUser executor, CancellationToken ct = default)
{
var remindAt = DateTimeOffset.UtcNow.Add(@in);
var memberData = data.GetOrCreateMemberData(executor.ID);
data.GetOrCreateMemberData(executor.ID).Reminders.Add(
memberData.Reminders.Add(
new Reminder
{
At = remindAt,
@ -159,15 +160,16 @@ public class RemindCommandGroup : CommandGroup
string.Format(Messages.ReminderCreated, executor.GetTag()), executor)
.WithDescription(builder.ToString())
.WithColour(ColorsList.Green)
.WithFooter(string.Format(Messages.ReminderPosition, memberData.Reminders.Count))
.Build();
return await _feedback.SendContextualEmbedResultAsync(embed, ct);
}
/// <summary>
/// A slash command that deletes a reminder using its index.
/// A slash command that deletes a reminder using its list position.
/// </summary>
/// <param name="index">The index of the reminder to delete.</param>
/// <param name="position">The list position of the reminder to delete.</param>
/// <returns>A feedback sending result which may or may not have succeeded.</returns>
[Command("delremind")]
[Description("Delete one of your reminders")]
@ -175,8 +177,8 @@ public class RemindCommandGroup : CommandGroup
[RequireContext(ChannelContext.Guild)]
[UsedImplicitly]
public async Task<Result> ExecuteDeleteReminderAsync(
[Description("Index of reminder to delete")] [MinValue(0)]
int index)
[Description("Position in list")] [MinValue(1)]
int position)
{
if (!_context.TryGetContextIDs(out var guildId, out _, out var executorId))
{
@ -192,7 +194,7 @@ public class RemindCommandGroup : CommandGroup
var data = await _guildData.GetData(guildId, CancellationToken);
Messages.Culture = GuildSettings.Language.Get(data.Settings);
return await DeleteReminderAsync(data.GetOrCreateMemberData(executorId), index, bot, CancellationToken);
return await DeleteReminderAsync(data.GetOrCreateMemberData(executorId), position - 1, bot, CancellationToken);
}
private async Task<Result> DeleteReminderAsync(MemberData data, int index, IUser bot,
@ -200,7 +202,7 @@ public class RemindCommandGroup : CommandGroup
{
if (index >= data.Reminders.Count)
{
var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.InvalidReminderIndex, bot)
var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.InvalidReminderPosition, bot)
.WithColour(ColorsList.Red)
.Build();

View file

@ -738,9 +738,9 @@ namespace Octobot {
}
}
internal static string InvalidReminderIndex {
internal static string InvalidReminderPosition {
get {
return ResourceManager.GetString("InvalidReminderIndex", resourceCulture);
return ResourceManager.GetString("InvalidReminderPosition", resourceCulture);
}
}
@ -780,9 +780,9 @@ namespace Octobot {
}
}
internal static string ReminderIndex {
internal static string ReminderPosition {
get {
return ResourceManager.GetString("ReminderIndex", resourceCulture);
return ResourceManager.GetString("ReminderPosition", resourceCulture);
}
}