コード例 #1
0
        public async Task Top(int page = 1)
        {
            page--;

            var currentUserStatistics = await _statisticsRepository.GetUserStatistics(Context.Guild.Id, Context.User.Id);

            var pagedUsers = await _statisticsRepository.GetStatistics(Context.Guild.Id, page);

            var totalUsers = (Context.Guild as SocketGuild).MemberCount;

            var guildMembers = await Context.Guild.GetUsersAsync();


            var formatFields = from sUser in pagedUsers
                               join gUser in guildMembers on sUser.UserId equals gUser.Id into users
                               from gUser in users.DefaultIfEmpty()
                               select new string[2] {
                gUser == null ? $"Użytkownik opuścił serwer ID: {sUser.UserId}" : Formatters.GetUserName(gUser), sUser.Score.ToString()
            };

            if (!formatFields.Any())
            {
                await ReplyImage(description : $"Brak użytkowników na pozycjach {page * 10 + 1} - {page * 10 + 10}");

                return;
            }

            int rownum = 1;

            var lines = from field in formatFields
                        select string.Format("[{0}]", (page * 10) + rownum ++).PadRight(12) + "> " +
                        $"#{field[0]}\n" +
                        $"Całkowity wynik:".PadLeft(32) + $" {field[1]}";

            var sb = new StringBuilder();

            sb.Append($"Ranking użytkowników serwera {Context.Guild.Name}\n\n");
            sb.Append(string.Join("\n", lines));
            sb.Append('\n');
            sb.Append(string.Concat(Enumerable.Repeat('-', 40)));
            //sb.Append($"\nTwoje miejsce w rankingu: {guildUsers.TakeWhile(x => x.UserId != Context.User.Id).Count() + 1} / {totalUsers}\n");
            sb.Append($"Całkowity wynik: {currentUserStatistics.Score}");
            await ReplyImage(description : $"```CS\n{sb.ToString()}```");
        }
コード例 #2
0
        private Statistics GetStatistics()
        {
            AesEncryption aes = new AesEncryption();

            byte[] key = aes.GenerateRandomNumber(32);
            byte[] iv  = aes.GenerateRandomNumber(16);

            // Gets the statistics encrypted
            byte[] encryptedData = StatisticsRepository.GetStatistics(key, iv, _carwashId);
            // Decrypts the data
            byte[] decryptedData = aes.Decrypt(encryptedData, key, iv);

            // Makes the byte array into a string
            string decryptedJson = Encoding.UTF8.GetString(decryptedData);
            // Deserializes the json string
            Statistics statistics = JsonHelper.DeserializeJson <Statistics>(decryptedJson);

            return(statistics);
        }