Skip to content

Commit

Permalink
Refactored more of RuriLib's code
Browse files Browse the repository at this point in the history
  • Loading branch information
openbullet committed Dec 15, 2024
1 parent 035712a commit 993d7b4
Show file tree
Hide file tree
Showing 46 changed files with 1,486 additions and 583 deletions.
91 changes: 87 additions & 4 deletions RuriLib/Blocks/Captchas/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@

namespace RuriLib.Blocks.Captchas;

/// <summary>
/// Methods for solving captchas.
/// </summary>
[BlockCategory("Captchas", "Blocks for solving captchas", "#7df9ff")]
public static class Methods
{
/// <summary>
/// Solves a text captcha.
/// </summary>
[Block("Solves a text captcha")]
public static async Task<string> SolveTextCaptcha(BotData data,
[BlockParam("Question", "The description of the captcha to solve, e.g. What is 2+2?")] string question,
Expand All @@ -35,6 +41,9 @@ public static async Task<string> SolveTextCaptcha(BotData data,
return response.Response;
}

/// <summary>
/// Solves an image captcha.
/// </summary>
[Block("Solves an image captcha")]
public static async Task<string> SolveImageCaptcha(BotData data, string base64,
CaptchaLanguageGroup languageGroup = CaptchaLanguageGroup.NotSpecified,
Expand Down Expand Up @@ -64,6 +73,9 @@ public static async Task<string> SolveImageCaptcha(BotData data, string base64,
return response.Response;
}

/// <summary>
/// Solves a ReCaptcha v2.
/// </summary>
[Block("Solves a ReCaptcha v2")]
public static async Task<string> SolveRecaptchaV2(BotData data, string siteKey, string siteUrl,
string sData = "", bool enterprise = false, bool isInvisible = false, bool useProxy = false,
Expand All @@ -80,11 +92,16 @@ public static async Task<string> SolveRecaptchaV2(BotData data, string siteKey,
return response.Response;
}

// For backwards compatibility
/// <summary>
/// Solves a ReCaptcha v2 (backwards compatibility).
/// </summary>
public static Task<string> SolveRecaptchaV2(BotData data, string siteKey, string siteUrl, bool isInvisible = false, bool useProxy = false,
string userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36")
=> SolveRecaptchaV2(data, siteKey, siteUrl, "", false, isInvisible, useProxy, userAgent);

/// <summary>
/// Solves a ReCaptcha v3.
/// </summary>
[Block("Solves a ReCaptcha v3")]
public static async Task<string> SolveRecaptchaV3(BotData data, string siteKey, string siteUrl, string action,
float minScore = 0.3F, bool enterprise = false, bool useProxy = false,
Expand All @@ -101,11 +118,16 @@ public static async Task<string> SolveRecaptchaV3(BotData data, string siteKey,
return response.Response;
}

// For backwards compatibility
/// <summary>
/// Solves a ReCaptcha v3 (backwards compatibility).
/// </summary>
public static Task<string> SolveRecaptchaV3(BotData data, string siteKey, string siteUrl, string action, float minScore = 0.3F, bool useProxy = false,
string userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36")
=> SolveRecaptchaV3(data, siteKey, siteUrl, action, minScore, false, useProxy, userAgent);

/// <summary>
/// Solves a FunCaptcha.
/// </summary>
[Block("Solves a FunCaptcha")]
public static async Task<string> SolveFunCaptcha(BotData data, string publicKey, string serviceUrl, string siteUrl,
bool noJS = false, string? extraData = null, bool useProxy = false,
Expand All @@ -122,12 +144,17 @@ public static async Task<string> SolveFunCaptcha(BotData data, string publicKey,
return response.Response;
}

// For backwards compatibility
/// <summary>
/// Solves a FunCaptcha (backwards compatibility).
/// </summary>
public static async Task<string> SolveFunCaptcha(BotData data, string publicKey, string serviceUrl, string siteUrl,
bool noJS = false, bool useProxy = false,
string userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36")
=> await SolveFunCaptcha(data, publicKey, serviceUrl, siteUrl, noJS, extraData: null, useProxy, userAgent);

/// <summary>
/// Solves a HCaptcha.
/// </summary>
[Block("Solves a HCaptcha")]
public static async Task<string> SolveHCaptcha(BotData data, string siteKey, string siteUrl,
string? enterprisePayload = null, bool isInvisible = false, bool useProxy = false,
Expand All @@ -144,12 +171,17 @@ public static async Task<string> SolveHCaptcha(BotData data, string siteKey, str
return response.Response;
}

// For backwards compatibility
/// <summary>
/// Solves a HCaptcha (backwards compatibility).
/// </summary>
public static async Task<string> SolveHCaptcha(BotData data, string siteKey, string siteUrl,
bool useProxy = false,
string userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36")
=> await SolveHCaptcha(data, siteKey, siteUrl, enterprisePayload: null, isInvisible: false, useProxy, userAgent);

/// <summary>
/// Solves a KeyCaptcha.
/// </summary>
[Block("Solves a KeyCaptcha")]
public static async Task<string> SolveKeyCaptcha(BotData data, string userId, string sessionId,
string webServerSign1, string webServerSign2, string siteUrl, bool useProxy = false,
Expand All @@ -166,6 +198,9 @@ public static async Task<string> SolveKeyCaptcha(BotData data, string userId, st
return response.Response;
}

/// <summary>
/// Solves a GeeTest v3 captcha.
/// </summary>
[Block("Solves a GeeTest v3 captcha",
extraInfo = "The response will be a list and its elements are (in order) challenge, validate, seccode")]
public static async Task<List<string>> SolveGeeTestCaptcha(BotData data, string gt, string apiChallenge,
Expand All @@ -186,6 +221,9 @@ public static async Task<List<string>> SolveGeeTestCaptcha(BotData data, string
return [response.Challenge, response.Validate, response.SecCode];
}

/// <summary>
/// Solves a Capy captcha.
/// </summary>
[Block("Solves a Capy captcha")]
public static async Task<List<string>> SolveCapyCaptcha(BotData data, string siteKey, string siteUrl,
bool useProxy = false,
Expand All @@ -205,6 +243,9 @@ public static async Task<List<string>> SolveCapyCaptcha(BotData data, string sit
return [response.ChallengeKey, response.CaptchaKey, response.Answer];
}

/// <summary>
/// Solves a DataDome captcha.
/// </summary>
[Block("Solves a DataDome captcha")]
public static async Task<string> SolveDataDomeCaptcha(BotData data, string captchaUrl, string siteUrl,
bool useProxy = false,
Expand All @@ -221,6 +262,9 @@ public static async Task<string> SolveDataDomeCaptcha(BotData data, string captc
return response.Response;
}

/// <summary>
/// Solves a Cloudflare Turnstile captcha.
/// </summary>
[Block("Solves a Cloudflare Turnstile captcha")]
public static async Task<string> SolveCloudflareTurnstileCaptcha(BotData data, string siteKey, string siteUrl,
string? action = null, string? cData = null, string? pageData = null, bool useProxy = false,
Expand All @@ -238,6 +282,9 @@ public static async Task<string> SolveCloudflareTurnstileCaptcha(BotData data, s
return response.Response;
}

/// <summary>
/// Solves a Lemin Cropped captcha.
/// </summary>
[Block("Solves a Lemin Cropped captcha",
extraInfo = "The response will be a list and its elements are (in order) answer, challenge ID")]
public static async Task<List<string>> SolveLeminCroppedCaptcha(BotData data, string captchaId, string siteUrl,
Expand All @@ -258,6 +305,9 @@ public static async Task<List<string>> SolveLeminCroppedCaptcha(BotData data, st
return [response.Answer, response.ChallengeId];
}

/// <summary>
/// Solves an Amazon WAF captcha.
/// </summary>
[Block("Solves an Amazon WAF captcha")]
public static async Task<string> SolveAmazonWafCaptcha(BotData data, string siteKey, string siteUrl,
string iv, string context, string? challengeScript = null, string? captchaScript = null, bool useProxy = false,
Expand All @@ -275,6 +325,9 @@ public static async Task<string> SolveAmazonWafCaptcha(BotData data, string site
return response.Response;
}

/// <summary>
/// Solves a Cyber SiARA captcha.
/// </summary>
[Block("Solves a Cyber SiARA captcha")]
public static async Task<string> SolveCyberSiAraCaptcha(BotData data, string masterUrlId, string siteUrl,
bool useProxy = false,
Expand All @@ -292,6 +345,9 @@ public static async Task<string> SolveCyberSiAraCaptcha(BotData data, string mas
return response.Response;
}

/// <summary>
/// Solves a MT captcha.
/// </summary>
[Block("Solves an MT captcha")]
public static async Task<string> SolveMtCaptcha(BotData data, string siteKey, string siteUrl,
bool useProxy = false, string userAgent =
Expand All @@ -308,6 +364,9 @@ public static async Task<string> SolveMtCaptcha(BotData data, string siteKey, st
return response.Response;
}

/// <summary>
/// Solves a CapMonster captcha.
/// </summary>
[Block("Solves a CutCaptcha")]
public static async Task<string> SolveCutCaptcha(BotData data, string miseryKey, string apiKey, string siteUrl,
bool useProxy = false, string userAgent =
Expand All @@ -324,6 +383,9 @@ public static async Task<string> SolveCutCaptcha(BotData data, string miseryKey,
return response.Response;
}

/// <summary>
/// Solves a Friendly captcha.
/// </summary>
[Block("Solves a Friendly captcha")]
public static async Task<string> SolveFriendlyCaptcha(BotData data, string siteKey, string siteUrl,
bool useProxy = false, string userAgent =
Expand All @@ -340,6 +402,9 @@ public static async Task<string> SolveFriendlyCaptcha(BotData data, string siteK
return response.Response;
}

/// <summary>
/// Solves an ATB captcha.
/// </summary>
[Block("Solves an atb captcha")]
public static async Task<string> SolveAtbCaptcha(BotData data, string appId, string apiServer, string siteUrl,
bool useProxy = false, string userAgent =
Expand All @@ -356,6 +421,9 @@ public static async Task<string> SolveAtbCaptcha(BotData data, string appId, str
return response.Response;
}

/// <summary>
/// Solves a Tencent captcha.
/// </summary>
[Block("Solves a Tencent captcha",
extraInfo = "The response will be a list and its elements are (in order) app id, ticket, return code, random string")]
public static async Task<List<string>> SolveTencentCaptcha(BotData data, string appId, string siteUrl,
Expand All @@ -377,6 +445,9 @@ public static async Task<List<string>> SolveTencentCaptcha(BotData data, string
return [response.AppId, response.Ticket, response.ReturnCode.ToString(), response.RandomString];
}

/// <summary>
/// Solves an audio captcha.
/// </summary>
[Block("Solves an audio captcha")]
public static async Task<string> SolveAudioCaptcha(BotData data, string base64,
CaptchaLanguage language = CaptchaLanguage.NotSpecified)
Expand All @@ -394,6 +465,9 @@ public static async Task<string> SolveAudioCaptcha(BotData data, string base64,
return response.Response;
}

/// <summary>
/// Solves a ReCaptcha Mobile.
/// </summary>
[Block("Solves a ReCaptcha Mobile")]
public static async Task<string> SolveRecaptchaMobile(BotData data, string appPackageName, string appKey,
string appAction, bool useProxy = false, string userAgent =
Expand All @@ -410,6 +484,9 @@ public static async Task<string> SolveRecaptchaMobile(BotData data, string appPa
return response.Response;
}

/// <summary>
/// Solves a GeeTest v4 captcha.
/// </summary>
[Block("Solves a GeeTest v4 captcha",
extraInfo =
"The response will be a list and its elements are (in order) captcha id, lot number, pass token, gen time, captcha output")]
Expand All @@ -433,6 +510,9 @@ public static async Task<List<string>> SolveGeeTestV4Captcha(BotData data, strin
return [response.CaptchaId, response.LotNumber, response.PassToken, response.GenTime, response.CaptchaOutput];
}

/// <summary>
/// Solves a Cloudflare Challenge page.
/// </summary>
[Block("Solves a Cloudflare Challenge page",
extraInfo = "The response will contain the value of the cf_clearance cookie")]
public static async Task<string> SolveCloudflareChallengePage(BotData data,
Expand All @@ -451,6 +531,9 @@ public static async Task<string> SolveCloudflareChallengePage(BotData data,
return response.Response;
}

/// <summary>
/// Reports an incorrectly solved captcha.
/// </summary>
[Block("Reports an incorrectly solved captcha to the service in order to get funds back")]
public static async Task ReportLastSolution(BotData data)
{
Expand Down
27 changes: 27 additions & 0 deletions RuriLib/Blocks/Conditions/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace RuriLib.Blocks.Conditions;

/// <summary>
/// Blocks to check conditions.
/// </summary>
[BlockCategory("Conditions", "Blocks that have to do with checking conditions", "#1e90ff")]
public static class Methods
{
Expand All @@ -14,6 +17,9 @@ public static class Methods
* of writing C# code that calls these methods where necessary once it's transpiled.
*/

/// <summary>
/// Checks a condition with two boolean terms.
/// </summary>
public static bool CheckCondition(BotData data, bool leftTerm, BoolComparison comparison, bool rightTerm)
{
data.Logger.LogHeader();
Expand All @@ -28,6 +34,9 @@ public static bool CheckCondition(BotData data, bool leftTerm, BoolComparison co
return result;
}

/// <summary>
/// Checks a condition with two string terms.
/// </summary>
public static bool CheckCondition(BotData data, string leftTerm, StrComparison comparison, string rightTerm)
{
data.Logger.LogHeader();
Expand All @@ -42,6 +51,9 @@ public static bool CheckCondition(BotData data, string leftTerm, StrComparison c
return result;
}

/// <summary>
/// Checks a condition between a list of strings and a string.
/// </summary>
public static bool CheckCondition(BotData data, List<string> leftTerm, ListComparison comparison, string rightTerm)
{
data.Logger.LogHeader();
Expand All @@ -56,6 +68,9 @@ public static bool CheckCondition(BotData data, List<string> leftTerm, ListCompa
return result;
}

/// <summary>
/// Checks a condition with two integer terms.
/// </summary>
public static bool CheckCondition(BotData data, int leftTerm, NumComparison comparison, int rightTerm)
{
data.Logger.LogHeader();
Expand All @@ -70,6 +85,9 @@ public static bool CheckCondition(BotData data, int leftTerm, NumComparison comp
return result;
}

/// <summary>
/// Checks a condition with two float terms.
/// </summary>
public static bool CheckCondition(BotData data, float leftTerm, NumComparison comparison, float rightTerm)
{
data.Logger.LogHeader();
Expand All @@ -84,6 +102,9 @@ public static bool CheckCondition(BotData data, float leftTerm, NumComparison co
return result;
}

/// <summary>
/// Checks a condition between a dictionary of strings and a string.
/// </summary>
public static bool CheckCondition(BotData data, Dictionary<string, string> leftTerm, DictComparison comparison, string rightTerm)
{
data.Logger.LogHeader();
Expand All @@ -98,6 +119,9 @@ public static bool CheckCondition(BotData data, Dictionary<string, string> leftT
return result;
}

/// <summary>
/// Checks if the source contains a global ban key.
/// </summary>
public static bool CheckGlobalBanKeys(BotData data)
{
data.Logger.LogHeader();
Expand All @@ -112,6 +136,9 @@ public static bool CheckGlobalBanKeys(BotData data)
return result;
}

/// <summary>
/// Checks if the source contains a global retry key.
/// </summary>
public static bool CheckGlobalRetryKeys(BotData data)
{
data.Logger.LogHeader();
Expand Down
6 changes: 6 additions & 0 deletions RuriLib/Blocks/Functions/ByteArrayFunctions/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
// ReSharper disable once CheckNamespace
namespace RuriLib.Blocks.Functions.ByteArray;

/// <summary>
/// Blocks for working with byte arrays.
/// </summary>
[BlockCategory("Byte Array Functions", "Blocks for working with byte arrays", "#9acd32")]
public static class Methods
{
/// <summary>
/// Merge two byte arrays together to form a longer one.
/// </summary>
[Block("Merges two byte arrays together to form a longer one")]
public static byte[] MergeByteArrays(BotData data, byte[] first, byte[] second)
{
Expand Down
Loading

0 comments on commit 993d7b4

Please sign in to comment.