diff options
Diffstat (limited to 'src/bot.rs')
| -rw-r--r-- | src/bot.rs | 52 |
1 files changed, 23 insertions, 29 deletions
@@ -13,14 +13,8 @@ use fnv::{ FnvHashMap, FnvHashSet, }; +use grate::tracing; use lazy_static::lazy_static; -use log::{ - debug, - error, - info, - trace, - warn, -}; use poise::{ BoxFuture, FrameworkError, @@ -75,11 +69,11 @@ impl EventHandler for Handler { let guild = r.guilds.iter().find(|g| g.id == CONFIG.discord.guild()); if guild.is_none() { - info!("bot isn't in configured guild. join here: {:?}", OAUTH_URL.as_str()); + tracing::info!("bot isn't in configured guild. join here: {:?}", OAUTH_URL.as_str()); return; } - info!("connected"); + tracing::info!("connected"); #[cfg(debug_assertions)] let botname = "thulani (dev)"; @@ -89,7 +83,7 @@ impl EventHandler for Handler { if let Some(guild) = guild { if let Err(e) = guild.id.edit_nickname(&ctx, Some(botname)).await { - error!("changing nickname: {:?}", e); + tracing::error!("changing nickname: {:?}", e); } } @@ -104,7 +98,7 @@ impl EventHandler for Handler { } async fn resume(&self, _ctx: Context, _resume: ResumedEvent) { - info!("reconnected to discord"); + tracing::info!("reconnected to discord"); } async fn message_delete( @@ -153,12 +147,12 @@ lazy_static! { .and_then(|f| serde_json::from_reader::<_, Vec<u64>>(f).map_err(anyhow::Error::from)); if let Err(ref e) = restrict_ids { - warn!("opening restrict file: {}", e); + tracing::warn!("opening restrict file: {}", e); } let result = restrict_ids.unwrap_or_default().into_iter().collect::<FnvHashSet<_>>(); - info!("restricted ids: {result:?}"); + tracing::info!("restricted ids: {result:?}"); result }; @@ -167,7 +161,7 @@ lazy_static! { fn on_err(err: FrameworkError<PoiseData, anyhow::Error>) -> BoxFuture<()> { Box::pin(async move { let Some(msg) = err_msg(&err) else { - warn!("error handler missing poise context"); + tracing::warn!("error handler missing poise context"); return; }; @@ -234,7 +228,7 @@ fn on_err(err: FrameworkError<PoiseData, anyhow::Error>) -> BoxFuture<()> { if content.is_empty() { if let Err(e) = util::reply(PoiseContext::Prefix(ctx), "what?").await { - error!("responding to empty message: {e}"); + tracing::error!("responding to empty message: {e}"); }; return; @@ -253,14 +247,14 @@ fn on_err(err: FrameworkError<PoiseData, anyhow::Error>) -> BoxFuture<()> { if let Err(e) = commands::link_unrecognized(PoiseContext::Prefix(ctx), u).await { - error!("processing audio: {e}"); + tracing::error!("processing audio: {e}"); "BANIC".to_string() } else { return; } }, Err(e) => { - error!("processing unrecognized message: {e}"); + tracing::error!("processing unrecognized message: {e}"); "BANIC".to_string() }, } @@ -272,7 +266,7 @@ fn on_err(err: FrameworkError<PoiseData, anyhow::Error>) -> BoxFuture<()> { ) .await { - error!("producing meme for unrecognized: {e}"); + tracing::error!("producing meme for unrecognized: {e}"); "BANIC".to_string() } else { return; @@ -282,14 +276,14 @@ fn on_err(err: FrameworkError<PoiseData, anyhow::Error>) -> BoxFuture<()> { _ => "BANIC".to_string(), }; - error!("error encountered: {err:#?}"); + tracing::error!("error encountered: {err:#?}"); if let Err(e) = msg.react(ctx, ReactionType::Unicode("❌".to_owned())).await { - error!("reacting to failed message: {e}"); + tracing::error!("reacting to failed message: {e}"); } let cm = CreateMessage::default().content(text).tts(msg.tts); if let Err(e) = msg.channel_id.send_message(ctx, cm).await { - error!("sending error to chat: {e}"); + tracing::error!("sending error to chat: {e}"); } }) } @@ -331,7 +325,7 @@ async fn framework() -> poise::Framework<PoiseData, anyhow::Error> { fn check(ctx: PoiseContext) -> BoxFuture<anyhow::Result<bool>> { Box::pin(async move { if !ctx.guild_id().map_or(false, |x| x == CONFIG.discord.guild()) { - info!( + tracing::info!( "rejecting command '{}' from user '{}': wrong guild", ctx.command().name, ctx.author().name @@ -364,7 +358,7 @@ fn check(ctx: PoiseContext) -> BoxFuture<anyhow::Result<bool>> { format!("it is {PERMITTED_WEEKDAY:?}") }; - info!( + tracing::info!( "rejecting command '{}' from user '{}': {}", ctx.command().name, ctx.author().name, @@ -378,7 +372,7 @@ fn check(ctx: PoiseContext) -> BoxFuture<anyhow::Result<bool>> { } fn before_handle<'fut>(ctx: PoiseContext<'fut>) -> Pin<Box<dyn Future<Output = ()> + Send + 'fut>> { - debug!( + tracing::debug!( "got command '{}' from user '{}' ({})", ctx.command().name, ctx.author().name, @@ -390,7 +384,7 @@ fn before_handle<'fut>(ctx: PoiseContext<'fut>) -> Pin<Box<dyn Future<Output = ( fn after_handle(ctx: PoiseContext) -> BoxFuture<()> { Box::pin(async move { - trace!("command '{}' completed successfully", ctx.command().name); + tracing::trace!("command '{}' completed successfully", ctx.command().name); }) } @@ -415,21 +409,21 @@ pub async fn run() -> anyhow::Result<()> { let shard_manager = client.shard_manager.clone(); let run_handle = tokio::spawn(async move { - info!("connecting to discord"); + tracing::info!("connecting to discord"); client.start().await.expect("running discord client"); }); tokio::signal::ctrl_c().await?; - warn!("got ^C, gracefully halting discord"); + tracing::warn!("got ^C, gracefully halting discord"); shard_manager.shutdown_all().await; run_handle.await?; - info!("discord shutdown"); + tracing::info!("discord shutdown"); #[cfg(all(windows, feature = "windows_autostart_postgres"))] unsafe { if started_pg { - log::info!("we started postgres, stopping it before shutdown"); + tracing::info!("we started postgres, stopping it before shutdown"); tokio::task::spawn_blocking(|| util::windows::shutdown_postgres()).await??; } |
