logs: handle no args given
unwrap logs
This commit is contained in:
parent
7ef4ad42e0
commit
7b31d24954
2 changed files with 28 additions and 10 deletions
|
@ -1,18 +1,34 @@
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
|
use std::error::Error;
|
||||||
use twitch_irc::message::PrivmsgMessage;
|
use twitch_irc::message::PrivmsgMessage;
|
||||||
|
|
||||||
use crate::client::TwitchClient;
|
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();
|
dotenv().ok();
|
||||||
|
let twitch_client = c.twitch_client.clone();
|
||||||
|
|
||||||
let url = format!(
|
if let Some(_args) = a.first() {
|
||||||
"https://logs.flake.sh/?channel={}&username={}",
|
let base_url = format!(
|
||||||
|
"https://logs.flake.sh/?username={}&channel={}",
|
||||||
a.first().unwrap(),
|
a.first().unwrap(),
|
||||||
a.get(1).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?
|
||||||
|
}
|
||||||
|
|
||||||
let twitch_client = c.twitch_client.clone();
|
Ok(())
|
||||||
|
|
||||||
let _response = twitch_client.say(m.channel_login.to_owned(), url).await;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,9 @@ pub async fn main() {
|
||||||
"user" => get_user_command(&msg, &client, &arguments)
|
"user" => get_user_command(&msg, &client, &arguments)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_default(),
|
.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(),
|
"massping" => massping_command(&msg, &client).await.unwrap_or_default(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue