Esempio n. 1
0
        public static JObject CreateGift(int score, CourseSettings settings)
        {
            var title    = score >= settings.masterScore ? settings.masterTitle : settings.passTitle;
            var subtitle = string.Format(
                settings.subtitle,
                Pluralize(score, "балл", "балла", "баллов"),
                Pluralize(settings.maxScore, "возможного", "возможных", "возможных"));

            return(JObject.Parse(
                       $@"{{
	""entry"": {{
		""$type"": ""gift"",
		""from"": {{
			""id"": ""1253"",
			""name"": ""Егоров Павел Владимирович"",
			""type"": 1
		}},
		""message"": ""{settings.message}"",
		""anonymously"": true,
		""giftImagePath"": ""{settings.giftImagePath}"",
		""title"": ""{title}"",
		""subtitle"": ""{subtitle}""
	}},
	""options"": {{
		""postAsOwner"": false
	}}
}}"));
        }
Esempio n. 2
0
        private void EnsureHaveGifts(List <RatingEntry> entries, CourseSettings courseSettings, string courseId)
        {
            int delayMs = settings["delayBetweenStaffRequests"].Value <int>();
            var granted = 0;

            foreach (var ratingEntry in entries)
            {
                if (granted >= maxGiftsPerRun)
                {
                    log.Info($"GiftGrantsLimitPerRunExceeded\t{maxGiftsPerRun}");
                    return;
                }
                if (GrantGiftsIfNone(ratingEntry, courseSettings, courseId))
                {
                    granted++;
                }
                Thread.Sleep(delayMs);
            }
        }
Esempio n. 3
0
        private bool GrantGiftsIfNone(RatingEntry entry, CourseSettings courseSettings, string courseId)
        {
            string sid           = entry.User.Logins.First(login => login.LoginProvider == "Контур.Паспорт").ProviderKey;
            var    staffUserId   = staffClient.GetUser(sid)["id"].Value <int>();
            var    gifts         = staffClient.GetUserGifts(staffUserId);
            var    giftImagePath = courseSettings.giftImagePath;

            bool hasComplexityGift = gifts["entries"].Children().Any(gift => gift["giftImagePath"].Value <string>() == giftImagePath);

            if (!hasComplexityGift)
            {
                log.Info($"NoGiftYet\t{entry.Score}\t{entry.User.VisibleName}");
                staffClient.GrantGift(staffUserId, entry.Score, courseSettings);
                log.Info($"ComplexityGiftGrantedFor\t{entry.User.VisibleName}\t{entry.User.KonturLogin}");
                telegramBot.PostToChannel($"Granted gift for course {courseId}\n{entry.Score} points for user {entry.User.VisibleName} {entry.User.KonturLogin}");
                return(true);
            }
            return(false);
        }
Esempio n. 4
0
        public JObject GrantGift(int staffUserId, int score, CourseSettings courseSettings)
        {
            var gift = GiftsFactory.CreateGift(score, courseSettings);

            return(Post($"feed/user_{staffUserId}", gift));
        }