This repository has been archived by the owner on Feb 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Добавлена функция удаления неактивных редакторов 2. Добавлена поддержка ruCaptcha 3. Добавлена поддержка списков из API 4. Изменены шаблонные настройки для создания групп
- Loading branch information
Showing
26 changed files
with
733 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using nng_one.ServiceCollections; | ||
using nng.Enums; | ||
using nng.Logging; | ||
using TwoCaptcha.Captcha; | ||
using VkNet.Utils.AntiCaptcha; | ||
|
||
namespace nng_one.CaptchaSolver; | ||
|
||
public class RuCaptchaSolver : ICaptchaSolver | ||
{ | ||
private readonly TwoCaptcha.TwoCaptcha _twoCaptcha; | ||
private readonly HttpClient _httpClient; | ||
|
||
private readonly Logger _logger = ServiceCollectionContainer.GetInstance().GlobalLogger; | ||
|
||
private string _lastCaptchaId = ""; | ||
private bool _lastCaptchaReported; | ||
|
||
public RuCaptchaSolver(string apiKey) | ||
{ | ||
_httpClient = new HttpClient(); | ||
_twoCaptcha = new TwoCaptcha.TwoCaptcha(apiKey); | ||
_lastCaptchaReported = true; | ||
} | ||
|
||
public string Solve(string url) | ||
{ | ||
if (!_lastCaptchaReported && !string.IsNullOrEmpty(_lastCaptchaId)) | ||
{ | ||
_logger.Log("Положительный репорт с ID отослан", LogType.Debug); | ||
_twoCaptcha.Report(_lastCaptchaId, true); | ||
_lastCaptchaReported = true; | ||
} | ||
|
||
DownloadCaptcha(url); | ||
|
||
_logger.Log("Решаем капчту..."); | ||
var normal = new Normal("temp/captcha.jpg"); | ||
|
||
try | ||
{ | ||
_twoCaptcha.Solve(normal).GetAwaiter().GetResult(); | ||
} | ||
catch (Exception e) | ||
{ | ||
_logger.Log($"Не удалось решить каптчу {normal.Id}: {e.GetType()}: {e.Message}", LogType.Error); | ||
_lastCaptchaId = normal.Id; | ||
_lastCaptchaReported = false; | ||
return string.Empty; | ||
} | ||
|
||
_lastCaptchaId = normal.Id; | ||
_lastCaptchaReported = false; | ||
|
||
_logger.Log($"Ответ RuCaptcha: {normal.Code} | ID: {normal.Id}", LogType.Debug); | ||
return normal.Code; | ||
} | ||
|
||
private void DownloadCaptcha(string url) | ||
{ | ||
_logger.Log("Скачиваем каптчу", LogType.Debug); | ||
var imageResult = _httpClient.Send(new HttpRequestMessage(HttpMethod.Get, url)); | ||
imageResult.EnsureSuccessStatusCode(); | ||
var image = imageResult.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult(); | ||
|
||
ClearPath(); | ||
|
||
var file = File.Create("temp/captcha.jpg"); | ||
file.Write(image); | ||
_logger.Log("Каптча перезаписана в temp/captcha.jpg", LogType.Debug); | ||
file.Close(); | ||
} | ||
|
||
private void ClearPath() | ||
{ | ||
if (!Directory.Exists("temp")) Directory.CreateDirectory("temp"); | ||
|
||
if (File.Exists("temp/captcha.jpg")) File.Delete("temp/captcha.jpg"); | ||
} | ||
|
||
public void CaptchaIsFalse() | ||
{ | ||
_logger.Log($"Неправильная каптча {_lastCaptchaId}", LogType.Error); | ||
if (string.IsNullOrEmpty(_lastCaptchaId)) return; | ||
|
||
_logger.Log("Отрицательный репорт с ID отослан", LogType.Debug); | ||
_twoCaptcha.Report(_lastCaptchaId, false); | ||
_lastCaptchaReported = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace nng_one.Enums; | ||
|
||
public enum Priority | ||
{ | ||
White = 0, | ||
Green = 1, | ||
Teal = 2, | ||
Orange = 3, | ||
Red = 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using nng_one.CaptchaSolver; | ||
using nng_one.Configs; | ||
using nng_one.Helpers; | ||
using nng.VkFrameworks; | ||
|
||
namespace nng_one.Extensions; | ||
|
||
public static class VkFrameworkExtensions | ||
{ | ||
private static readonly Config Config = ConfigProcessor.LoadConfig(); | ||
|
||
public static void SetCaptchaBasedOnConfig(this VkFramework vkFramework) | ||
{ | ||
if (!Config.CaptchaBypass) | ||
{ | ||
vkFramework.SetCaptchaSolver(new CaptchaHandler()); | ||
} | ||
else | ||
{ | ||
if (!string.IsNullOrEmpty(Config.RuCaptchaToken) && !string.IsNullOrWhiteSpace(Config.RuCaptchaToken)) | ||
vkFramework.SetCaptchaSolver(new RuCaptchaSolver(Config.RuCaptchaToken)); | ||
else | ||
vkFramework.ResetCaptchaSolver(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.