mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
- Removed GuildConfigs repository, moved to extensions - Moved StreamSettings extension to GuildConfig extensions - namespace NadekoBot.Core has been simplified to NadekoBot in many places (more to come) - Replaced some raw delete queries with simple linqtodb queries
69 lines
2.1 KiB
C#
69 lines
2.1 KiB
C#
using System;
|
|
using Discord;
|
|
using NadekoBot.Core.Services;
|
|
using NadekoBot.Modules;
|
|
using System.Threading.Tasks;
|
|
using NadekoBot.Modules.Gambling.Services;
|
|
|
|
namespace NadekoBot.Modules.Gambling.Common
|
|
{
|
|
public abstract class GamblingModule<TService> : NadekoModule<TService>
|
|
{
|
|
private readonly Lazy<GamblingConfig> _lazyConfig;
|
|
protected GamblingConfig _config => _lazyConfig.Value;
|
|
protected string CurrencySign => _config.Currency.Sign;
|
|
protected string CurrencyName => _config.Currency.Name;
|
|
|
|
protected GamblingModule(GamblingConfigService gambService)
|
|
{
|
|
_lazyConfig = new Lazy<GamblingConfig>(() => gambService.Data);
|
|
}
|
|
|
|
private async Task<bool> InternalCheckBet(long amount)
|
|
{
|
|
if (amount < 1)
|
|
{
|
|
return false;
|
|
}
|
|
if (amount < _config.MinBet)
|
|
{
|
|
await ReplyErrorLocalizedAsync("min_bet_limit",
|
|
Format.Bold(_config.MinBet.ToString()) + CurrencySign).ConfigureAwait(false);
|
|
return false;
|
|
}
|
|
if (_config.MaxBet > 0 && amount > _config.MaxBet)
|
|
{
|
|
await ReplyErrorLocalizedAsync("max_bet_limit",
|
|
Format.Bold(_config.MaxBet.ToString()) + CurrencySign).ConfigureAwait(false);
|
|
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)
|
|
{
|
|
}
|
|
}
|
|
}
|