debug: add more info

This commit is contained in:
tretrauit 2023-12-31 23:49:07 +07:00
parent 34c52cd9ab
commit 9536539e8c
3 changed files with 44 additions and 27 deletions

View File

@ -1,20 +1,21 @@
use crate::template::message;
use serenity::builder::CreateMessage;
use serenity::client::Context; use serenity::client::Context;
use serenity::model::channel::Message; use serenity::model::channel::Message;
use serenity::builder::CreateMessage; use swordfish_common::error;
use crate::template::message;
pub async fn error_message(ctx: &Context, msg: &Message, content: String) { pub async fn error_message(ctx: &Context, msg: &Message, content: String) {
msg.channel_id match msg
.send_message( .channel_id
ctx, .send_message(
CreateMessage::new().add_embed( ctx,
message::error_embed( CreateMessage::new().add_embed(message::error_embed(ctx, None, Some(content)).await),
ctx, )
None, .await
Some(content), {
) Ok(_) => (),
.await, Err(why) => {
), error!("Failed to send error message: {:?}", why);
) }
.await?; };
} }

View File

@ -12,7 +12,10 @@ use swordfish_common::{debug, error, info, trace, warn};
pub fn analyze_card(leptess: &LepTess, card: image::DynamicImage) { pub fn analyze_card(leptess: &LepTess, card: image::DynamicImage) {
trace!("Analyzing card..."); trace!("Analyzing card...");
// Read the name and the series // Read the name and the series
let name_img = card.crop_imm(0, 0, 257, 29); let name_img = card.crop_imm(22, 26, 206 - 22, 70 - 26);
name_img.save("debug/4-name.png").unwrap();
let series_img = card.crop_imm(22, 260, 206 - 22, 306 - 260);
series_img.save("debug/4-series.png").unwrap();
// Read the print number // Read the print number
} }

View File

@ -57,7 +57,7 @@ async fn parse_katana(ctx: &Context, msg: &Message) -> Result<(), String> {
{ {
trace!("Card drop detected, executing drop analyzer..."); trace!("Card drop detected, executing drop analyzer...");
unsafe { unsafe {
match katana::analyze_drop_message(&LEPTESS_ARC, msg) { match katana::analyze_drop_message(&LEPTESS_ARC, msg).await {
Ok(_) => { Ok(_) => {
// msg.reply(ctx, "Drop analysis complete").await?; // msg.reply(ctx, "Drop analysis complete").await?;
} }
@ -120,12 +120,18 @@ async fn kdropanalyze(ctx: &Context, msg: &Message) -> CommandResult {
Some(content) => match content.parse::<u64>() { Some(content) => match content.parse::<u64>() {
Ok(id) => id, Ok(id) => id,
Err(why) => { Err(why) => {
helper::error_message(ctx, msg, format!("Failed to parse channel ID: `{:?}`", why)).await; helper::error_message(ctx, msg, format!("Failed to parse channel ID: `{:?}`", why))
.await;
return Ok(()); return Ok(());
} }
}, },
None => { None => {
helper::error_message(ctx, msg, "Usage: `kdropanalyze <channel ID> <message ID>`".to_string()).await; helper::error_message(
ctx,
msg,
"Usage: `kdropanalyze <channel ID> <message ID>`".to_string(),
)
.await;
return Ok(()); return Ok(());
} }
}; };
@ -133,12 +139,18 @@ async fn kdropanalyze(ctx: &Context, msg: &Message) -> CommandResult {
Some(content) => match content.parse::<u64>() { Some(content) => match content.parse::<u64>() {
Ok(id) => id, Ok(id) => id,
Err(why) => { Err(why) => {
helper::error_message(ctx, msg, format!("Failed to parse message ID: `{:?}`", why)).await; helper::error_message(ctx, msg, format!("Failed to parse message ID: `{:?}`", why))
.await;
return Ok(()); return Ok(());
} }
}, },
None => { None => {
helper::error_message(ctx, msg, "Usage: `kdropanalyze <channel ID> <message ID>`".to_string()).await; helper::error_message(
ctx,
msg,
"Usage: `kdropanalyze <channel ID> <message ID>`".to_string(),
)
.await;
return Ok(()); return Ok(());
} }
}; };
@ -162,7 +174,8 @@ async fn kdropanalyze(ctx: &Context, msg: &Message) -> CommandResult {
msg.reply(ctx, "Drop analysis complete").await?; msg.reply(ctx, "Drop analysis complete").await?;
} }
Err(why) => { Err(why) => {
helper::error_message(ctx, msg, format!("Failed to analyze drop: `{:?}`", why)).await; helper::error_message(ctx, msg, format!("Failed to analyze drop: `{:?}`", why))
.await;
} }
}; };
} }