.xpadd will now work on roles

This commit is contained in:
Kwoth
2022-07-26 15:47:55 +02:00
parent a7b3a238f5
commit 0f8291c589
5 changed files with 34 additions and 3 deletions

View File

@@ -252,6 +252,23 @@ public partial class Xp : NadekoModule<XpService>
[Cmd]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.Administrator)]
[Priority(2)]
public async Task XpAdd(long amount, [Remainder] SocketRole role)
{
if (amount == 0)
return;
if (role.IsManaged)
return;
var count = await _service.AddXpToUsersAsync(ctx.Guild.Id, amount, role.Members.Select(x => x.Id).ToArray());
await ReplyConfirmLocalizedAsync(strs.xpadd_users(Format.Bold(amount.ToString()), Format.Bold(count.ToString())));
}
[Cmd]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.Administrator)]
[Priority(3)]
public async Task XpAdd(int amount, ulong userId)
{
if (amount == 0)
@@ -265,6 +282,7 @@ public partial class Xp : NadekoModule<XpService>
[Cmd]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.Administrator)]
[Priority(4)]
public Task XpAdd(int amount, [Leftover] IGuildUser user)
=> XpAdd(amount, user.Id);

View File

@@ -726,6 +726,17 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
// });
// }
public async Task<int> AddXpToUsersAsync(ulong guildId, long amount, params ulong[] userIds)
{
await using var ctx = _db.GetDbContext();
return await ctx.GetTable<UserXpStats>()
.Where(x => x.GuildId == guildId && userIds.Contains(x.UserId))
.UpdateAsync(old => new()
{
Xp = old.Xp + amount
});
}
public void AddXp(ulong userId, ulong guildId, int amount)
{
using var uow = _db.GetDbContext();

View File

@@ -7,7 +7,7 @@ namespace NadekoBot.Services;
public sealed class StatsService : IStatsService, IReadyExecutor, INService
{
public const string BOT_VERSION = "4.2.15";
public const string BOT_VERSION = "4.3.0";
public string Author
=> "Kwoth#2452";

View File

@@ -1853,9 +1853,10 @@ xpgloballeaderboard:
args:
- ""
xpadd:
desc: "Adds xp to a user on the server. This does not affect their global ranking. You can use negative values."
desc: "Adds server XP to a single user or all users role on this server. This does not affect their global ranking. You can use negative values."
args:
- "100 @Someone"
- "500 SomeRoleName"
clubcreate:
desc: "Creates a club. You must be at least level 5 and not be in the club already."
args:

View File

@@ -1012,5 +1012,6 @@
"quotas": "<<< Quotas >>>",
"patron_not_enabled": "Patron system is disabled.",
"results_in": "{0} results in {1}s",
"patron_msg_sent": "Done sending messages to patrons at and above tier {1}. {1} successfully sent and {2} failed."
"patron_msg_sent": "Done sending messages to patrons at and above tier {1}. {1} successfully sent and {2} failed.",
"xpadd_users": "Added {0} server XP to {1} users."
}