From 3c44da52c2d804e4479d210771107ba5b78b116f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=20Gramn=C3=A6s=20Tjernshaugen?= Date: Tue, 19 Mar 2024 19:38:27 +0100 Subject: [PATCH] Remove redundant match statement --- src/slack.rs | 60 ++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/src/slack.rs b/src/slack.rs index e3ae3d5..070e4fd 100644 --- a/src/slack.rs +++ b/src/slack.rs @@ -147,7 +147,7 @@ async fn handle_disconnect_message( async fn handle_slash_command( message: incoming::Incoming, ) -> outgoing::SlackOutgoingMessage { - let command_spin_mode = match message.payload.command.as_str() { + let spin_mode = match message.payload.command.as_str() { "/spin" => SpinMode::Any, "/spin-vegan" => SpinMode::Vegan, "/spin-vegetarian" => SpinMode::Vegetarian, @@ -160,35 +160,31 @@ async fn handle_slash_command( } }; - match command_spin_mode { - spin_mode => { - let pizza = get_random_pizza(spin_mode); - let outgoing_message = outgoing::SlashCommandOutgoingMessage { - response_type: "in_channel".to_string(), - blocks: vec![ - outgoing::SlackCommandBlock { - r#type: "section".to_string(), - text: outgoing::SlackCommandBlockText { - r#type: "mrkdwn".to_string(), - text: format!("Gratulerer, du har fått {}", pizza.name), - }, - }, - outgoing::SlackCommandBlock { - r#type: "section".to_string(), - text: outgoing::SlackCommandBlockText { - r#type: "mrkdwn".to_string(), - text: format!( - "{} er en pizza med {} ({})", - pizza.name, pizza.description, pizza.extra - ), - }, - }, - ], - }; - outgoing::SlackOutgoingMessage::SlashCommand(outgoing::Outgoing::new( - message.envelope_id, - Some(outgoing_message), - )) - } - } + let pizza = get_random_pizza(spin_mode); + let outgoing_message = outgoing::SlashCommandOutgoingMessage { + response_type: "in_channel".to_string(), + blocks: vec![ + outgoing::SlackCommandBlock { + r#type: "section".to_string(), + text: outgoing::SlackCommandBlockText { + r#type: "mrkdwn".to_string(), + text: format!("Gratulerer, du har fått {}", pizza.name), + }, + }, + outgoing::SlackCommandBlock { + r#type: "section".to_string(), + text: outgoing::SlackCommandBlockText { + r#type: "mrkdwn".to_string(), + text: format!( + "{} er en pizza med {} ({})", + pizza.name, pizza.description, pizza.extra + ), + }, + }, + ], + }; + outgoing::SlackOutgoingMessage::SlashCommand(outgoing::Outgoing::new( + message.envelope_id, + Some(outgoing_message), + )) }