static private async Task <Result> GetBdsmResultAsync(string link, IConfiguration config) { var testResultMatch = BdsmModule.TestResultLinkRegex.Match(link); if (!testResultMatch.Success) { throw new ArgumentException(null, nameof(link)); } var testid = testResultMatch.Groups[1].Value; var bdsmSettings = new BdsmTestOrgSettings(config); var requestData = new Dictionary <string, string> { { "uauth[uid]", bdsmSettings.ApiKey.Uid }, { "uauth[salt]", bdsmSettings.ApiKey.Salt }, { "uauth[authsig]", bdsmSettings.ApiKey.AuthSig }, { "rauth[rid]", testid } }; var response = await new HttpClient().PostAsync( "https://bdsmtest.org/ajax/getresult", new FormUrlEncodedContent(requestData)); var responseData = await response.Content.ReadAsStringAsync(); var testResult = JsonConvert.DeserializeObject <Result>(responseData); return(testResult); }
public UserBdsmTraitsService(DatabaseFactory databaseFactory, BdsmTestOrgSettings settings, BdsmTraitOperationCheckTranslations checkTranslations, IMemoryCache cache, UsersService usersService) { DatabaseFactory = databaseFactory; Settings = settings; CheckTranslations = checkTranslations; Cache = cache; UsersService = usersService; }
static public EmbedBuilder WithBdsmTestOrgQuizResult(this EmbedBuilder builder, BdsmTestOrgSettings settings, BdsmTestOrgResult quizResult) { if (quizResult is null) { throw new ArgumentNullException(nameof(quizResult)); } builder.WithTitle(quizResult.Link) .WithColor(new Color(0, 0, 0)) .WithUrl(quizResult.Link) .WithTimestamp(quizResult.SubmittedAt) .WithFooter("BDSMTest.org"); var relevantItems = quizResult.Items .Where(i => i.Score >= settings.StrongTraitThreshold) .OrderByDescending(i => i.Score) .ToList(); if (relevantItems.Count == 0) { builder.WithDescription(settings.NoTraitsToReportMessage); } foreach (var relevantItem in relevantItems) { builder.AddField(relevantItem.Trait.GetDisplayName(), $"{relevantItem.Score:P0}"); } return(builder); }
static public EmbedBuilder WithBdsmTestOrgQuizInvitation(this EmbedBuilder builder, BdsmTestOrgSettings settings, IUser user) { return(builder.WithTitle(settings.TestLinkUrl) .WithColor(new Color(0, 0, 0)) .WithUrl(settings.TestLinkUrl) .WithDescription(settings.NoResultsOnRecordMessage) .WithFooter("BDSMTest.org")); }