1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-01-31 09:09:00 +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

@ -453,8 +453,8 @@
<data name="ReminderList" xml:space="preserve"> <data name="ReminderList" xml:space="preserve">
<value>{0}'s reminders</value> <value>{0}'s reminders</value>
</data> </data>
<data name="InvalidReminderIndex" xml:space="preserve"> <data name="InvalidReminderPosition" xml:space="preserve">
<value>There's no reminder with that index!</value> <value>There's no reminder in this position!</value>
</data> </data>
<data name="ReminderDeleted" xml:space="preserve"> <data name="ReminderDeleted" xml:space="preserve">
<value>Reminder deleted</value> <value>Reminder deleted</value>
@ -474,8 +474,8 @@
<data name="DescriptionActionJumpToChannel" xml:space="preserve"> <data name="DescriptionActionJumpToChannel" xml:space="preserve">
<value>Jump to channel: {0}</value> <value>Jump to channel: {0}</value>
</data> </data>
<data name="ReminderIndex" xml:space="preserve"> <data name="ReminderPosition" xml:space="preserve">
<value>Index: {0}</value> <value>Position in list: {0}</value>
</data> </data>
<data name="ReminderWillBeSentOn" xml:space="preserve"> <data name="ReminderWillBeSentOn" xml:space="preserve">
<value>The reminder will be sent on: {0}</value> <value>The reminder will be sent on: {0}</value>

View file

@ -453,8 +453,8 @@
<data name="ReminderList" xml:space="preserve"> <data name="ReminderList" xml:space="preserve">
<value>Напоминания {0}</value> <value>Напоминания {0}</value>
</data> </data>
<data name="InvalidReminderIndex" xml:space="preserve"> <data name="InvalidReminderPosition" xml:space="preserve">
<value>У тебя нет напоминания с указанным индексом!</value> <value>У тебя нет напоминания на этой позиции!</value>
</data> </data>
<data name="ReminderDeleted" xml:space="preserve"> <data name="ReminderDeleted" xml:space="preserve">
<value>Напоминание удалено</value> <value>Напоминание удалено</value>
@ -474,8 +474,8 @@
<data name="DescriptionActionJumpToChannel" xml:space="preserve"> <data name="DescriptionActionJumpToChannel" xml:space="preserve">
<value>Перейти к каналу: {0}</value> <value>Перейти к каналу: {0}</value>
</data> </data>
<data name="ReminderIndex" 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="ReminderWillBeSentOn" xml:space="preserve">
<value>Напоминание будет отправлено: {0}</value> <value>Напоминание будет отправлено: {0}</value>

View file

@ -453,8 +453,8 @@
<data name="ReminderList" xml:space="preserve"> <data name="ReminderList" xml:space="preserve">
<value>напоминалки {0}</value> <value>напоминалки {0}</value>
</data> </data>
<data name="InvalidReminderIndex" xml:space="preserve"> <data name="InvalidReminderPosition" xml:space="preserve">
<value>у тебя нет напоминалки с этим индексом!</value> <value>у тебя нет напоминалки на этом номере!</value>
</data> </data>
<data name="ReminderDeleted" xml:space="preserve"> <data name="ReminderDeleted" xml:space="preserve">
<value>напоминалка уничтожена</value> <value>напоминалка уничтожена</value>
@ -474,8 +474,8 @@
<data name="DescriptionActionJumpToChannel" xml:space="preserve"> <data name="DescriptionActionJumpToChannel" xml:space="preserve">
<value>чекнуть канал: {0}</value> <value>чекнуть канал: {0}</value>
</data> </data>
<data name="ReminderIndex" 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="ReminderWillBeSentOn" xml:space="preserve">
<value>я пну тебе это: {0}</value> <value>я пну тебе это: {0}</value>

View file

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

View file

@ -738,9 +738,9 @@ namespace Octobot {
} }
} }
internal static string InvalidReminderIndex { internal static string InvalidReminderPosition {
get { 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 { get {
return ResourceManager.GetString("ReminderIndex", resourceCulture); return ResourceManager.GetString("ReminderPosition", resourceCulture);
} }
} }