mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-03 16:24:27 -05:00 
			
		
		
		
	Using INumber<T> for pretty printing nadeko currency
This commit is contained in:
		@@ -1,4 +1,6 @@
 | 
				
			|||||||
namespace Nadeko.Common;
 | 
					using System.Numerics;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Nadeko.Common;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public readonly struct ShmartNumber : IEquatable<ShmartNumber>
 | 
					public readonly struct ShmartNumber : IEquatable<ShmartNumber>
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,7 +29,7 @@ public partial class Gambling
 | 
				
			|||||||
            
 | 
					            
 | 
				
			||||||
            if (await _bank.DepositAsync(ctx.User.Id, amount))
 | 
					            if (await _bank.DepositAsync(ctx.User.Id, amount))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                await ReplyConfirmLocalizedAsync(strs.bank_deposited(N(amount)));
 | 
					                await ReplyConfirmLocalizedAsync(strs.bank_deposited(N(amount.Value)));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else
 | 
					            else
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@@ -45,7 +45,7 @@ public partial class Gambling
 | 
				
			|||||||
            
 | 
					            
 | 
				
			||||||
            if (await _bank.WithdrawAsync(ctx.User.Id, amount))
 | 
					            if (await _bank.WithdrawAsync(ctx.User.Id, amount))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                await ReplyConfirmLocalizedAsync(strs.bank_withdrew(N(amount)));
 | 
					                await ReplyConfirmLocalizedAsync(strs.bank_withdrew(N(amount.Amount)));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else
 | 
					            else
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -435,7 +435,7 @@ public partial class Gambling : GamblingModule<GamblingService>
 | 
				
			|||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!await _cs.TransferAsync(_eb, ctx.User, receiver, amount, msg, N(amount)))
 | 
					        if (!await _cs.TransferAsync(_eb, ctx.User, receiver, amount, msg, N(amount.Value)))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
 | 
					            await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
@@ -744,7 +744,7 @@ public partial class Gambling : GamblingModule<GamblingService>
 | 
				
			|||||||
            await ctx.Channel.TriggerTypingAsync();
 | 
					            await ctx.Channel.TriggerTypingAsync();
 | 
				
			||||||
            await _tracker.EnsureUsersDownloadedAsync(ctx.Guild);
 | 
					            await _tracker.EnsureUsersDownloadedAsync(ctx.Guild);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var sg = (SocketGuild)ctx.Guild;
 | 
					            var sg = (SocketGuild)ctx.Guild!;
 | 
				
			||||||
            cleanRichest = cleanRichest.Where(x => sg.GetUser(x.UserId) is not null).ToList();
 | 
					            cleanRichest = cleanRichest.Where(x => sg.GetUser(x.UserId) is not null).ToList();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
@@ -920,10 +920,11 @@ public partial class Gambling : GamblingModule<GamblingService>
 | 
				
			|||||||
    [OwnerOnly]
 | 
					    [OwnerOnly]
 | 
				
			||||||
    public async Task BetTest()
 | 
					    public async Task BetTest()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        await SendConfirmAsync(GetText(strs.available_tests),
 | 
					        var values = Enum.GetValues<GambleTestTarget>()
 | 
				
			||||||
            Enum.GetValues<GambleTestTarget>()
 | 
					                         .Select(x => $"`{x}`")
 | 
				
			||||||
                .Select(x => $"`{x}`")
 | 
					                         .Join(", ");
 | 
				
			||||||
                .Join(", "));
 | 
					        
 | 
				
			||||||
 | 
					        await SendConfirmAsync(GetText(strs.available_tests), values);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [Cmd]
 | 
					    [Cmd]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
#nullable disable
 | 
					#nullable disable
 | 
				
			||||||
using NadekoBot.Modules.Gambling.Services;
 | 
					using NadekoBot.Modules.Gambling.Services;
 | 
				
			||||||
using System.Globalization;
 | 
					using System.Globalization;
 | 
				
			||||||
 | 
					using System.Numerics;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Modules.Gambling.Common;
 | 
					namespace NadekoBot.Modules.Gambling.Common;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -39,16 +40,12 @@ public abstract class GamblingModule<TService> : NadekoModule<TService>
 | 
				
			|||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static string N(long cur, IFormatProvider format)
 | 
					    public static string N<T>(T cur, IFormatProvider format)
 | 
				
			||||||
 | 
					        where T : INumber<T>
 | 
				
			||||||
        => cur.ToString("C0", format);
 | 
					        => cur.ToString("C0", format);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static string N(decimal cur, IFormatProvider format)
 | 
					    protected string N<T>(T cur)
 | 
				
			||||||
        => cur.ToString("C0", format);
 | 
					        where T : INumber<T>
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    protected string N(long cur)
 | 
					 | 
				
			||||||
        => N(cur, GetFlowersCiInternal());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    protected string N(decimal cur)
 | 
					 | 
				
			||||||
        => N(cur, GetFlowersCiInternal());
 | 
					        => N(cur, GetFlowersCiInternal());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected IFormatProvider GetFlowersCiInternal()
 | 
					    protected IFormatProvider GetFlowersCiInternal()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user