logs: handle no args given

unwrap logs
This commit is contained in:
notohh 2024-06-17 17:21:57 -04:00
parent 7ef4ad42e0
commit 7b31d24954
Signed by: notohh
GPG key ID: BD47506D475EE86D
2 changed files with 28 additions and 10 deletions

View file

@ -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<dyn Error>> {
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: <username> <channel> ".to_string(),
)
.await?
}
Ok(())
}

View file

@ -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(),
_ => {}
}