Exemple #1
0
        public EPService(DiscordSocketClient c)
        {
            client = c;
            InitializeLoader();
            LoadDatabase();
            LoadDatabaseGuild();
            LoadDatabaseBG();

            ProfileImageProcessing.Initialize();
        }
Exemple #2
0
        private async Task DrawProfile(String AvatarUrl, IUser userInfo, SocketCommandContext Context)
        {
            if (String.IsNullOrEmpty(AvatarUrl))
                AvatarUrl =
                    "http://is2.mzstatic.com/image/pf/us/r30/Purple7/v4/89/51/05/89510540-66df-9f6f-5c91-afa5e48af4e8/mzl.sbwqpbfh.png";

            Uri requestUri = new Uri(AvatarUrl);

            if (File.Exists($"{userInfo.Id}Avatar.png"))
            {
                File.Delete($"{userInfo.Id}Avatar.png");
            }

            using (var client = new HttpClient())
            using (var request = new HttpRequestMessage(HttpMethod.Get, requestUri))
            using (
                Stream contentStream = await (await client.SendAsync(request)).Content.ReadAsStreamAsync(),
                    stream = new FileStream($"{userInfo.Id}Avatar.png", FileMode.Create, FileAccess.Write,
                        FileShare.None, 3145728, true))
            {
                await contentStream.CopyToAsync(stream);
                await contentStream.FlushAsync();
                contentStream.Dispose();
                await stream.FlushAsync();
                stream.Dispose();
                Console.WriteLine("DONE STREAM");
            }

            var username = userInfo.Username;
            if (userInfo.Username.Length > 20)
            {
                username = userInfo.Username.Remove(20) + "...";
            }



            //GET RANK

            var guild = ((SocketGuild)Context.Guild);
            //guild.DownloadUsersAsync();

            if (guild.MemberCount < 200)
            {
                guild.DownloadUsersAsync().Wait();
                //await guild.DownloadUsersAsync();
            }

            //FEED LIST
            Dictionary<ulong, float> epList = new Dictionary<ulong, float>();
            foreach (var u in guild.Users)
            {
                if (!u.IsBot && userEPDict.ContainsKey(u.Id))
                {
                    userStruct str = new userStruct();
                    userEPDict.TryGetValue(u.Id, out str);
                    if (!epList.ContainsKey(u.Id))
                    {
                        epList.Add(u.Id, str.ep);
                    }
                }
            }

            //GETLIST
            var sortedList = epList.OrderByDescending(pair => pair.Value)
                .ToDictionary(pair => pair.Key, pair => pair.Value);
            var rank = GetIndex(sortedList, userInfo.Id) + 1;
            //END RANK

            userStruct user = new userStruct();
            if (userEPDict.ContainsKey(userInfo.Id))
            {
                userEPDict.TryGetValue(userInfo.Id, out user);
            }
            else
            {
                user.ep = 0;
                user.level = 0;
            }
            
            ProfileImageProcessing.GenerateProfile($"{userInfo.Id}Avatar.png", username, rank, user.level, (int)user.ep, $"{userInfo.Id}.png");
        }