diff options
Diffstat (limited to 'src/commands')
| -rw-r--r-- | src/commands/game.rs | 22 | ||||
| -rw-r--r-- | src/commands/meme/create.rs | 20 | ||||
| -rw-r--r-- | src/commands/meme/delete.rs | 4 | ||||
| -rw-r--r-- | src/commands/meme/history.rs | 25 | ||||
| -rw-r--r-- | src/commands/meme/invoke.rs | 8 | ||||
| -rw-r--r-- | src/commands/meme/mod.rs | 4 | ||||
| -rw-r--r-- | src/commands/playback.rs | 15 | ||||
| -rw-r--r-- | src/commands/roll.rs | 5 | ||||
| -rw-r--r-- | src/commands/today/mod.rs | 8 |
9 files changed, 49 insertions, 62 deletions
diff --git a/src/commands/game.rs b/src/commands/game.rs index ba9ac69..258feaf 100644 --- a/src/commands/game.rs +++ b/src/commands/game.rs @@ -17,13 +17,9 @@ use fnv::{ FnvHashMap, FnvHashSet, }; +use grate::tracing; use itertools::Itertools; use lazy_static::lazy_static; -use log::{ - debug, - error, - info, -}; use serde::Deserialize; use serenity::model::{ guild::Guild, @@ -86,7 +82,7 @@ lazy_static! { }) .collect::<FnvHashMap<_, _>>(); - info!( + tracing::info!( "loaded user info for {} users ({:#?})", result.len(), result.keys().collect::<Vec<_>>() @@ -248,14 +244,14 @@ async fn _game( let Ok(guild) = guild.guild(&ctx).ok_or_else(|| anyhow!("couldn't find guild")) else { - error!("failed retrieving guild"); + tracing::error!("failed retrieving guild"); return None; }; get_user_id(guild.borrow(), &u) }; - debug!("parsed userid {:?}", possible); + tracing::debug!("parsed userid {:?}", possible); match possible { Ok(x) => Some(x), @@ -276,7 +272,7 @@ async fn _game( let res = DISCORD_MAP.get(&uid).map(|s| s.to_lowercase()); if res.is_none() { - info!("user {uid} is not recognized"); + tracing::info!("user {uid} is not recognized"); } res @@ -314,7 +310,7 @@ async fn _game( let inferred = users.is_empty(); if inferred && users.len() < 2 || !inferred && users.is_empty() { - info!("too few known users to make game comparison"); + tracing::info!("too few known users to make game comparison"); util::reply(ctx, "yer too lonely").await?; return Ok(()); } @@ -458,7 +454,7 @@ pub async fn updategaem(ctx: PoiseContext<'_>, user: Option<String>) -> anyhow:: }, }; - debug!("parsed userid {:?}", user); + tracing::debug!("parsed userid {:?}", user); let username = match DISCORD_MAP.get(&user) { Some(s) => s, @@ -498,7 +494,7 @@ pub async fn updategaem(ctx: PoiseContext<'_>, user: Option<String>) -> anyhow:: let appid_column = match appid_column { Some(c) => &spreadsheet[c][1..], None => { - error!("didn't find an appid column in the spreadsheet"); + tracing::error!("didn't find an appid column in the spreadsheet"); util::reply(ctx, "SPREADSHEET BROKE").await?; return Ok(()); }, @@ -555,7 +551,7 @@ pub async fn updategaem(ctx: PoiseContext<'_>, user: Option<String>) -> anyhow:: let games_owned = games_owned.response.games.into_iter().map(|ge| ge.app_id).collect::<FnvHashSet<_>>(); - debug!("user owns {} steam games", games_owned.len()); + tracing::debug!("user owns {} steam games", games_owned.len()); let found_games = missing_appids .filter_map(|(ai, x)| { diff --git a/src/commands/meme/create.rs b/src/commands/meme/create.rs index 185e1f6..a4e9656 100644 --- a/src/commands/meme/create.rs +++ b/src/commands/meme/create.rs @@ -2,11 +2,7 @@ use std::process::Stdio; use anyhow::anyhow; use diesel::result::Error as DieselError; -use log::{ - debug, - error, - warn, -}; +use grate::tracing; use serenity::all::ReactionType; use tap::Pipe; use tokio::{ @@ -40,7 +36,7 @@ pub async fn addmeme( let image = util::msg(ctx).and_then(|msg| msg.attachments.first()); if image.is_none() && text.is_none() { - warn!("tried to create non-audio meme with no image or text"); + tracing::warn!("tried to create non-audio meme with no image or text"); util::reply(ctx, "hahAA it's empty xdddd").await?; return Ok(()); @@ -74,7 +70,7 @@ pub async fn addmeme( if let Some(DieselError::DatabaseError(DatabaseErrorKind::UniqueViolation, _)) = e.downcast_ref::<DieselError>() { - error!("tried to create meme that already exists"); + tracing::error!("tried to create meme that already exists"); util::react(ctx, '❌').await?; util::reply(ctx, "that meme already exists").await?; @@ -97,7 +93,7 @@ pub async fn addaudiomeme( audio_str: String, #[rest] text: Option<String>, ) -> anyhow::Result<()> { - debug!("running addaudiomeme"); + tracing::debug!("running addaudiomeme"); let elems = audio_str.split_whitespace().collect::<Vec<_>>(); @@ -113,7 +109,7 @@ pub async fn addaudiomeme( util::react(ctx, '🔃').await?; let youtube_url = util::ytdl_url(audio_link.as_str()).await?; - debug!("got download url: {youtube_url}"); + tracing::debug!("got download url: {youtube_url}"); let duration_opts = if let Some(e) = end { vec![ @@ -166,10 +162,10 @@ pub async fn addaudiomeme( let mut audio_data = Vec::new(); let bytes = audio_reader.read_to_end(&mut audio_data).await?; - debug!("downloaded audio ({} bytes)", audio_data.len()); + tracing::debug!("downloaded audio ({} bytes)", audio_data.len()); if bytes == 0 { - debug!("read 0 bytes from audio reader"); + tracing::debug!("read 0 bytes from audio reader"); util::unreact(ctx, '🔃').await?; util::reply(ctx, "🔇🔇🔇🔕🔕🔕🔕🔕🔇🔕🔕🔇🔕🔕📣📢📣📢📣").await?; @@ -200,7 +196,7 @@ pub async fn addaudiomeme( if let Some(DieselError::DatabaseError(DatabaseErrorKind::UniqueViolation, _)) = e.downcast_ref::<DieselError>() { - error!("tried to create meme that already exists"); + tracing::error!("tried to create meme that already exists"); util::react(ctx, ReactionType::Unicode("❌".to_owned())).await?; util::reply(ctx, "that meme already exists").await?; diff --git a/src/commands/meme/delete.rs b/src/commands/meme/delete.rs index 4769cc8..560da28 100644 --- a/src/commands/meme/delete.rs +++ b/src/commands/meme/delete.rs @@ -2,7 +2,7 @@ use diesel::{ result::Error as DieselError, NotFound, }; -use log::info; +use grate::tracing; use serenity::all::ReactionType; use crate::{ @@ -26,7 +26,7 @@ pub async fn delmeme(ctx: PoiseContext<'_>, title: String) -> anyhow::Result<()> }, Err(e) => { if let Some(NotFound) = e.downcast_ref::<DieselError>() { - info!("attempted to delete nonexistent meme: '{}'", title); + tracing::info!("attempted to delete nonexistent meme: '{}'", title); util::react(ctx, ReactionType::Unicode("❓".to_owned())).await?; util::reply(ctx, "nice try").await?; diff --git a/src/commands/meme/history.rs b/src/commands/meme/history.rs index 68416e5..e3d0de3 100644 --- a/src/commands/meme/history.rs +++ b/src/commands/meme/history.rs @@ -3,13 +3,9 @@ use diesel::{ result::Error as DieselError, NotFound, }; +use grate::tracing; use itertools::Itertools; use lazy_static::lazy_static; -use log::{ - debug, - error, - info, -}; use serenity::{ futures::{ StreamExt, @@ -58,7 +54,7 @@ pub async fn wat(ctx: PoiseContext<'_>) -> anyhow::Result<()> { Ok(x) => x, Err(e) => { if let Some(NotFound) = e.downcast_ref::<DieselError>() { - info!("found no memes in history"); + tracing::info!("found no memes in history"); util::reply(ctx, "no one has ever memed before").await?; return Ok(()); @@ -89,7 +85,7 @@ pub async fn wat(ctx: PoiseContext<'_>) -> anyhow::Result<()> { }, Err(e) => { if let Some(NotFound) = e.downcast_ref::<DieselError>() { - info!("last meme not found in database"); + tracing::info!("last meme not found in database"); util::reply(ctx, "heuueueeeeh?").await?; return Ok(()); @@ -110,7 +106,10 @@ pub async fn history(ctx: PoiseContext<'_>, n: Option<usize>) -> anyhow::Result< let n = n.unwrap_or(CONFIG.default_hist); if n > CONFIG.max_hist { - debug!("user requested more than MAX_HIST ({}) items from history", CONFIG.max_hist); + tracing::debug!( + "user requested more than MAX_HIST ({}) items from history", + CONFIG.max_hist + ); util::reply(ctx, "YER PUSHIN ME OVER THE FUCKIN LINE").await?; } @@ -122,13 +121,13 @@ pub async fn history(ctx: PoiseContext<'_>, n: Option<usize>) -> anyhow::Result< }; if records.is_empty() { - info!("no memes in history"); + tracing::info!("no memes in history"); util::reply(ctx, "i don't remember anything :(").await?; return Ok(()); } - info!("reporting meme history (len {})", n); + tracing::info!("reporting meme history (len {})", n); let resp = serenity::futures::stream::iter(records.into_iter().enumerate().rev()) .then(|(i, rec)| async move { @@ -182,7 +181,7 @@ pub async fn history(ctx: PoiseContext<'_>, n: Option<usize>) -> anyhow::Result< Err(e) => { if let Some(variant) = e.downcast_ref::<DieselError>() { if *variant != NotFound { - error!("error encountered loading meme history: {}", e); + tracing::error!("error encountered loading meme history: {}", e); } } @@ -213,7 +212,7 @@ pub async fn stats(ctx: PoiseContext<'_>) -> anyhow::Result<()> { let mut conn = connection().await?; let stats = db::stats(&mut conn).await?; - debug!("reporting stats"); + tracing::debug!("reporting stats"); let rand_user: User = UserId::new(stats.most_random_meme_user).to_user(&ctx).await?; let direct_user: User = UserId::new(stats.most_directly_named_meme_user).to_user(&ctx).await?; @@ -408,7 +407,7 @@ pub async fn query(ctx: PoiseContext<'_>, rest: util::RestVec) -> anyhow::Result .join("\n"); if result.is_empty() { - info!("no memes matched query"); + tracing::info!("no memes matched query"); util::reply(ctx, "no match").await?; return Ok(()); diff --git a/src/commands/meme/invoke.rs b/src/commands/meme/invoke.rs index 1d9040d..37a78f5 100644 --- a/src/commands/meme/invoke.rs +++ b/src/commands/meme/invoke.rs @@ -2,7 +2,7 @@ use diesel::{ result::Error as DieselError, NotFound, }; -use log::info; +use grate::tracing; use crate::{ commands::meme::send_meme, @@ -89,7 +89,7 @@ pub(crate) async fn _meme( }, Err(e) => { return if let Some(NotFound) = e.downcast_ref::<DieselError>() { - info!("requested meme not found in database"); + tracing::info!("requested meme not found in database"); util::reply(ctx, "c'mon baby, guesstimate").await?; Ok(()) @@ -123,7 +123,7 @@ async fn rand_meme(ctx: PoiseContext<'_>, audio_playback: AudioPlayback) -> anyh }, Err(e) => { if let Some(NotFound) = e.downcast_ref::<DieselError>() { - info!("random meme not found"); + tracing::info!("random meme not found"); util::reply(ctx, "i don't know any :(").await?; return Ok(()); @@ -151,7 +151,7 @@ pub async fn rare_meme(ctx: PoiseContext<'_>) -> anyhow::Result<()> { }, Err(e) => { if let Some(NotFound) = e.downcast_ref::<DieselError>() { - info!("rare meme not found"); + tracing::info!("rare meme not found"); util::reply(ctx, "i don't know any :(").await?; return Ok(()); diff --git a/src/commands/meme/mod.rs b/src/commands/meme/mod.rs index ca7714a..4819c1d 100644 --- a/src/commands/meme/mod.rs +++ b/src/commands/meme/mod.rs @@ -1,5 +1,5 @@ use diesel_async::AsyncPgConnection; -use log::debug; +use grate::tracing; use rand::random; use serenity::{ all::ReactionType, @@ -70,7 +70,7 @@ async fn send_meme( let should_tts = t.content.as_ref().map(|t| !t.is_empty()).unwrap_or(false) && random::<u32>() % 25 == 0; - debug!("sending meme (tts: {}): {:?}", should_tts, t); + tracing::debug!("sending meme (tts: {}): {:?}", should_tts, t); let image = t.image(conn).await; let audio = t.audio(conn).await; diff --git a/src/commands/playback.rs b/src/commands/playback.rs index 9b74c02..ad24eb3 100644 --- a/src/commands/playback.rs +++ b/src/commands/playback.rs @@ -1,16 +1,11 @@ -use std::sync::Arc; - -use log::{ - debug, - info, - warn, -}; +use grate::tracing; use serenity::prelude::*; use songbird::{ input::YoutubeDl, Call, Songbird, }; +use std::sync::Arc; use crate::{ bot::HttpKey, @@ -38,9 +33,9 @@ pub async fn songbird(ctx: PoiseContext<'_>) -> anyhow::Result<(Arc<Songbird>, A pub async fn _play(ctx: PoiseContext<'_>, url: &url::Url) -> anyhow::Result<()> { use url::Host; - debug!("playing '{}'", url); + tracing::debug!("playing '{}'", url); if !url.scheme().starts_with("http") { - warn!("got bad url argument to play: {}", url); + tracing::warn!("got bad url argument to play: {}", url); util::reply(ctx, "bAD LiNk").await?; return Ok(()); @@ -52,7 +47,7 @@ pub async fn _play(ctx: PoiseContext<'_>, url: &url::Url) -> anyhow::Result<()> }); if host.is_some_and(|h| h.to_lowercase().contains("imgur")) { - info!("detected imgur link"); + tracing::info!("detected imgur link"); if ctx.author().id == 106160362109272064 { util::reply(ctx, "fuck you conway").await?; diff --git a/src/commands/roll.rs b/src/commands/roll.rs index fd3102c..16fe15f 100644 --- a/src/commands/roll.rs +++ b/src/commands/roll.rs @@ -1,4 +1,5 @@ use crate::util; +use grate::tracing; /// Roll some number of dice or perform a calculation. #[poise::command(prefix_command, guild_only, aliases("calc", "calculate"))] @@ -8,11 +9,11 @@ pub async fn roll<U: Send + Sync>( ) -> anyhow::Result<()> { match thulani_calc::Calc::eval(&rest) { Ok(result) => { - log::debug!("got calc result '{}'", result); + tracing::debug!("got calc result '{}'", result); util::reply(ctx, result.to_string()).await?; }, Err(e) => { - log::error!("error encountered reading calc '{}': {}", rest, e); + tracing::error!("error encountered reading calc '{}': {}", rest, e); util::reply(ctx, "I COULDN'T READ THAT YOU FUCK").await?; }, } diff --git a/src/commands/today/mod.rs b/src/commands/today/mod.rs index 7b5fe8d..0b9b857 100644 --- a/src/commands/today/mod.rs +++ b/src/commands/today/mod.rs @@ -1,6 +1,6 @@ use chrono::Duration; +use grate::tracing; use lazy_static::lazy_static; -use log::debug; use rand::{ seq::SliceRandom, thread_rng, @@ -76,11 +76,11 @@ pub async fn today(ctx: PoiseContext<'_>, #[rest] _rest: Option<String>) -> anyh match dt { Ok(dt) => { - debug!("overriding with datetime: {dt}"); + tracing::debug!("overriding with datetime: {dt}"); result = dt; }, Err(e) => { - debug!("parsing datetime: {e:?}"); + tracing::debug!("parsing datetime: {e:?}"); }, }; } @@ -91,7 +91,7 @@ pub async fn today(ctx: PoiseContext<'_>, #[rest] _rest: Option<String>) -> anyh let options: Vec<TodayArgs> = ALL.iter().flat_map(|f| f(today)).collect(); - debug!("{} options for {}", options.len(), today); + tracing::debug!("{} options for {}", options.len(), today); let play_args = options.choose(&mut thread_rng()); |
