From 7b31d249546ac71d3a4bfd6e777cfc3f8b83c41c Mon Sep 17 00:00:00 2001 From: notohh Date: Mon, 17 Jun 2024 17:21:57 -0400 Subject: [PATCH] logs: handle no args given unwrap logs --- src/commands/logs.rs | 34 +++++++++++++++++++++++++--------- src/main.rs | 4 +++- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/commands/logs.rs b/src/commands/logs.rs index 8d13ead..4f497b2 100644 --- a/src/commands/logs.rs +++ b/src/commands/logs.rs @@ -1,18 +1,34 @@ use dotenv::dotenv; +use std::error::Error; use twitch_irc::message::PrivmsgMessage; use crate::client::TwitchClient; -pub async fn logs_command(m: &PrivmsgMessage, c: &TwitchClient, a: &[&str]) { +pub async fn logs_command( + m: &PrivmsgMessage, + c: &TwitchClient, + a: &[&str], +) -> Result<(), Box> { dotenv().ok(); - - let url = format!( - "https://logs.flake.sh/?channel={}&username={}", - a.first().unwrap(), - a.get(1).unwrap() - ); - let twitch_client = c.twitch_client.clone(); - let _response = twitch_client.say(m.channel_login.to_owned(), url).await; + if let Some(_args) = a.first() { + let base_url = format!( + "https://logs.flake.sh/?username={}&channel={}", + a.first().unwrap(), + a.get(1).unwrap() + ); + twitch_client + .say(m.channel_login.to_owned(), base_url.to_string()) + .await? + } else { + twitch_client + .say( + m.channel_login.to_owned(), + "Please provide args: ".to_string(), + ) + .await? + } + + Ok(()) } diff --git a/src/main.rs b/src/main.rs index e04e305..248e957 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,7 +56,9 @@ pub async fn main() { "user" => get_user_command(&msg, &client, &arguments) .await .unwrap_or_default(), - "logs" => logs_command(&msg, &client, &arguments).await, + "logs" => logs_command(&msg, &client, &arguments) + .await + .unwrap_or_default(), "massping" => massping_command(&msg, &client).await.unwrap_or_default(), _ => {} }