public static bool IsTorunamentInPlayStage(this IReadOnlyTournamentState tournamentState) { return(tournamentState != null && (tournamentState.Stage == TournamentStage.RunningTournament || tournamentState.Stage == TournamentStage.Rebracketing || tournamentState.Stage == TournamentStage.Finals)); }
private static bool HasTournamentDirectorPrivileges( IReadOnlyTournamentState currentTournament, IGuildChannel channel, IGuildUser user) { // TD is only allowed to run commands when they are a director of the current tournament. return(currentTournament.GuildId == channel.GuildId && (IsAdminUser(channel, user) || currentTournament.IsDirector(user.Id))); }
private TournamentRoles GetTournamentRoles(IReadOnlyTournamentState state) { IRole directorRole = this.Guild.GetRole(state.TournamentRoles.DirectorRoleId); Dictionary <Reader, IRole> roomReaderRoles = state.TournamentRoles.ReaderRoomRoleIds .ToDictionary(kvp => kvp.Key, kvp => this.Guild.GetRole(kvp.Value)); Dictionary <Team, IRole> teamRoles = state.TournamentRoles.TeamRoleIds .ToDictionary(kvp => kvp.Key, kvp => this.Guild.GetRole(kvp.Value)); return(new TournamentRoles() { DirectorRole = directorRole, RoomReaderRoles = roomReaderRoles, TeamRoles = teamRoles }); }
private Player GetPlayerFromReactionEventOrNull( IReadOnlyTournamentState currentTournament, IGuildUser user, ulong messageId, string emojiName, out string errorMessage) { errorMessage = null; if (currentTournament == null || !currentTournament.IsJoinTeamMessage(messageId) || !currentTournament.TryGetTeamFromSymbol(emojiName, out Team team)) { // Ignore reactions added/removed from non-team messages. return(null); } // TODO: since we have the message ID it's unlikely we need to verify the guild, but we should double check. if (user.Id == this.Client.CurrentUser.Id) { errorMessage = BotStrings.BotCannotJoinAsPlayer; return(null); } ulong userId = user.Id; if (currentTournament.IsDirector(userId)) { errorMessage = BotStrings.TournamentDirectorCannotJoinAsPlayer; return(null); } if (currentTournament.IsReader(userId)) { errorMessage = BotStrings.ReaderCannotJoinAsPlayer; return(null); } Player player = new Player() { Id = userId, Team = team }; return(player); }
private static bool CanActAsTournamentDirector(ICommandContext context, IReadOnlyTournamentState tournament) { return(IsAdminUser(context) || tournament.IsDirector(context.User.Id)); }
private static int GetMaximumTeamCount(IReadOnlyTournamentState currentTournament) { return(currentTournament.Readers.Count() * 2 + 1); }