Ejemplo n.º 1
0
        private static bool TryGetEmojis(int count, out IEmote[] emotes, out string errorMessage)
        {
            emotes       = null;
            errorMessage = null;

            const int emojiLimit = 9 + 26;

            if (count < 0)
            {
                errorMessage = BotStrings.NumberOfTeamsMustBeGreaterThanZero;
                return(false);
            }
            else if (count > emojiLimit)
            {
                errorMessage = BotStrings.TooManyTeams(emojiLimit);
                return(false);
            }

            emotes = new IEmote[count];
            int numberLoopLimit = Math.Min(9, count);

            // Encoding.Unicode.GetString(new byte[] { 49, 0, 227, 32 }) to Encoding.Unicode.GetString(new byte[] { 58, 0, 227, 32 }) is 1-9
            byte[] numberBlock = { 49, 0, 227, 32 };
            int    i           = 0;

            for (; i < numberLoopLimit; i++)
            {
                emotes[i]       = new Emoji(Encoding.Unicode.GetString(numberBlock));
                numberBlock[0] += 1;
            }

            // Encoding.Unicode.GetString(new byte[] { 60, 216, 230, 221 }) to Encoding.Unicode.GetString(new byte[] { 60, 216, 255, 221 }) is A-Z
            byte[] letterBlock = new byte[] { 60, 216, 230, 221 };
            for (; i < count; i++)
            {
                emotes[i]       = new Emoji(Encoding.Unicode.GetString(letterBlock));
                letterBlock[2] += 1;
            }

            return(true);
        }
Ejemplo n.º 2
0
        // TODO: Make string message and IGuildChannel?
        private async Task HandleAddTeamsStage(ITournamentState currentTournament, SocketMessage message)
        {
            if (!TeamsParser.TryParseTeams(message.Content, out IEnumerable <Team> teams, out string errorMessage))
            {
                await message.Channel.SendMessageAsync(errorMessage, options : RequestOptionsSettings.Default);

                this.Logger.Debug("Team names could not be parsed. Error message: {errorMessage}", errorMessage);
                return;
            }

            currentTournament.AddTeams(teams);

            int teamsCount = currentTournament.Teams.Count();

            if (teamsCount < 2)
            {
                await message.Channel.SendMessageAsync(
                    BotStrings.MustBeTwoTeamsPerTournament, options : RequestOptionsSettings.Default);

                currentTournament.RemoveTeams(teams);
                this.Logger.Debug("Too few teams specified in AddTeams stage ({0})", teamsCount);
                return;
            }

            int maxTeamsCount = GetMaximumTeamCount(currentTournament);

            if (teamsCount > maxTeamsCount)
            {
                currentTournament.TryClearTeams();
                await message.Channel.SendMessageAsync(
                    BotStrings.TooManyTeams(maxTeamsCount), options : RequestOptionsSettings.Default);

                this.Logger.Debug("Too many teams specified in AddTeams stage ({0})", teamsCount);
                return;
            }

            if (!TryGetEmojis(teamsCount, out IEmote[] emotes, out errorMessage))