Files
nadekobot/src/NadekoBot/Modules/Gambling/CurrencyEventsCommands.cs
Kwoth d5fd6aae8e - More code cleanup and codestyle updates
- Fixed some possible nullref exceptions
- Methods signatures now have up to 3 parameters before breakaing down each parameter in a separate line
- Method invocations have the same rule, except the first parameter will be in the same line as the invocation to prevent some ugliness when passing lambas as arguments
- Applied many more codestyles
- Extensions folder fully reformatted
2021-12-26 17:28:39 +01:00

74 lines
2.8 KiB
C#

using NadekoBot.Modules.Gambling.Services;
using NadekoBot.Modules.Gambling.Common.Events;
using NadekoBot.Services.Database.Models;
using NadekoBot.Modules.Gambling.Common;
namespace NadekoBot.Modules.Gambling;
public partial class Gambling
{
[Group]
public class CurrencyEventsCommands : GamblingSubmodule<CurrencyEventsService>
{
public CurrencyEventsCommands(GamblingConfigService gamblingConf) : base(gamblingConf)
{
}
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
[NadekoOptionsAttribute(typeof(EventOptions))]
[OwnerOnly]
public async Task EventStart(CurrencyEvent.Type ev, params string[] options)
{
var (opts, _) = OptionsParser.ParseFrom(new EventOptions(), options);
if (!await _service.TryCreateEventAsync(ctx.Guild.Id,
ctx.Channel.Id,
ev,
opts,
GetEmbed))
{
await ReplyErrorLocalizedAsync(strs.start_event_fail).ConfigureAwait(false);
}
}
private IEmbedBuilder GetEmbed(CurrencyEvent.Type type, EventOptions opts, long currentPot)
=> type switch
{
CurrencyEvent.Type.Reaction => _eb.Create()
.WithOkColor()
.WithTitle(GetText(strs.event_title(type.ToString())))
.WithDescription(GetReactionDescription(opts.Amount, currentPot))
.WithFooter(GetText(strs.event_duration_footer(opts.Hours))),
CurrencyEvent.Type.GameStatus => _eb.Create()
.WithOkColor()
.WithTitle(GetText(strs.event_title(type.ToString())))
.WithDescription(GetGameStatusDescription(opts.Amount, currentPot))
.WithFooter(GetText(strs.event_duration_footer(opts.Hours))),
_ => throw new ArgumentOutOfRangeException(nameof(type))
};
private string GetReactionDescription(long amount, long potSize)
{
var potSizeStr = Format.Bold(potSize == 0
? "∞" + CurrencySign
: potSize + CurrencySign);
return GetText(strs.new_reaction_event(
CurrencySign,
Format.Bold(amount + CurrencySign),
potSizeStr));
}
private string GetGameStatusDescription(long amount, long potSize)
{
var potSizeStr = Format.Bold(potSize == 0
? "∞" + CurrencySign
: potSize + CurrencySign);
return GetText(strs.new_gamestatus_event(
CurrencySign,
Format.Bold(amount + CurrencySign),
potSizeStr));
}
}
}