Example #1
0
 public static bool IsTorunamentInPlayStage(this IReadOnlyTournamentState tournamentState)
 {
     return(tournamentState != null &&
            (tournamentState.Stage == TournamentStage.RunningTournament ||
             tournamentState.Stage == TournamentStage.Rebracketing ||
             tournamentState.Stage == TournamentStage.Finals));
 }
Example #2
0
 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)));
 }
Example #3
0
        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
            });
        }
Example #4
0
        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);
        }
Example #5
0
 private static bool CanActAsTournamentDirector(ICommandContext context, IReadOnlyTournamentState tournament)
 {
     return(IsAdminUser(context) || tournament.IsDirector(context.User.Id));
 }
Example #6
0
 private static int GetMaximumTeamCount(IReadOnlyTournamentState currentTournament)
 {
     return(currentTournament.Readers.Count() * 2 + 1);
 }