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; } }
public async Task <bool> TryCreateEventAsync(ulong guildId, ulong channelId, CurrencyEvent.Type type, EventOptions opts, Func <CurrencyEvent.Type, EventOptions, long, EmbedBuilder> embed) { SocketGuild g = _client.GetGuild(guildId); SocketTextChannel ch = g?.GetChannel(channelId) as SocketTextChannel; if (ch == null) { return(false); } ICurrencyEvent ce; if (type == CurrencyEvent.Type.Reaction) { ce = new ReactionEvent(_client, _cs, _bc, g, ch, opts, embed); } //else if (type == Event.Type.NotRaid) //{ // ce = new NotRaidEvent(_client, _cs, _bc, g, ch, opts, embed); //} else { return(false); } var added = _events.TryAdd(guildId, ce); if (added) { try { ce.OnEnded += OnEventEnded; await ce.StartEvent().ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); _events.TryRemove(guildId, out ce); return(false); } } return(added); }
public async Task <bool> TryCreateEventAsync(ulong guildId, ulong channelId, CurrencyEvent.Type type, EventOptions opts, Func <CurrencyEvent.Type, EventOptions, long, EmbedBuilder> embed) { SocketGuild g = _client.GetGuild(guildId); SocketTextChannel ch = g?.GetChannel(channelId) as SocketTextChannel; if (ch == null) { return(false); } ICurrencyEvent ce; if (type == CurrencyEvent.Type.Reaction) { ce = new ReactionEvent(_client, _cs, g, ch, opts, _configService.Data, embed); } else if (type == CurrencyEvent.Type.GameStatus) { ce = new GameStatusEvent(_client, _cs, g, ch, opts, embed); } else { return(false); } var added = _events.TryAdd(guildId, ce); if (added) { try { ce.OnEnded += OnEventEnded; await ce.StartEvent().ConfigureAwait(false); } catch (Exception ex) { Log.Warning(ex, "Error starting event"); _events.TryRemove(guildId, out ce); return(false); } } return(added); }
private EmbedBuilder GetEmbed(CurrencyEvent.Type type, EventOptions opts, long currentPot) { switch (type) { case CurrencyEvent.Type.Reaction: return(new EmbedBuilder() .WithOkColor() .WithTitle(GetText("reaction_title")) .WithDescription(GetReactionDescription(opts.Amount, currentPot)) .WithFooter(GetText("new_reaction_footer", opts.Hours))); //case Event.Type.NotRaid: // return new EmbedBuilder() // .WithOkColor() // .WithTitle(GetText("notraid_title")) // .WithDescription(GetNotRaidDescription(opts.Amount, currentPot)) // .WithFooter(GetText("notraid_footer", opts.Hours)); default: break; } throw new ArgumentOutOfRangeException(nameof(type)); }
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)); }