public async Task ExecuteGroupAsync(CommandContext ctx) { if (this.Service.IsEventRunningInChannel(ctx.Channel.Id)) { if (this.Service.GetEventInChannel(ctx.Channel.Id) is AnimalRace) { await this.JoinAsync(ctx); } else { throw new CommandFailedException(ctx, "cmd-err-evt-dup"); } return; } var game = new AnimalRace(ctx.Client.GetInteractivity(), ctx.Channel); this.Service.RegisterEventInChannel(game, ctx.Channel.Id); try { await ctx.ImpInfoAsync(this.ModuleColor, Emojis.Clock1, "str-game-ar-start", AnimalRace.MaxParticipants); await this.JoinAsync(ctx); await Task.Delay(TimeSpan.FromSeconds(30)); if (game.ParticipantCount > 1) { GameStatsService gss = ctx.Services.GetRequiredService <GameStatsService>(); await game.RunAsync(this.Localization); if (game.WinnerIds is { }) { await Task.WhenAll(game.WinnerIds.Select(w => gss.UpdateStatsAsync(w, s => s.AnimalRacesWon++))); } }
public async Task ExecuteGroupAsync(CommandContext ctx) { if (this.Shared.IsEventRunningInChannel(ctx.Channel.Id)) { if (this.Shared.GetEventInChannel(ctx.Channel.Id) is AnimalRace) { await this.JoinAsync(ctx); } else { throw new CommandFailedException("Another event is already running in the current channel."); } return; } var game = new AnimalRace(ctx.Client.GetInteractivity(), ctx.Channel); this.Shared.RegisterEventInChannel(game, ctx.Channel.Id); try { await this.InformAsync(ctx, StaticDiscordEmoji.Clock1, $"The race will start in 30s or when there are 10 participants. Use command {Formatter.InlineCode("game animalrace")} to join the race."); await this.JoinAsync(ctx); await Task.Delay(TimeSpan.FromSeconds(30)); if (game.ParticipantCount > 1) { await game.RunAsync(); foreach (ulong uid in game.WinnerIds) { await this.Database.UpdateStatsAsync(uid, s => s.AnimalRacesWon++); } } else { await this.InformAsync(ctx, StaticDiscordEmoji.AlarmClock, "Not enough users joined the race."); } } finally { this.Shared.UnregisterEventInChannel(ctx.Channel.Id); } }