mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-04 08:34:27 -05:00 
			
		
		
		
	Added an option to award currency based on received xp
This commit is contained in:
		@@ -26,6 +26,9 @@ public sealed partial class XpConfig : ICloneable<XpConfig>
 | 
			
		||||
 | 
			
		||||
    [Comment(@"The maximum amount of minutes the bot will keep track of a user in a voice channel")]
 | 
			
		||||
    public int VoiceMaxMinutes { get; set; } = 720;
 | 
			
		||||
    
 | 
			
		||||
    [Comment(@"The amount of currency users will receive for each point of global xp that they earn")]
 | 
			
		||||
    public float CurrencyPerXp { get; set; } = 0;
 | 
			
		||||
 | 
			
		||||
    [Comment(@"Xp Shop config")]
 | 
			
		||||
    public ShopConfig Shop { get; set; } = new();
 | 
			
		||||
 
 | 
			
		||||
@@ -52,11 +52,11 @@ public sealed class XpConfigService : ConfigServiceBase<XpConfig>
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        if (data.Version < 5)
 | 
			
		||||
        if (data.Version < 6)
 | 
			
		||||
        {
 | 
			
		||||
            ModifyConfig(c =>
 | 
			
		||||
            {
 | 
			
		||||
                c.Version = 5;
 | 
			
		||||
                c.Version = 6;
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -176,6 +176,16 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
 | 
			
		||||
            var gxps = new List<UserXpStats>(globalToAdd.Count);
 | 
			
		||||
            await using (var ctx = _db.GetDbContext())
 | 
			
		||||
            {
 | 
			
		||||
                var conf = _xpConfig.Data;
 | 
			
		||||
                if (conf.CurrencyPerXp > 0)
 | 
			
		||||
                {
 | 
			
		||||
                    foreach (var user in globalToAdd)
 | 
			
		||||
                    {
 | 
			
		||||
                        var amount = user.Value.XpAmount * conf.CurrencyPerXp;
 | 
			
		||||
                        await _cs.AddAsync(user.Key, (long)(amount), null);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                
 | 
			
		||||
                // update global user xp in batches
 | 
			
		||||
                // group by xp amount and update the same amounts at the same time
 | 
			
		||||
                foreach (var group in globalToAdd.GroupBy(x => x.Value.XpAmount, x => x.Key))
 | 
			
		||||
@@ -197,7 +207,6 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
 | 
			
		||||
                    
 | 
			
		||||
                    dus.AddRange(items);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // update guild user xp in batches
 | 
			
		||||
                foreach (var (guildId, toAdd) in guildToAdd)
 | 
			
		||||
                {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user