$lb is now paginated

This commit is contained in:
Kwoth 2017-03-09 02:17:18 +01:00
parent dc283d1054
commit ba19524245
7 changed files with 2126 additions and 2093 deletions

View File

@ -244,19 +244,26 @@ namespace NadekoBot.Modules.Gambling
}
[NadekoCommand, Usage, Description, Aliases]
public async Task Leaderboard()
public async Task Leaderboard(int page = 1)
{
List<Currency> richest;
using (var uow = DbHandler.UnitOfWork())
{
richest = uow.Currency.GetTopRichest(9).ToList();
richest = uow.Currency.GetTopRichest(9, 9 * (page - 1)).ToList();
}
if (!richest.Any())
return;
var embed = new EmbedBuilder()
.WithOkColor()
.WithTitle(NadekoBot.BotConfig.CurrencySign + " " + GetText("leaderboard"));
.WithTitle(NadekoBot.BotConfig.CurrencySign +
" " + GetText("leaderboard"))
.WithFooter(efb => efb.WithText(GetText("page", page)));
if (!richest.Any())
{
embed.WithDescription(GetText("no_users_found"));
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
return;
}
for (var i = 0; i < richest.Count; i++)
{

View File

@ -2404,6 +2404,15 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to No users found..
/// </summary>
public static string gambling_no_users_found {
get {
return ResourceManager.GetString("gambling_no_users_found", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Nobody.
/// </summary>
@ -2422,6 +2431,15 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to page {0}.
/// </summary>
public static string gambling_page {
get {
return ResourceManager.GetString("gambling_page", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Price.
/// </summary>

File diff suppressed because it is too large Load Diff

View File

@ -2224,4 +2224,10 @@ Owner ID: {2}</value>
<data name="games_pick_sn" xml:space="preserve">
<value>Pick it up by typing `{0}pick`</value>
</data>
<data name="gambling_no_users_found" xml:space="preserve">
<value>No users found.</value>
</data>
<data name="gambling_page" xml:space="preserve">
<value>page {0}</value>
</data>
</root>

View File

@ -8,6 +8,6 @@ namespace NadekoBot.Services.Database.Repositories
Currency GetOrCreate(ulong userId);
long GetUserCurrency(ulong userId);
bool TryUpdateState(ulong userId, long change);
IEnumerable<Currency> GetTopRichest(int count);
IEnumerable<Currency> GetTopRichest(int count, int skip);
}
}

View File

@ -27,8 +27,8 @@ namespace NadekoBot.Services.Database.Repositories.Impl
return cur;
}
public IEnumerable<Currency> GetTopRichest(int count) =>
_set.OrderByDescending(c => c.Amount).Take(count).ToList();
public IEnumerable<Currency> GetTopRichest(int count, int skip = 0) =>
_set.OrderByDescending(c => c.Amount).Skip(skip).Take(count).ToList();
public long GetUserCurrency(ulong userId) =>
GetOrCreate(userId).Amount;

View File

@ -93,9 +93,9 @@ namespace NadekoBot.Extensions
private static EmbedBuilder AddPaginatedFooter(this EmbedBuilder embed, int curPage, int? lastPage)
{
if (lastPage != null)
return embed.WithFooter(efb => efb.WithText($"page {curPage} / {lastPage}"));
return embed.WithFooter(efb => efb.WithText($"{curPage} / {lastPage}"));
else
return embed.WithFooter(efb => efb.WithText($"page {curPage}"));
return embed.WithFooter(efb => efb.WithText(curPage.ToString()));
}
public static ReactionEventWrapper OnReaction(this IUserMessage msg, Action<SocketReaction> reactionAdded, Action<SocketReaction> reactionRemoved = null)