private static async Task <bool> LostUsers(BanroyaleGame br, IEnumerable <SocketGuildUser> users) { if (users.Count() == 0) { return(false); } var failed = new List <SocketGuildUser>(); string desc = "These users lose: "; var tasks = new List <Task>(); foreach (var user in users) { try { if (br.Banroyale.BanLengthHours > 0) { tasks.Add(user.BanAsync()); } else if (br.Banroyale.Kick) { tasks.Add(user.KickAsync()); } else { tasks.Add(user.RemoveRoleAsync(br.Role)); } desc += user.Mention + " "; } catch { failed.Add(user); desc += $"({user.Mention} - failed to kick from the game, user too powerful) "; } } await Task.WhenAll(tasks); desc += "\nStill in the game: "; var remainingUsers = br.Role.Members.Where(x => !users.Contains(x)); foreach (var user in remainingUsers) { desc += user.Mention + " "; } await br.Channel.SendMessageAsync(embed : new EmbedBuilderPrepared(desc).WithTitle("Ban Royale - Round Results") .WithColor(Color.DarkRed) .Build()); return(await EndBanroyale(br, remainingUsers)); }
private static async Task <bool> EndBanroyale(BanroyaleGame br, IEnumerable <SocketGuildUser> users) { if (users.Count() <= br.Banroyale.WinnerAmount) { br.Timer.Stop(); br.Timer.Close(); await BanroyaleDb.EndBanroyale(br.Banroyale.Id); string desc = "Winners: "; int split = 0; if (br.Role.Members.Count() == 0) { desc += "Everyone lost! Well done guys, I'm proud of you."; } else { split = br.Banroyale.RewardPool / users.Count(); foreach (var user in users) { _ = BalanceDb.AddToasties(user.Id, split, br.Banroyale.GuildId); _ = user.RemoveRoleAsync(br.Role); desc += user.Mention + " "; } } if (split > 0) { desc += $"\nSplitting **{br.Banroyale.RewardPool}** toasties from the reward pool! ({split} each)"; } await br.Channel.SendMessageAsync(embed : new EmbedBuilderPrepared(desc).WithTitle("Ban Royale Over!") .WithColor(Color.Gold) .Build()); return(true); } return(false); }
public async Task StartBanroyale([Remainder] string str = "") { var banroyale = await BanroyaleDb.GetBanroyale(Context.Channel.Id); if (banroyale == null) { await Context.Channel.SendMessageAsync(":x: There is no running Ban Royale in this channel."); return; } if (banroyale.Running == true) { await Context.Channel.SendMessageAsync(":x: The Ban Royale has already started."); return; } banroyale.Running = true; await BanroyaleDb.UpdateBanroyale(banroyale); var br = new BanroyaleGame(banroyale, Context.Channel, Context.Guild.GetRole(banroyale.ParticipantRoleId)); await ReplyAsync($"Starting Ban Royale! I will send a new message every **{banroyale.MinFrequency}-{banroyale.MaxFrequency}s** and leave a reaction on them. The last users to click these reactions will lose!"); }