mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -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:
@@ -766,7 +766,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
}
|
||||
|
||||
|
||||
async Task<IEnumerable<DiscordUser>> GetTopRichest(int curPage)
|
||||
async Task<IReadOnlyCollection<DiscordUser>> GetTopRichest(int curPage)
|
||||
{
|
||||
if (opts.Clean)
|
||||
{
|
||||
|
@@ -143,6 +143,10 @@ public partial class Searches
|
||||
if (--index < 0)
|
||||
return;
|
||||
|
||||
var canMentionEveryone = (ctx.User as IGuildUser)?.GuildPermissions.MentionEveryone ?? true;
|
||||
if (!canMentionEveryone)
|
||||
message = message?.SanitizeAllMentions();
|
||||
|
||||
if (!_service.SetStreamMessage(ctx.Guild.Id, index, message, out var fs))
|
||||
{
|
||||
await Response().Confirm(strs.stream_not_following).SendAsync();
|
||||
@@ -160,6 +164,10 @@ public partial class Searches
|
||||
[UserPerm(GuildPerm.ManageMessages)]
|
||||
public async Task StreamMessageAll([Leftover] string message)
|
||||
{
|
||||
var canMentionEveryone = (ctx.User as IGuildUser)?.GuildPermissions.MentionEveryone ?? true;
|
||||
if (!canMentionEveryone)
|
||||
message = message?.SanitizeAllMentions();
|
||||
|
||||
var count = _service.SetStreamMessageForAll(ctx.Guild.Id, message);
|
||||
|
||||
if (count == 0)
|
||||
|
@@ -294,6 +294,7 @@ public sealed class StreamNotificationService : INService, IReadyExecutor
|
||||
var msg = await _sender.Response(textChannel)
|
||||
.Embed(GetEmbed(fs.GuildId, stream, false))
|
||||
.Text(message)
|
||||
.Sanitize(false)
|
||||
.SendAsync();
|
||||
|
||||
// only cache the ids of channel/message pairs
|
||||
@@ -615,7 +616,9 @@ public sealed class StreamNotificationService : INService, IReadyExecutor
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
|
||||
var all = uow.Set<FollowedStream>().ToList();
|
||||
var all = uow.Set<FollowedStream>()
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.ToList();
|
||||
|
||||
if (all.Count == 0)
|
||||
return 0;
|
||||
@@ -623,6 +626,19 @@ public sealed class StreamNotificationService : INService, IReadyExecutor
|
||||
all.ForEach(x => x.Message = message);
|
||||
|
||||
uow.SaveChanges();
|
||||
|
||||
lock (_shardLock)
|
||||
{
|
||||
foreach (var fs in all)
|
||||
{
|
||||
var streams = GetLocalGuildStreams(fs.CreateKey(), guildId);
|
||||
|
||||
// message doesn't participate in equality checking
|
||||
// removing and adding = update
|
||||
streams.Remove(fs);
|
||||
streams.Add(fs);
|
||||
}
|
||||
}
|
||||
|
||||
return all.Count;
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#nullable disable warnings
|
||||
using NadekoBot.Modules.Xp.Services;
|
||||
using NadekoBot.Db.Models;
|
||||
using NadekoBot.Db;
|
||||
using NadekoBot.Modules.Patronage;
|
||||
|
||||
namespace NadekoBot.Modules.Xp;
|
||||
@@ -191,21 +190,22 @@ public partial class Xp : NadekoModule<XpService>
|
||||
await ctx.Channel.TriggerTypingAsync();
|
||||
await _tracker.EnsureUsersDownloadedAsync(ctx.Guild);
|
||||
|
||||
allCleanUsers = _service.GetTopUserXps(ctx.Guild.Id, 1000)
|
||||
.Where(user => socketGuild.GetUser(user.UserId) is not null)
|
||||
.ToList();
|
||||
allCleanUsers = (await _service.GetTopUserXps(ctx.Guild.Id, 1000))
|
||||
.Where(user => socketGuild.GetUser(user.UserId) is not null)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
await Response()
|
||||
var res = opts.Clean
|
||||
? Response()
|
||||
.Paginated()
|
||||
.PageItems<UserXpStats>(opts.Clean
|
||||
? (curPage) => Task.FromResult<IEnumerable<UserXpStats>>(allCleanUsers.Skip(curPage * 9)
|
||||
.Take(9)
|
||||
.ToList())
|
||||
: (curPage) => Task.FromResult<IEnumerable<UserXpStats>>(_service.GetUserXps(ctx.Guild.Id, curPage)))
|
||||
.Items(allCleanUsers)
|
||||
: Response()
|
||||
.Paginated()
|
||||
.PageItems((curPage) => _service.GetUserXps(ctx.Guild.Id, curPage));
|
||||
|
||||
await res
|
||||
.PageSize(9)
|
||||
.CurrentPage(page)
|
||||
.AddFooter(false)
|
||||
.Page((users, curPage) =>
|
||||
{
|
||||
var embed = _sender.CreateEmbed().WithTitle(GetText(strs.server_leaderboard)).WithOkColor();
|
||||
@@ -241,23 +241,33 @@ public partial class Xp : NadekoModule<XpService>
|
||||
{
|
||||
if (--page < 0 || page > 99)
|
||||
return;
|
||||
var users = _service.GetUserXps(page);
|
||||
|
||||
var embed = _sender.CreateEmbed().WithTitle(GetText(strs.global_leaderboard)).WithOkColor();
|
||||
await Response()
|
||||
.Paginated()
|
||||
.PageItems(async curPage => await _service.GetUserXps(curPage))
|
||||
.PageSize(9)
|
||||
.Page((users, curPage) =>
|
||||
{
|
||||
var embed = _sender.CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.global_leaderboard));
|
||||
|
||||
if (!users.Any())
|
||||
embed.WithDescription("-");
|
||||
else
|
||||
{
|
||||
for (var i = 0; i < users.Length; i++)
|
||||
{
|
||||
var user = users[i];
|
||||
embed.AddField($"#{i + 1 + (page * 9)} {user.ToString()}",
|
||||
$"{GetText(strs.level_x(new LevelStats(users[i].TotalXp).Level))} - {users[i].TotalXp}xp");
|
||||
}
|
||||
}
|
||||
if (!users.Any())
|
||||
{
|
||||
embed.WithDescription("-");
|
||||
return embed;
|
||||
}
|
||||
|
||||
await Response().Embed(embed).SendAsync();
|
||||
for (var i = 0; i < users.Count; i++)
|
||||
{
|
||||
var user = users[i];
|
||||
embed.AddField($"#{i + 1 + (curPage * 9)} {user}",
|
||||
$"{GetText(strs.level_x(new LevelStats(users[i].TotalXp).Level))} - {users[i].TotalXp}xp");
|
||||
}
|
||||
|
||||
return embed;
|
||||
})
|
||||
.SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
|
@@ -563,22 +563,23 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
||||
public List<UserXpStats> GetUserXps(ulong guildId, int page)
|
||||
public async Task<IReadOnlyCollection<UserXpStats>> GetUserXps(ulong guildId, int page)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
return uow.Set<UserXpStats>().GetUsersFor(guildId, page);
|
||||
await using var uow = _db.GetDbContext();
|
||||
return await uow.Set<UserXpStats>().GetUsersFor(guildId, page);
|
||||
}
|
||||
|
||||
public List<UserXpStats> GetTopUserXps(ulong guildId, int count)
|
||||
public async Task<IReadOnlyCollection<UserXpStats>> GetTopUserXps(ulong guildId, int count)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
return uow.Set<UserXpStats>().GetTopUserXps(guildId, count);
|
||||
await using var uow = _db.GetDbContext();
|
||||
return await uow.Set<UserXpStats>().GetTopUserXps(guildId, count);
|
||||
}
|
||||
|
||||
public DiscordUser[] GetUserXps(int page, int perPage = 9)
|
||||
public Task<IReadOnlyCollection<DiscordUser>> GetUserXps(int page, int perPage = 9)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
return uow.Set<DiscordUser>().GetUsersXpLeaderboardFor(page, perPage);
|
||||
return uow.Set<DiscordUser>()
|
||||
.GetUsersXpLeaderboardFor(page, perPage);
|
||||
}
|
||||
|
||||
public async Task ChangeNotificationType(ulong userId, ulong guildId, XpNotificationLocation type)
|
||||
@@ -884,7 +885,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
|
||||
var du = uow.GetOrCreateUser(user, set => set.Include(x => x.Club));
|
||||
var totalXp = du.TotalXp;
|
||||
var globalRank = uow.Set<DiscordUser>().GetUserGlobalRank(user.Id);
|
||||
var guildRank = uow.Set<UserXpStats>().GetUserGuildRanking(user.Id, user.GuildId);
|
||||
var guildRank = await uow.Set<UserXpStats>().GetUserGuildRanking(user.Id, user.GuildId);
|
||||
var stats = uow.GetOrCreateUserXpStats(user.GuildId, user.Id);
|
||||
await uow.SaveChangesAsync();
|
||||
|
||||
|
Reference in New Issue
Block a user