mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
fix: xplb and xpglb pagination fixed, closes #430
fix: Page number when there is an unknown number of items while paginating is now correct fix: .stm and .stma fixed and can now mention everyone as long as the user executing the command also can dev: Cleaned up/improved some code
This commit is contained in:
@@ -58,7 +58,7 @@ public partial class ResponseBuilder
|
||||
cb.WithButton(new ButtonBuilder()
|
||||
.WithStyle(ButtonStyle.Primary)
|
||||
.WithCustomId(BUTTON_RIGHT)
|
||||
.WithDisabled(lastPage == 0 || currentPage >= lastPage)
|
||||
.WithDisabled(lastPage is not null && (lastPage == 0 || currentPage >= lastPage))
|
||||
.WithEmote(InteractionHelpers.ArrowRight));
|
||||
|
||||
return cb;
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using NadekoBot.Common.Configs;
|
||||
using NadekoBot.Db.Models;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace NadekoBot.Extensions;
|
||||
|
||||
@@ -357,10 +358,9 @@ public sealed partial class ResponseBuilder
|
||||
fileName = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public PaginatedResponseBuilder Paginated()
|
||||
=> new(this);
|
||||
|
||||
}
|
||||
|
||||
public class PaginatedResponseBuilder
|
||||
@@ -376,7 +376,7 @@ public class PaginatedResponseBuilder
|
||||
=> new SourcedPaginatedResponseBuilder<T>(_builder)
|
||||
.Items(items);
|
||||
|
||||
public SourcedPaginatedResponseBuilder<T> PageItems<T>(Func<int, Task<IEnumerable<T>>> items)
|
||||
public SourcedPaginatedResponseBuilder<T> PageItems<T>(Func<int, Task<IReadOnlyCollection<T>>> items)
|
||||
=> new SourcedPaginatedResponseBuilder<T>(_builder)
|
||||
.PageItems(items);
|
||||
}
|
||||
@@ -390,14 +390,14 @@ public sealed class SourcedPaginatedResponseBuilder<T> : PaginatedResponseBuilde
|
||||
return Task.FromResult<EmbedBuilder>(new());
|
||||
};
|
||||
|
||||
public Func<int, Task<IEnumerable<T>>> ItemsFunc { get; set; } = static delegate
|
||||
public Func<int, Task<IReadOnlyCollection<T>>> ItemsFunc { get; set; } = static delegate
|
||||
{
|
||||
return Task.FromResult(Enumerable.Empty<T>());
|
||||
return Task.FromResult<IReadOnlyCollection<T>>(ReadOnlyCollection<T>.Empty);
|
||||
};
|
||||
|
||||
public Func<int, Task<SimpleInteractionBase>>? InteractionFunc { get; private set; }
|
||||
|
||||
public int Elems { get; private set; } = 1;
|
||||
public int? Elems { get; private set; } = 1;
|
||||
public int ItemsPerPage { get; private set; } = 9;
|
||||
public bool AddPaginatedFooter { get; private set; } = true;
|
||||
public bool IsEphemeral { get; private set; }
|
||||
@@ -413,18 +413,19 @@ public sealed class SourcedPaginatedResponseBuilder<T> : PaginatedResponseBuilde
|
||||
{
|
||||
items = col;
|
||||
Elems = col.Count;
|
||||
ItemsFunc = (i) => Task.FromResult(items.Skip(i * ItemsPerPage).Take(ItemsPerPage));
|
||||
ItemsFunc = (i) => Task.FromResult(items.Skip(i * ItemsPerPage).Take(ItemsPerPage).ToArray() as IReadOnlyCollection<T>);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SourcedPaginatedResponseBuilder<T> TotalElements(int i)
|
||||
{
|
||||
Elems = i;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SourcedPaginatedResponseBuilder<T> PageItems(Func<int, Task<IEnumerable<T>>> func)
|
||||
public SourcedPaginatedResponseBuilder<T> PageItems(Func<int, Task<IReadOnlyCollection<T>>> func)
|
||||
{
|
||||
Elems = null;
|
||||
ItemsFunc = func;
|
||||
return this;
|
||||
}
|
||||
|
@@ -167,7 +167,8 @@ public static class Extensions
|
||||
{
|
||||
if (lastPage is not null)
|
||||
return embed.WithFooter($"{curPage + 1} / {lastPage + 1}");
|
||||
return embed.WithFooter(curPage.ToString());
|
||||
|
||||
return embed.WithFooter((curPage + 1).ToString());
|
||||
}
|
||||
|
||||
// public static EmbedBuilder WithOkColor(this EmbedBuilder eb)
|
||||
|
Reference in New Issue
Block a user