public async Task Close(CommandContext ctx, string type, int number) { type = type.ToLower(); if (type == "set") { await ctx.RespondAsync("Closing set and removing roles please wait..."); Set set = Matchmaker.Sets[number - 1]; List <DiscordRole> roleRemovalList = CommandHelper.DraftRoleIds.Select(e => ctx.Guild.GetRole(e)).ToList(); foreach (SdlPlayer sdlPlayer in set.AllPlayers) { await(await ctx.Guild.GetMemberAsync(sdlPlayer.DiscordId)).RemoveRolesAsync(roleRemovalList); } decimal points = await MatchModule.ReportScores(set, true); DiscordEmbed setEmbed = set.GetScoreEmbedBuilder(points, 0).Build(); await ctx.RespondAsync($"An admin has closed set number {number}.", embed : setEmbed); set.Close(); } else if (type == "lobby") { Matchmaker.Lobbies[number - 1].Close(); await ctx.RespondAsync($"An admin has closed lobby number {number}."); } else { await ctx.RespondAsync("Please specify \"set\" or \"lobby\"."); } }
public async Task Leave(CommandContext ctx) { try { if (!(ctx.User is DiscordMember user)) { return; } Lobby joinedLobby = Matchmaker.Lobbies.FirstOrDefault(e => e.Players.Any(f => f.DiscordId == user.Id)); if (joinedLobby != null) { joinedLobby.RemovePlayer(joinedLobby.Players.FirstOrDefault(e => e.DiscordId == user.Id)); await ctx.RespondAsync($"You have left lobby #{joinedLobby.LobbyNumber}."); if (joinedLobby.Players.Count == 0) { joinedLobby.Close(); await ctx.RespondAsync($"Lobby #{joinedLobby.LobbyNumber} has been disbanded."); } } else { Set joinedSet = Matchmaker.Sets.FirstOrDefault(e => e.AllPlayers.Any(f => f.DiscordId == user.Id)); if (joinedSet == null) { return; } if (ctx.Channel.Id != (await CommandHelper.ChannelFromSet(joinedSet.SetNumber)).Id) { return; } decimal penalty = MatchModule.CalculatePoints(joinedSet) / 2 + 10; string penaltyDir = Directory.CreateDirectory(Path.Combine(Globals.AppPath, "Penalties")).FullName; string penaltyFile = Path.Combine(penaltyDir, $"{user.Id}.penalty"); string penaltyMessage = $"If you leave the set, you will be instated with a penalty of {penalty} points. "; Record record; if (File.Exists(penaltyFile)) { record = JsonConvert.DeserializeObject <Record>(File.ReadAllText(penaltyFile)); int infractionCount = record.InfractionsThisMonth() + 1; switch (infractionCount) { case 1: penaltyMessage += ""; break; case 2: penaltyMessage += "In addition, you will be banned from participating in SDL for 24 hours."; break; case 3: penaltyMessage += "In addition, you will be banned from participating in SDL for 1 week."; break; default: penaltyMessage += "In addition, you will be banned from participating in SDL for 1 week AND will be barred from participating in cups."; break; } } else { penaltyMessage += " Otherwise, this time will be just a warning."; record = new Record { AllInfractions = new List <Infraction>() }; } await ctx.RespondAsync(penaltyMessage + "\nAre you sure you wish to leave the set? (Y/N)"); InteractivityModule interactivity = ctx.Client.GetInteractivityModule(); MessageContext response = await interactivity.WaitForMessageAsync(x => user.Id == x.Author.Id, TimeSpan.FromMinutes(1)); if (response == null) { await ctx.RespondAsync($"{user.Mention} took too long to respond. Assuming you changed your mind, please continue with the set."); } else if (response.Message.Content.ToLower() == "y") { decimal points = await MatchModule.ReportScores(joinedSet, true); await MySqlClient.PenalizePlayer(await MySqlClient.RetrieveSdlPlayer(user.Id), (int)penalty, "Left a set."); record.AllInfractions.Add(new Infraction { Penalty = (int)penalty, Notes = "Left a set.", TimeOfOffense = DateTime.Now }); if (joinedSet.AlphaTeam.Players.Any(e => e.DiscordId == user.Id)) { joinedSet.AlphaTeam.RemovePlayer( joinedSet.AlphaTeam.Players.First(e => e.DiscordId == user.Id)); } else if (joinedSet.BravoTeam.Players.Any(e => e.DiscordId == user.Id)) { joinedSet.BravoTeam.RemovePlayer( joinedSet.BravoTeam.Players.First(e => e.DiscordId == user.Id)); } else if (joinedSet.DraftPlayers.Any(e => e.DiscordId == user.Id)) { joinedSet.DraftPlayers.Remove( joinedSet.DraftPlayers.First(e => e.DiscordId == user.Id)); } List <DiscordMember> remainingUsers = ctx.Guild.Members.Where(x => joinedSet.AllPlayers.Any(y => y.DiscordId == x.Id)).ToList(); File.WriteAllText(penaltyFile, JsonConvert.SerializeObject(record, Formatting.Indented)); await ctx.RespondAsync( $"{user.Mention} Aforementioned penalty applied. Don't make a habit of this! " + $"As for the rest of the set, you will return to <#572536965833162753> to requeue. " + $"Beginning removal of access to this channel in 30 seconds. " + $"Rate limiting may cause the full process to take up to two minutes.", embed : joinedSet.GetScoreEmbedBuilder(points, points / 2).Build()); /*Lobby movedLobby = Matchmaker.Lobbies.First(e => !e.Players.Any()); * * if (movedLobby == null) * { * // TODO Not sure what to do if all lobbies are filled. * return; * } * * foreach (SdlPlayer joinedSetPlayer in joinedSet.AllPlayers) * { * movedLobby.AddPlayer(joinedSetPlayer, true); * }*/ joinedSet.Close(); await Task.Delay(TimeSpan.FromSeconds(30)); List <DiscordRole> roleRemovalList = CommandHelper.DraftRoleIds.Select(e => ctx.Guild.GetRole(e)).ToList(); await user.RemoveRolesAsync(roleRemovalList.Where(x => user.Roles.Select(xr => xr.Id).Contains(x.Id))); foreach (DiscordMember member in remainingUsers) { await member.RemoveRolesAsync(roleRemovalList.Where(x => member.Roles.Any(f => f.Id == x.Id))); } /*await (await ctx.Client.GetChannelAsync(572536965833162753)) * .SendMessageAsync($"{8 - movedLobby.Players.Count} players needed to begin.", * embed: movedLobby.GetEmbedBuilder().Build());*/ } else { await ctx.RespondAsync("Assuming you declined leaving since you did not reply with \"Y\". Please continue with the set."); } } } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task Kick(CommandContext ctx, DiscordMember user, bool noPenalty = false) { Lobby joinedLobby = Matchmaker.Lobbies.FirstOrDefault(e => e.Players.Any(f => f.DiscordId == user.Id)); if (joinedLobby != null) { joinedLobby.RemovePlayer(joinedLobby.Players.FirstOrDefault(e => e.DiscordId == user.Id)); await ctx.RespondAsync($"{user.Mention} has been kicked from lobby #{joinedLobby.LobbyNumber}."); if (joinedLobby.Players.Count == 0) { joinedLobby.Close(); await ctx.RespondAsync($"Lobby #{joinedLobby.LobbyNumber} has been disbanded."); } } else { Set joinedSet = Matchmaker.Sets.FirstOrDefault(e => e.AllPlayers.Any(f => f.DiscordId == user.Id)); decimal points = await MatchModule.ReportScores(joinedSet, true); if (joinedSet == null) { return; } if (!noPenalty) { string penaltyDir = Directory.CreateDirectory(Path.Combine(Globals.AppPath, "Penalties")).FullName; string penaltyFile = Path.Combine(penaltyDir, $"{user.Id}.penalty"); Record record; if (File.Exists(penaltyFile)) { record = JsonConvert.DeserializeObject <Record>(File.ReadAllText(penaltyFile)); } else { record = new Record { AllInfractions = new List <Infraction>() }; } // await AirTableClient.PenalizePlayer(user.Id, (int) (10 + points / 2), "Was kicked from a set."); record.AllInfractions.Add(new Infraction { Penalty = (int)(10 + points / 2), Notes = "Was kicked from a set.", TimeOfOffense = DateTime.Now }); File.WriteAllText(penaltyFile, JsonConvert.SerializeObject(record, Formatting.Indented)); } if (joinedSet.AlphaTeam.Players.Any(e => e.DiscordId == user.Id)) { joinedSet.AlphaTeam.RemovePlayer( joinedSet.AlphaTeam.Players.First(e => e.DiscordId == user.Id)); } else if (joinedSet.BravoTeam.Players.Any(e => e.DiscordId == user.Id)) { joinedSet.BravoTeam.RemovePlayer( joinedSet.BravoTeam.Players.First(e => e.DiscordId == user.Id)); } else if (joinedSet.DraftPlayers.Any(e => e.DiscordId == user.Id)) { joinedSet.DraftPlayers.Remove( joinedSet.DraftPlayers.First(e => e.DiscordId == user.Id)); } List <DiscordMember> remainingUsers = ctx.Guild.Members.Where(x => joinedSet.AllPlayers.Any(y => y.DiscordId == x.Id)).ToList(); await ctx.RespondAsync( $"{user.Mention} was kicked from the set. " + $"Beginning removal of access to this channel in 30 seconds. " + $"Rate limiting may cause the full process to take up to two minutes.", embed : joinedSet.GetScoreEmbedBuilder(points, 0).Build()); #region RemovedForBug /*Lobby movedLobby = Matchmaker.Lobbies.First(e => !e.Players.Any()); * * if (movedLobby == null) * { * // TODO Not sure what to do if all lobbies are filled. * return; * } * * foreach (SdlPlayer joinedSetPlayer in joinedSet.AllPlayers) * { * movedLobby.AddPlayer(joinedSetPlayer, true); * }*/ #endregion joinedSet.Close(); await Task.Delay(TimeSpan.FromSeconds(30)); List <DiscordRole> roleRemovalList = CommandHelper.DraftRoleIds.Select(e => ctx.Guild.GetRole(e)).ToList(); await user.RemoveRolesAsync(roleRemovalList.Where(x => user.Roles.Select(xr => xr.Id).Contains(x.Id))); foreach (DiscordMember member in remainingUsers) { await member.RemoveRolesAsync(roleRemovalList.Where(x => member.Roles.Any(f => f.Id == x.Id))); } #region AlsoRemoved /*await ((ITextChannel)ctx.Client.GetChannel(572536965833162753)) * .SendMessageAsync($"{8 - movedLobby.Players.Count} players needed to begin.", * embed: movedLobby.GetEmbedBuilder().Build());*/ #endregion } }