feat(katana): c o:w parser
This commit is contained in:
parent
410625e2b3
commit
fb74bfe568
@ -26,7 +26,6 @@ pub fn init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn query_card(name: &str, series: &str) -> Option<Card> {
|
pub async fn query_card(name: &str, series: &str) -> Option<Card> {
|
||||||
// todo!("Query card from database");
|
|
||||||
KATANA
|
KATANA
|
||||||
.get()
|
.get()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use crate::structs::Card;
|
use crate::structs::Card;
|
||||||
use log::{error, trace};
|
use log::{error, trace};
|
||||||
|
|
||||||
|
// atopwl
|
||||||
pub fn parse_cards_from_qingque_atopwl(content: &String) -> Vec<Card> {
|
pub fn parse_cards_from_qingque_atopwl(content: &String) -> Vec<Card> {
|
||||||
let mut cards: Vec<Card> = Vec::new();
|
let mut cards: Vec<Card> = Vec::new();
|
||||||
for line in content.split("\n") {
|
for line in content.split("\n") {
|
||||||
@ -59,3 +60,58 @@ pub fn parse_cards_from_qingque_atopwl(content: &String) -> Vec<Card> {
|
|||||||
}
|
}
|
||||||
cards
|
cards
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// kc o:w
|
||||||
|
pub fn parse_cards_from_katana_kc_ow(content: &String) -> Vec<Card> {
|
||||||
|
let mut cards: Vec<Card> = Vec::new();
|
||||||
|
for line in content.split("\n") {
|
||||||
|
trace!("Parsing line: {}", line);
|
||||||
|
if !line.ends_with("**") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let mut line_split = line.split(" · ");
|
||||||
|
let tag_wl_block = line_split.nth(0).unwrap();
|
||||||
|
let mut wl_block = match tag_wl_block.split("`").nth(1) {
|
||||||
|
Some(wl_block) => {
|
||||||
|
// If one does not start with ♡, it is not a wishlist command
|
||||||
|
// then we'll just break entirely.
|
||||||
|
if !wl_block.starts_with("♡") {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
wl_block.to_string()
|
||||||
|
},
|
||||||
|
None => break,
|
||||||
|
};
|
||||||
|
wl_block.remove(0);
|
||||||
|
wl_block = wl_block.trim().to_string();
|
||||||
|
let wishlist = match wl_block.parse::<u32>() {
|
||||||
|
Ok(wishlist) => wishlist,
|
||||||
|
Err(_) => {
|
||||||
|
error!("Failed to parse wishlist number: {}", wl_block);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let series = match line_split.nth(4) {
|
||||||
|
Some(series) => series.to_string(),
|
||||||
|
None => continue,
|
||||||
|
};
|
||||||
|
let name = match line_split.next() {
|
||||||
|
Some(name) => {
|
||||||
|
let mut name_string = name.to_string();
|
||||||
|
name_string.remove_matches("**");
|
||||||
|
name_string
|
||||||
|
}
|
||||||
|
None => continue,
|
||||||
|
};
|
||||||
|
let card = Card {
|
||||||
|
wishlist: Some(wishlist),
|
||||||
|
name,
|
||||||
|
series,
|
||||||
|
print: 0,
|
||||||
|
last_update_ts: 0,
|
||||||
|
};
|
||||||
|
trace!("Parsed card: {:?}", card);
|
||||||
|
cards.push(card);
|
||||||
|
}
|
||||||
|
cards
|
||||||
|
}
|
||||||
|
@ -42,12 +42,18 @@ pub struct Features {
|
|||||||
pub sofa_drop_analysis: DropAnalyzer,
|
pub sofa_drop_analysis: DropAnalyzer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub struct General {
|
||||||
|
pub prefix: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub log: Log,
|
pub log: Log,
|
||||||
pub tesseract: Tesseract,
|
pub tesseract: Tesseract,
|
||||||
pub debug: Debug,
|
pub debug: Debug,
|
||||||
pub features: Features,
|
pub features: Features,
|
||||||
|
pub general: General,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@ -94,6 +100,9 @@ impl Config {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
general: General {
|
||||||
|
prefix: "~".to_string(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn save(&self, path: &str) {
|
pub fn save(&self, path: &str) {
|
||||||
|
@ -127,6 +127,48 @@ pub async fn dbg_parse_qingque_atopwl(ctx: &Context, msg: &Message) -> CommandRe
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn dbg_parse_katana_kc_ow(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
|
let target_msg = match dbg_get_message("embed", ctx, msg).await {
|
||||||
|
Ok(msg) => msg,
|
||||||
|
Err(_) => {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if target_msg.embeds.len() == 0 {
|
||||||
|
helper::error_message(
|
||||||
|
ctx,
|
||||||
|
msg,
|
||||||
|
"Message does not contain any embeds".to_string(),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let embed = &target_msg.embeds[0];
|
||||||
|
let embed_description = match embed.description {
|
||||||
|
Some(ref description) => description,
|
||||||
|
None => {
|
||||||
|
helper::error_message(
|
||||||
|
ctx,
|
||||||
|
msg,
|
||||||
|
"Embed does not contain a description".to_string(),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let cards = utils::katana::parse_cards_from_katana_kc_ow(embed_description);
|
||||||
|
helper::info_message(
|
||||||
|
ctx,
|
||||||
|
msg,
|
||||||
|
format!("Parsed cards: ```\n{:?}\n```", cards),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn dbg_embed(ctx: &Context, msg: &Message) -> CommandResult {
|
pub async fn dbg_embed(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
let target_msg = match dbg_get_message("embed", ctx, msg).await {
|
let target_msg = match dbg_get_message("embed", ctx, msg).await {
|
||||||
Ok(msg) => msg,
|
Ok(msg) => msg,
|
||||||
@ -158,7 +200,7 @@ pub async fn dbg_embed(ctx: &Context, msg: &Message) -> CommandResult {
|
|||||||
msg,
|
msg,
|
||||||
format!(
|
format!(
|
||||||
"Title: \n\
|
"Title: \n\
|
||||||
```\
|
```\n\
|
||||||
{}\n\
|
{}\n\
|
||||||
```\n\
|
```\n\
|
||||||
Description: \n\
|
Description: \n\
|
||||||
|
@ -203,7 +203,7 @@ async fn main() {
|
|||||||
swordfish_common::database::init().await;
|
swordfish_common::database::init().await;
|
||||||
info!("Initializing Discord client...");
|
info!("Initializing Discord client...");
|
||||||
let framework = StandardFramework::new().group(&GENERAL_GROUP);
|
let framework = StandardFramework::new().group(&GENERAL_GROUP);
|
||||||
framework.configure(Configuration::new().prefix("~")); // set the bot's prefix to "~"
|
framework.configure(Configuration::new().prefix(CONFIG.get().unwrap().general.prefix.clone()));
|
||||||
|
|
||||||
// Login with a bot token from the environment
|
// Login with a bot token from the environment
|
||||||
let intents = GatewayIntents::non_privileged() | GatewayIntents::MESSAGE_CONTENT;
|
let intents = GatewayIntents::non_privileged() | GatewayIntents::MESSAGE_CONTENT;
|
||||||
@ -229,7 +229,7 @@ async fn ping(ctx: &Context, msg: &Message) -> CommandResult {
|
|||||||
#[command]
|
#[command]
|
||||||
async fn debug(ctx: &Context, msg: &Message) -> CommandResult {
|
async fn debug(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
let config = CONFIG.get().unwrap();
|
let config = CONFIG.get().unwrap();
|
||||||
if ["debug", "trace"].contains(&config.log.level.as_str()){
|
if !["debug", "trace"].contains(&config.log.level.as_str()){
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if !config.debug.allowed_users.contains(&msg.author.id.get()) {
|
if !config.debug.allowed_users.contains(&msg.author.id.get()) {
|
||||||
@ -255,6 +255,7 @@ async fn debug(ctx: &Context, msg: &Message) -> CommandResult {
|
|||||||
"kda" => debug::dbg_kdropanalyze(ctx, msg).await?,
|
"kda" => debug::dbg_kdropanalyze(ctx, msg).await?,
|
||||||
"embed" => debug::dbg_embed(ctx, msg).await?,
|
"embed" => debug::dbg_embed(ctx, msg).await?,
|
||||||
"parse-qingque-atopwl" => debug::dbg_parse_qingque_atopwl(ctx, msg).await?,
|
"parse-qingque-atopwl" => debug::dbg_parse_qingque_atopwl(ctx, msg).await?,
|
||||||
|
"parse-katana-kc_ow" => debug::dbg_parse_katana_kc_ow(ctx, msg).await?,
|
||||||
_ => {
|
_ => {
|
||||||
helper::error_message(
|
helper::error_message(
|
||||||
ctx,
|
ctx,
|
||||||
|
Loading…
Reference in New Issue
Block a user