예제 #1
0
        public static async Task Test()
        {
            var request     = new UserStatusRequest();
            var submissions = await request.GetUserSubmissionsAsync("handle");

            var acceptedSubmissions = submissions.Where(i => i.Verdict == SubmissionVerdict.OK);
        }
예제 #2
0
        public static async Task RunMyChild()
        {
            var request     = new UserStatusRequest();
            var submissions = await request.GetUserSubmissionsAsync("Laggy", from : 1, count : 10);

            var anotherRequest = new UserInfoRequest();
            var user           = anotherRequest.GetUserInfo("Laggy");
            var users          = await anotherRequest.GetUsersInfoAsync(new [] { "Laggy", "majk", "tourist" });

            var yetAnotherRequest = new ContestRatingChangesRequest();
            var changes           = await yetAnotherRequest.GetRatingChangesAsync(contestId : 1000);

            foreach (var change in changes)
            {
                Console.WriteLine($"{change.Handle} has got {change.NewRating - change.OldRating}");
            }
        }
예제 #3
0
        public async Task <List <KeyValuePair <int, int> > > Pick()
        {
            return(await Task.Factory.StartNew(async() =>
            {
                var users = new List <CustomUser>();
                List <KeyValuePair <int, int> > res = new List <KeyValuePair <int, int> >();
                foreach (var handle in _handles)
                {
                    var req = new UserStatusRequest();
                    var submissions = await req.GetUserSubmissionsAsync(handle, 1, 10000000);
                    if (submissions == null || submissions.Count == 0)
                    {
                        continue;
                    }

                    users.Add(new CustomUser()
                    {
                        handle = handle,
                        submissions = submissions
                    });
                }
                var result = Globals.ProblemSet.Problems.Where(c =>
                                                               users.All(u => u.submissions.All(s => c.Name != s.Problem.Name && c.ContestId != s.Problem.ContestId)));

                var contestList = new Dictionary <int, int>();

                foreach (var problem in result)
                {
                    if (!contestList.ContainsKey(problem.ContestId))
                    {
                        contestList.Add(problem.ContestId, 1);
                    }
                    else
                    {
                        contestList[problem.ContestId]++;
                    }
                }
                return contestList.ToList();
            }).Result);
        }
예제 #4
0
        public async Task SetHandle(string codeforcesHandle)
        {
            var discordInfo = Context.Message.Author.Id;

            var rndContest = RandomContestGenerator.Get();

            #region ReplyBuild

            var embed = new EmbedBuilder()
            {
                Author = new EmbedAuthorBuilder
                {
                    Name    = "Verification",
                    IconUrl =
                        "https://cdn1.iconfinder.com/data/icons/basic-ui-icon-rounded-colored/512/icon-41-512.png",
                    Url = ""
                },
                Footer = new EmbedFooterBuilder
                {
                    Text    = "You have 1 minute.",
                    IconUrl = "https://d30y9cdsu7xlg0.cloudfront.net/png/273613-200.png"
                },
                Fields = new List <EmbedFieldBuilder>
                {
                    new EmbedFieldBuilder
                    {
                        Name     = "Please visit the link below and submit a compilation error:",
                        IsInline = false,
                        Value    = $"{rndContest.Item1}"
                    }
                }
            };

            #endregion

            await ReplyAsync("", false, embed);

            await Task.Delay(60000);

            var req     = new UserStatusRequest();
            var lastSub = await req.GetUserSubmissionsAsync(codeforcesHandle, 1);

            if (lastSub == null)
            {
                await ReplyAsync("", false, Failed());

                return;
            }

            if (lastSub[0].ContestId == rndContest.Item2 && lastSub[0].Problem.Index == rndContest.Item3.ToString())
            {
                _userManager.AddUser(discordInfo, codeforcesHandle);

                #region ReplyBuild

                embed.Color  = Color.Green;
                embed.Author = new EmbedAuthorBuilder
                {
                    Name    = "Verification: Success",
                    IconUrl =
                        "https://cdn1.iconfinder.com/data/icons/basic-ui-icon-rounded-colored/512/icon-41-512.png",
                    Url = ""
                };
                embed.Footer = new EmbedFooterBuilder
                {
                    Text    = "Here, eat this.",
                    IconUrl = "https://image.flaticon.com/icons/png/128/164/164659.png"
                };
                embed.Fields = new List <EmbedFieldBuilder>
                {
                    new EmbedFieldBuilder
                    {
                        Name     = "Your codeforces handle has been set to:",
                        IsInline = false,
                        Value    = $"{codeforcesHandle}"
                    }
                };

                #endregion

                await ReplyAsync("", false, embed);

                await Task.Delay(50);

                var rating = _userManager.GetUser(discordInfo).Rating;
                var role   = Utility.RolePicker(rating);

                await _userManager.FindUser(discordInfo).AddRoleAsync(Context.Guild.Roles.First(w => w.Name == role));
            }
            else
            {
                await ReplyAsync("", false, Failed());
            }
        }