diff --git a/src/actions.rs b/src/actions.rs index c4bc2db..b240492 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -16,6 +16,8 @@ pub struct IdeaReactionAction { } #[derive(thiserror::Error, Debug)] +// TODO(kisaragi): https://github.com/GiganticMinecraft/idea-reaction/pull/153 が済んだらヴァリアントの名前を変える +#[expect(clippy::enum_variant_names)] pub enum IdeaReactionActionError { #[error("Failed to reaction. (Reason: {0})")] FailedToReaction(String), diff --git a/src/handler.rs b/src/handler.rs index 644ce98..80dc58e 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -29,10 +29,11 @@ impl EventHandler for Handler { return; }; - if message.embeds.first().is_none() { + let Some(first_embed) = message.embeds.first() else { return; }; - let embed = match parse_embed(message.embeds.first().unwrap()) { + + let embed = match parse_embed(first_embed) { Ok(embed) => embed, Err(why) => { tracing::error!("Failed to parse embed: {:?}", why); diff --git a/src/main.rs b/src/main.rs index 7a149b1..5e53fa2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![deny(clippy::all)] + use anyhow::Context; use handler::Handler; use serenity::{all::GatewayIntents, Client}; diff --git a/src/parsers.rs b/src/parsers.rs index 9d915da..0706ea2 100644 --- a/src/parsers.rs +++ b/src/parsers.rs @@ -52,19 +52,19 @@ pub fn parse_embed(embed: &serenity::all::Embed) -> anyhow::Result anyhow::Result { +fn parse_issue_number(title: &str) -> anyhow::Result { let re = match regex::Regex::new(r"#(\d+)") { Ok(regex) => regex, Err(why) => return Err(ParseEnvIDsError::FailedToParseIssueNumber(why.to_string())), }; - match re.captures(&title) { + match re.captures(title) { Some(caps) => match caps.get(1).unwrap().as_str().parse::() { Ok(num) => Ok(num), Err(why) => Err(ParseEnvIDsError::FailedToParseIssueNumber(why.to_string())), @@ -94,17 +94,17 @@ mod parsers_test { "[New issue] アイデア提案用プロジェクト - アイデア提案 #10925: 棒メニューに建築素材のみの購入メニュー" ]; - assert_eq!(parse_issue_number(&mock[0].to_string()).unwrap(), 9); - assert_eq!(parse_issue_number(&mock[1].to_string()).unwrap(), 951); - assert_eq!(parse_issue_number(&mock[2].to_string()).unwrap(), 1527); - assert_eq!(parse_issue_number(&mock[3].to_string()).unwrap(), 10925); + assert_eq!(parse_issue_number(mock[0]).unwrap(), 9); + assert_eq!(parse_issue_number(mock[1]).unwrap(), 951); + assert_eq!(parse_issue_number(mock[2]).unwrap(), 1527); + assert_eq!(parse_issue_number(mock[3]).unwrap(), 10925); } // `parse_issue_number()` が Issue 番号がないタイトルのパースを正しく失敗できるか #[test] fn test_parse_issue_number_no_capture() { let mock = "[New issue] アイデア提案用プロジェクト - アイデア提案: 不定期イベントシステム"; - let result = parse_issue_number(&mock.to_string()); + let result = parse_issue_number(mock); assert!(result.is_err()); }