Files
nadekobot/src/NadekoBot/Modules/Gambling/CurrencyEventsCommands.cs
Kwoth 15dac7e3ed Massive cleanup
- 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
2021-09-06 21:34:41 +02:00

94 lines
3.6 KiB
C#

using Discord;
using Discord.Commands;
using NadekoBot.Extensions;
using System.Threading.Tasks;
using NadekoBot.Common.Attributes;
using NadekoBot.Modules.Gambling.Services;
using NadekoBot.Modules.Gambling.Common.Events;
using System;
using NadekoBot.Core.Common;
using NadekoBot.Core.Services.Database.Models;
using NadekoBot.Modules.Gambling.Common;
namespace NadekoBot.Modules.Gambling
{
public partial class Gambling
{
[Group]
public class CurrencyEventsCommands : GamblingSubmodule<CurrencyEventsService>
{
public enum OtherEvent
{
BotListUpvoters
}
public CurrencyEventsCommands(GamblingConfigService gamblingConf) : base(gamblingConf)
{
}
[NadekoCommand, Usage, Description, 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
).ConfigureAwait(false))
{
await ReplyErrorLocalizedAsync("start_event_fail").ConfigureAwait(false);
return;
}
}
private EmbedBuilder GetEmbed(CurrencyEvent.Type type, EventOptions opts, long currentPot)
{
switch (type)
{
case CurrencyEvent.Type.Reaction:
return new EmbedBuilder()
.WithOkColor()
.WithTitle(GetText("event_title", type.ToString()))
.WithDescription(GetReactionDescription(opts.Amount, currentPot))
.WithFooter(GetText("event_duration_footer", opts.Hours));
case CurrencyEvent.Type.GameStatus:
return new EmbedBuilder()
.WithOkColor()
.WithTitle(GetText("event_title", type.ToString()))
.WithDescription(GetGameStatusDescription(opts.Amount, currentPot))
.WithFooter(GetText("event_duration_footer", opts.Hours));
default:
break;
}
throw new ArgumentOutOfRangeException(nameof(type));
}
private string GetReactionDescription(long amount, long potSize)
{
string potSizeStr = Format.Bold(potSize == 0
? "∞" + CurrencySign
: potSize.ToString() + CurrencySign);
return GetText("new_reaction_event",
CurrencySign,
Format.Bold(amount + CurrencySign),
potSizeStr);
}
private string GetGameStatusDescription(long amount, long potSize)
{
string potSizeStr = Format.Bold(potSize == 0
? "∞" + CurrencySign
: potSize.ToString() + CurrencySign);
return GetText("new_gamestatus_event",
CurrencySign,
Format.Bold(amount + CurrencySign),
potSizeStr);
}
}
}
}