commit 75aed7050d6030b4498bc42671e4e116b13f9f56
parent 72898596bd861bedf86340612f34147163f14d51
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Wed, 29 Mar 2023 17:20:29 -0700
cleanup
Diffstat:
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/src/lechatphp/mod.rs b/src/lechatphp/mod.rs
@@ -140,18 +140,17 @@ fn solve_difficulty2(img: &DynamicImage) -> Option<String> {
#[derive(Clone, Debug)]
struct Letter {
- offset_x: u32,
- offset_y: u32,
+ offset: Point,
character: char,
}
impl Letter {
fn key(&self) -> String {
- format!("{}_{}_{}", self.character, self.offset_x, self.offset_y)
+ format!("{}_{}_{}", self.character, self.offset.x, self.offset.y)
}
fn offset(&self) -> Point {
- Point::new(self.offset_x, self.offset_y)
+ self.offset.clone()
}
fn center(&self) -> Point {
@@ -211,7 +210,7 @@ fn solve_difficulty3(img: &DynamicImage) -> Result<String, String> {
}
}
- let letter = Letter{offset_x: x, offset_y: y, character: c};
+ let letter = Letter{offset: Point::new(x, y), character: c};
letters_map.insert(c, letter); // Keep letters in hashmap for easy access
break;
}
@@ -225,7 +224,7 @@ fn solve_difficulty3(img: &DynamicImage) -> Result<String, String> {
let mut starting: Option<Letter> = None;
// Step2: Find the starting letter
for (_, letter) in letters_map.iter() {
- let square = img.crop_imm(letter.offset_x-5, letter.offset_y-3, 8+5+6, 14+3+2);
+ let square = img.crop_imm(letter.offset.x-5, letter.offset.y-3, 8+5+6, 14+3+2);
let count_red = count_red_px(&square);
if count_red > min_starting_pt_red_px {
starting = Some(letter.clone());
@@ -251,7 +250,7 @@ fn solve_difficulty3(img: &DynamicImage) -> Result<String, String> {
break;
}
- let top_left = Point::new(letter.offset_x-5, letter.offset_y-3);
+ let top_left = Point::new(letter.offset.x-5, letter.offset.y-3);
let mut rect = Rect{p1: top_left, width: 8+5+6, height: 14+3+2};
let mut retry = 0;
@@ -329,7 +328,7 @@ fn solve_difficulty3(img: &DynamicImage) -> Result<String, String> {
fn get_letter_in_direction(letter: &Letter, angle: f64, letters_map: &HashMap<char, Letter>) -> Letter {
let mut angle = angle;
let mut min_angle = f64::MAX;
- let mut out = Letter{offset_x: 0, offset_y: 0, character: ' '};
+ let mut out = Letter{offset: Point::new(0, 0), character: ' '};
// Visit every other letters
for (_, other_letter) in letters_map.iter() {
if other_letter.key() == letter.key() {
diff --git a/src/main.rs b/src/main.rs
@@ -223,7 +223,6 @@ struct LeChatPHPClient {
client: Client,
session: String,
config: LeChatPHPConfig,
- dkf_api_key: Option<String>,
manual_captcha: bool,
refresh_rate: u64,
max_login_retry: isize,
@@ -253,6 +252,7 @@ impl LeChatPHPClient {
eprintln!("{:?}", e.to_string());
break;
} else if e.to_string() == CAPTCHA_FAILED_SOLVE_ERR {
+ // If we fail to solve the captcha, retry right away.
eprintln!("{}", e.to_string());
continue;
} else if e.to_string() == CAPTCHA_WG_ERR || e.to_string() == CAPTCHA_USED_ERR {
@@ -1705,7 +1705,6 @@ fn new_default_le_chat_php_client(params: Params) -> LeChatPHPClient {
guest_color: params.guest_color,
session: "".to_owned(),
client: params.client,
- dkf_api_key: params.dkf_api_key,
manual_captcha: params.manual_captcha,
refresh_rate: params.refresh_rate,
config: LeChatPHPConfig::new_black_hat_chat_config(),
@@ -1735,7 +1734,6 @@ struct Params {
password: String,
guest_color: String,
client: Client,
- dkf_api_key: Option<String>,
manual_captcha: bool,
refresh_rate: u64,
max_login_retry: isize,
@@ -1983,7 +1981,6 @@ fn main() -> Result<()> {
password,
guest_color,
client: client.clone(),
- dkf_api_key: opts.dkf_api_key,
manual_captcha: opts.manual_captcha,
refresh_rate: opts.refresh_rate,
max_login_retry: opts.max_login_retry,