chore: move args checking to a function
Clean up the code
This commit is contained in:
parent
b16c0dadab
commit
3dcfdafc37
@ -287,7 +287,7 @@ async fn info(ctx: &Context, msg: &Message) -> CommandResult {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn dbg_parse_qingque_atopwl(ctx: &Context, msg: &Message) -> CommandResult {
|
async fn dbg_get_message(command: &str, ctx: &Context, msg: &Message) -> Result<Message, ()> {
|
||||||
let mut args = msg.content.split(" ");
|
let mut args = msg.content.split(" ");
|
||||||
let target_channel_id = match args.nth(2) {
|
let target_channel_id = match args.nth(2) {
|
||||||
Some(content) => match content.parse::<u64>() {
|
Some(content) => match content.parse::<u64>() {
|
||||||
@ -307,11 +307,11 @@ async fn dbg_parse_qingque_atopwl(ctx: &Context, msg: &Message) -> CommandResult
|
|||||||
helper::error_message(
|
helper::error_message(
|
||||||
ctx,
|
ctx,
|
||||||
msg,
|
msg,
|
||||||
"Usage: `parse-qingque-atopwl <channel ID> <message ID>`".to_string(),
|
format!("Usage: `{} <channel ID> <message ID>`", command),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
return Ok(());
|
return Err(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let target_msg_id = match args.nth(0) {
|
let target_msg_id = match args.nth(0) {
|
||||||
@ -325,18 +325,18 @@ async fn dbg_parse_qingque_atopwl(ctx: &Context, msg: &Message) -> CommandResult
|
|||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
return Ok(());
|
return Err(());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
helper::error_message(
|
helper::error_message(
|
||||||
ctx,
|
ctx,
|
||||||
msg,
|
msg,
|
||||||
"Usage: `parse-qingque-atopwl <channel ID> <message ID>`".to_string(),
|
format!("Usage: `{} <channel ID> <message ID>`", command),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
return Ok(());
|
return Err(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let target_msg = match ctx
|
let target_msg = match ctx
|
||||||
@ -356,6 +356,16 @@ async fn dbg_parse_qingque_atopwl(ctx: &Context, msg: &Message) -> CommandResult
|
|||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
target_msg
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn dbg_parse_qingque_atopwl(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
|
let target_msg = match dbg_get_message("embed", ctx, msg).await {
|
||||||
|
Ok(msg) => msg,
|
||||||
|
Err(_) => {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -395,74 +405,9 @@ async fn dbg_parse_qingque_atopwl(ctx: &Context, msg: &Message) -> CommandResult
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn dbg_embed(ctx: &Context, msg: &Message) -> CommandResult {
|
async fn dbg_embed(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
let mut args = msg.content.split(" ");
|
let target_msg = match dbg_get_message("embed", ctx, msg).await {
|
||||||
let target_channel_id = match args.nth(2) {
|
|
||||||
Some(content) => match content.parse::<u64>() {
|
|
||||||
Ok(id) => id,
|
|
||||||
Err(why) => {
|
|
||||||
helper::error_message(
|
|
||||||
ctx,
|
|
||||||
msg,
|
|
||||||
format!("Failed to parse channel ID: `{:?}`", why),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
helper::error_message(
|
|
||||||
ctx,
|
|
||||||
msg,
|
|
||||||
"Usage: `embed <channel ID> <message ID>`".to_string(),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let target_msg_id = match args.nth(0) {
|
|
||||||
Some(content) => match content.parse::<u64>() {
|
|
||||||
Ok(id) => id,
|
|
||||||
Err(why) => {
|
|
||||||
helper::error_message(
|
|
||||||
ctx,
|
|
||||||
msg,
|
|
||||||
format!("Failed to parse message ID: `{:?}`", why),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
helper::error_message(
|
|
||||||
ctx,
|
|
||||||
msg,
|
|
||||||
"Usage: `embed <channel ID> <message ID>`".to_string(),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let target_msg = match ctx
|
|
||||||
.http()
|
|
||||||
.get_message(
|
|
||||||
ChannelId::new(target_channel_id),
|
|
||||||
MessageId::new(target_msg_id),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(msg) => msg,
|
Ok(msg) => msg,
|
||||||
Err(why) => {
|
Err(_) => {
|
||||||
helper::error_message(
|
|
||||||
ctx,
|
|
||||||
msg,
|
|
||||||
format!("Failed to get message: `{:?}`", why),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -479,24 +424,11 @@ async fn dbg_embed(ctx: &Context, msg: &Message) -> CommandResult {
|
|||||||
let embed = &target_msg.embeds[0];
|
let embed = &target_msg.embeds[0];
|
||||||
let embed_title = match embed.title {
|
let embed_title = match embed.title {
|
||||||
Some(ref title) => title,
|
Some(ref title) => title,
|
||||||
None => {
|
None => "None",
|
||||||
helper::error_message(ctx, msg, "Embed does not contain a title".to_string(), None)
|
|
||||||
.await;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let embed_description = match embed.description {
|
let embed_description = match embed.description {
|
||||||
Some(ref description) => description,
|
Some(ref description) => description,
|
||||||
None => {
|
None => "None",
|
||||||
helper::error_message(
|
|
||||||
ctx,
|
|
||||||
msg,
|
|
||||||
"Embed does not contain a description".to_string(),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
helper::info_message(
|
helper::info_message(
|
||||||
ctx,
|
ctx,
|
||||||
@ -519,74 +451,9 @@ async fn dbg_embed(ctx: &Context, msg: &Message) -> CommandResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn dbg_kdropanalyze(ctx: &Context, msg: &Message) -> CommandResult {
|
async fn dbg_kdropanalyze(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
let mut args = msg.content.split(" ");
|
let target_msg = match dbg_get_message("embed", ctx, msg).await {
|
||||||
let target_channel_id = match args.nth(2) {
|
|
||||||
Some(content) => match content.parse::<u64>() {
|
|
||||||
Ok(id) => id,
|
|
||||||
Err(why) => {
|
|
||||||
helper::error_message(
|
|
||||||
ctx,
|
|
||||||
msg,
|
|
||||||
format!("Failed to parse channel ID: `{:?}`", why),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
helper::error_message(
|
|
||||||
ctx,
|
|
||||||
msg,
|
|
||||||
"Usage: `kdropanalyze <channel ID> <message ID>`".to_string(),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let target_msg_id = match args.nth(0) {
|
|
||||||
Some(content) => match content.parse::<u64>() {
|
|
||||||
Ok(id) => id,
|
|
||||||
Err(why) => {
|
|
||||||
helper::error_message(
|
|
||||||
ctx,
|
|
||||||
msg,
|
|
||||||
format!("Failed to parse message ID: `{:?}`", why),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
helper::error_message(
|
|
||||||
ctx,
|
|
||||||
msg,
|
|
||||||
"Usage: `kdropanalyze <channel ID> <message ID>`".to_string(),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let target_msg = match ctx
|
|
||||||
.http()
|
|
||||||
.get_message(
|
|
||||||
ChannelId::new(target_channel_id),
|
|
||||||
MessageId::new(target_msg_id),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(msg) => msg,
|
Ok(msg) => msg,
|
||||||
Err(why) => {
|
Err(_) => {
|
||||||
helper::error_message(
|
|
||||||
ctx,
|
|
||||||
msg,
|
|
||||||
format!("Failed to get message: `{:?}`", why),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user