mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-04 08:34:27 -05:00 
			
		
		
		
	.xpadd will now work on roles
This commit is contained in:
		@@ -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);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user