This repository has been archived on 2024-12-22. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
elliebot/src/EllieBot/Modules/Gambling/GamblingTopLevelModule.cs
2024-09-21 00:44:21 +12:00

68 lines
No EOL
1.8 KiB
C#

#nullable disable
using EllieBot.Modules.Gambling.Services;
using System.Numerics;
namespace EllieBot.Modules.Gambling.Common;
public abstract class GamblingModule<TService> : EllieModule<TService>
{
protected GamblingConfig Config
=> _lazyConfig.Value;
protected string CurrencySign
=> Config.Currency.Sign;
protected string CurrencyName
=> Config.Currency.Name;
private readonly Lazy<GamblingConfig> _lazyConfig;
protected GamblingModule(GamblingConfigService gambService)
=> _lazyConfig = new(() => gambService.Data);
private async Task<bool> InternalCheckBet(long amount)
{
if (amount < 1)
return false;
if (amount < Config.MinBet)
{
await Response().Error(strs.min_bet_limit(Format.Bold(Config.MinBet.ToString()) + CurrencySign)).SendAsync();
return false;
}
if (Config.MaxBet > 0 && amount > Config.MaxBet)
{
await Response().Error(strs.max_bet_limit(Format.Bold(Config.MaxBet.ToString()) + CurrencySign)).SendAsync();
return false;
}
return true;
}
protected string N<T>(T cur)
where T : INumber<T>
=> CurrencyHelper.N(cur, Culture, CurrencySign);
protected Task<bool> CheckBetMandatory(long amount)
{
if (amount < 1)
return Task.FromResult(false);
return InternalCheckBet(amount);
}
protected Task<bool> CheckBetOptional(long amount)
{
if (amount == 0)
return Task.FromResult(true);
return InternalCheckBet(amount);
}
}
public abstract class GamblingSubmodule<TService> : GamblingModule<TService>
{
protected GamblingSubmodule(GamblingConfigService gamblingConfService)
: base(gamblingConfService)
{
}
}