mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-04 00:34:26 -05:00 
			
		
		
		
	Moved some ICurrencyService methods to extensions to simplify use
This commit is contained in:
		@@ -65,8 +65,7 @@ public partial class Gambling : GamblingModule<GamblingService>
 | 
			
		||||
 | 
			
		||||
    public async Task<string> GetBalanceStringAsync(ulong userId)
 | 
			
		||||
    {
 | 
			
		||||
        await using var wallet = await _cs.GetWalletAsync(userId);
 | 
			
		||||
        var bal = await wallet.GetBalance();
 | 
			
		||||
        var bal = await _cs.GetBalanceAsync(userId);
 | 
			
		||||
        return N(bal);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -99,19 +99,4 @@ public class CurrencyService : ICurrencyService, INService
 | 
			
		||||
        await using var wallet = await GetWalletAsync(user.Id);
 | 
			
		||||
        return await wallet.Take(amount, txData);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public async Task<bool> TransferAsync(
 | 
			
		||||
        ulong fromId,
 | 
			
		||||
        ulong toId,
 | 
			
		||||
        long amount,
 | 
			
		||||
        string fromName,
 | 
			
		||||
        string note)
 | 
			
		||||
    {
 | 
			
		||||
        await using var fromWallet = await GetWalletAsync(fromId);
 | 
			
		||||
        await using var toWallet = await GetWalletAsync(toId);
 | 
			
		||||
 | 
			
		||||
        var extra = new TxData("gift", fromName, note, fromId);
 | 
			
		||||
 | 
			
		||||
        return await fromWallet.Transfer(amount, toWallet, extra);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										28
									
								
								src/NadekoBot/Services/Currency/CurrencyServiceExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/NadekoBot/Services/Currency/CurrencyServiceExtensions.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
using NadekoBot.Services.Currency;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Services;
 | 
			
		||||
 | 
			
		||||
public static class CurrencyServiceExtensions
 | 
			
		||||
{
 | 
			
		||||
    public static async Task<long> GetBalanceAsync(this ICurrencyService cs, ulong userId)
 | 
			
		||||
    {
 | 
			
		||||
        await using var wallet = await cs.GetWalletAsync(userId);
 | 
			
		||||
        return await wallet.GetBalance();
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static async Task<bool> TransferAsync(
 | 
			
		||||
        this ICurrencyService cs,
 | 
			
		||||
        ulong fromId,
 | 
			
		||||
        ulong toId,
 | 
			
		||||
        long amount,
 | 
			
		||||
        string fromName,
 | 
			
		||||
        string note)
 | 
			
		||||
    {
 | 
			
		||||
        await using var fromWallet = await cs.GetWalletAsync(fromId);
 | 
			
		||||
        await using var toWallet = await cs.GetWalletAsync(toId);
 | 
			
		||||
 | 
			
		||||
        var extra = new TxData("gift", fromName, note, fromId);
 | 
			
		||||
 | 
			
		||||
        return await fromWallet.Transfer(amount, toWallet, extra);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -38,11 +38,4 @@ public interface ICurrencyService
 | 
			
		||||
        IUser user,
 | 
			
		||||
        long amount,
 | 
			
		||||
        TxData txData);
 | 
			
		||||
 | 
			
		||||
    Task<bool> TransferAsync(
 | 
			
		||||
        ulong from,
 | 
			
		||||
        ulong to,
 | 
			
		||||
        long amount,
 | 
			
		||||
        string fromName,
 | 
			
		||||
        string note);
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user