More cleanup and restructuring, nothing of note

This commit is contained in:
Kwoth
2022-01-02 04:16:34 +01:00
parent 3428073208
commit 25f249ab5e
5 changed files with 5 additions and 10 deletions

View File

@@ -0,0 +1,59 @@
#nullable disable
using NadekoBot.Modules.Gambling.Services;
namespace NadekoBot.Modules.Gambling.Common;
public abstract class GamblingModule<TService> : NadekoModule<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 ReplyErrorLocalizedAsync(strs.min_bet_limit(Format.Bold(_config.MinBet.ToString()) + CurrencySign));
return false;
}
if (_config.MaxBet > 0 && amount > _config.MaxBet)
{
await ReplyErrorLocalizedAsync(strs.max_bet_limit(Format.Bold(_config.MaxBet.ToString()) + CurrencySign));
return false;
}
return true;
}
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)
{
}
}