diff options
| -rw-r--r-- | src/bot.rs | 1 | ||||
| -rw-r--r-- | src/commands/meme/create.rs | 16 | ||||
| -rw-r--r-- | src/commands/mod.rs | 3 | ||||
| -rw-r--r-- | src/commands/playback.rs | 3 | ||||
| -rw-r--r-- | src/commands/today/mod.rs | 34 | ||||
| -rw-r--r-- | src/config.rs | 8 | ||||
| -rw-r--r-- | src/util/mod.rs | 11 |
7 files changed, 33 insertions, 43 deletions
@@ -391,6 +391,7 @@ pub async fn run() -> anyhow::Result<()> { info!("shutdown"); }); + info!("starting bot"); client.start().await?; Ok(()) diff --git a/src/commands/meme/create.rs b/src/commands/meme/create.rs index e2eacbf..c28f583 100644 --- a/src/commands/meme/create.rs +++ b/src/commands/meme/create.rs @@ -33,14 +33,8 @@ use crate::{ pub async fn addmeme( ctx: PoiseContext<'_>, title: String, - #[rest] text: String, + #[rest] text: Option<String>, ) -> anyhow::Result<()> { - let text = if text.is_empty() { - None - } else { - Some(text) - }; - let mut conn = connection().await?; let image = util::msg(ctx).and_then(|msg| msg.attachments.first()); @@ -101,7 +95,7 @@ pub async fn addaudiomeme( ctx: PoiseContext<'_>, title: String, audio_str: String, - #[rest] rest: String, + #[rest] text: Option<String>, ) -> anyhow::Result<()> { debug!("running addaudiomeme"); @@ -155,12 +149,6 @@ pub async fn addaudiomeme( let mut audio_reader = ffmpeg_command.stdout.unwrap(); - let text = if rest.is_empty() { - None - } else { - Some(rest) - }; - let mut conn = connection().await?; let image_att = diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 1ad4a59..b7a8378 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -20,7 +20,8 @@ pub(crate) mod today; pub use self::meme::*; pub fn commands() -> Vec<poise::Command<crate::PoiseData, anyhow::Error>> { - let mut commands = vec![sound_levels::mute(), sound_levels::unmute(), roll::roll(), help()]; + let mut commands = + vec![sound_levels::mute(), sound_levels::unmute(), roll::roll(), today::today(), help()]; commands.extend(playback::commands()); diff --git a/src/commands/playback.rs b/src/commands/playback.rs index 48f3286..70dd704 100644 --- a/src/commands/playback.rs +++ b/src/commands/playback.rs @@ -78,7 +78,8 @@ pub async fn _play(ctx: PoiseContext<'_>, url: &url::Url) -> anyhow::Result<()> data.get::<HttpKey>().unwrap().clone() }; - let input = YoutubeDl::new_ytdl_like("yt-dlp", client.clone(), url.to_string()); + let input = + YoutubeDl::new_ytdl_like(&crate::config::YTDL_COMMAND, client.clone(), url.to_string()); call.enqueue_input(input.into()).await; util::react(ctx, ReactionType::Unicode("📣".to_owned())).await?; diff --git a/src/commands/today/mod.rs b/src/commands/today/mod.rs index c1a02d5..7b5fe8d 100644 --- a/src/commands/today/mod.rs +++ b/src/commands/today/mod.rs @@ -59,29 +59,31 @@ lazy_static! { } #[poise::command(slash_command, prefix_command, guild_only)] -pub async fn today(ctx: PoiseContext<'_>, #[rest] _rest: String) -> anyhow::Result<()> { +pub async fn today(ctx: PoiseContext<'_>, #[rest] _rest: Option<String>) -> anyhow::Result<()> { let today = { #[allow(unused_mut)] let mut result = chrono::Local::now().naive_local(); #[cfg(debug_assertions)] { - let dt = _rest.parse::<chrono::NaiveDateTime>().or_else(|_| { - _rest.parse::<chrono::NaiveDate>().map(|date| { - let time = chrono::NaiveTime::from_hms_opt(12, 0, 0).unwrap(); - date.and_time(time) - }) - }); + if let Some(rest) = _rest { + let dt = rest.parse::<chrono::NaiveDateTime>().or_else(|_| { + rest.parse::<chrono::NaiveDate>().map(|date| { + let time = chrono::NaiveTime::from_hms_opt(12, 0, 0).unwrap(); + date.and_time(time) + }) + }); - match dt { - Ok(dt) => { - debug!("overriding with datetime: {dt}"); - result = dt; - }, - Err(e) => { - debug!("parsing datetime: {e:?}"); - }, - }; + match dt { + Ok(dt) => { + debug!("overriding with datetime: {dt}"); + result = dt; + }, + Err(e) => { + debug!("parsing datetime: {e:?}"); + }, + }; + } } result diff --git a/src/config.rs b/src/config.rs index 84ee88b..896f82f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -18,7 +18,13 @@ lazy_static! { }; pub static ref FFMPEG_COMMAND: String = { let result = CONFIG.ffmpeg.clone().unwrap_or("ffmpeg".to_owned()); - log::debug!("got ffmpeg: {}", result); + log::debug!("got ffmpeg: {result}"); + + result + }; + pub static ref YTDL_COMMAND: String = { + let result = CONFIG.ytdl.clone().unwrap_or("yt-dlp".to_owned()); + log::debug!("got ytdl: {result}"); result }; diff --git a/src/util/mod.rs b/src/util/mod.rs index f959a37..5b943fe 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -176,15 +176,6 @@ pub async fn ytdl_url(uri: &str) -> anyhow::Result<String> { use serde_json::Value; use tokio::process::Command; - lazy_static! { - static ref YTDL_COMMAND: String = { - let result = CONFIG.ytdl.clone().unwrap_or("youtube-dl".to_owned()); - debug!("got ytdl: {}", result); - - result - }; - } - let args = [ "-f", "webm[abr>0]/bestaudio/best", @@ -196,7 +187,7 @@ pub async fn ytdl_url(uri: &str) -> anyhow::Result<String> { debug!("downloading info for uri: {uri}"); - let mut command = Command::new(&*YTDL_COMMAND); + let mut command = Command::new(&*crate::config::YTDL_COMMAND); command.args(args).stdin(Stdio::null()); debug!("running command: {command:?}"); |
