diff options
Diffstat (limited to 'src/bot.rs')
| -rw-r--r-- | src/bot.rs | 57 |
1 files changed, 33 insertions, 24 deletions
@@ -69,7 +69,7 @@ impl EventHandler for Handler { let guild = r.guilds.iter().find(|g| g.id == CONFIG.discord.guild()); if guild.is_none() { - tracing::info!("bot isn't in configured guild. join here: {:?}", OAUTH_URL.as_str()); + tracing::info!(join_url = OAUTH_URL.as_str(), "bot isn't in configured guild"); return; } @@ -147,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 { - tracing::warn!("opening restrict file: {}", e); + tracing::warn!(error = %e, "opening restrict file"); } let result = restrict_ids.unwrap_or_default().into_iter().collect::<FnvHashSet<_>>(); - tracing::info!("restricted ids: {result:?}"); + tracing::info!(restricted_ids = ?result); result }; @@ -228,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 { - tracing::error!("responding to empty message: {e}"); + tracing::error!(error = %e, "responding to empty message"); }; return; @@ -247,14 +247,14 @@ fn on_err(err: FrameworkError<PoiseData, anyhow::Error>) -> BoxFuture<()> { if let Err(e) = commands::link_unrecognized(PoiseContext::Prefix(ctx), u).await { - tracing::error!("processing audio: {e}"); + tracing::error!(error = %e, "processing audio"); "BANIC".to_string() } else { return; } }, Err(e) => { - tracing::error!("processing unrecognized message: {e}"); + tracing::error!(error = %e, "processing unrecognized message"); "BANIC".to_string() }, } @@ -266,7 +266,7 @@ fn on_err(err: FrameworkError<PoiseData, anyhow::Error>) -> BoxFuture<()> { ) .await { - tracing::error!("producing meme for unrecognized: {e}"); + tracing::error!(error = %e, "producing meme for unrecognized"); "BANIC".to_string() } else { return; @@ -278,12 +278,12 @@ fn on_err(err: FrameworkError<PoiseData, anyhow::Error>) -> BoxFuture<()> { tracing::error!("error encountered: {err:#?}"); if let Err(e) = msg.react(ctx, ReactionType::Unicode("❌".to_owned())).await { - tracing::error!("reacting to failed message: {e}"); + tracing::error!(error = %e, "reacting to failed message"); } let cm = CreateMessage::default().content(text).tts(msg.tts); if let Err(e) = msg.channel_id.send_message(ctx, cm).await { - tracing::error!("sending error to chat: {e}"); + tracing::error!(error = %e, "sending error to chat"); } }) } @@ -312,7 +312,7 @@ async fn framework() -> poise::Framework<PoiseData, anyhow::Error> { commands: commands::commands(), owners: HashSet::from_iter([CONFIG.discord.owner()]), initialize_owners: false, - skip_checks_for_owners: true, + skip_checks_for_owners: false, ..Default::default() }) @@ -324,22 +324,30 @@ async fn framework() -> poise::Framework<PoiseData, anyhow::Error> { fn check(ctx: PoiseContext) -> BoxFuture<anyhow::Result<bool>> { Box::pin(async move { + let span = tracing::debug_span!( + "check", + name = %ctx.command().name, + author = %ctx.author().name, + author_id = %ctx.author().id, + ) + .entered(); + if !ctx.guild_id().map_or(false, |x| x == CONFIG.discord.guild()) { - tracing::info!( - "rejecting command '{}' from user '{}': wrong guild", - ctx.command().name, - ctx.author().name - ); + tracing::info!("rejecting command, wrong guild"); + return Ok(false); } if ctx.author().id == CONFIG.discord.owner() { + tracing::info!("author is owner"); + return Ok(true); } let restricted_prefix = RESTRICTED_PREFIXES.iter().any(|&prefix| ctx.prefix() == prefix); if !restricted_prefix { + tracing::debug!("command isn't restricted"); return Ok(true); } @@ -349,6 +357,7 @@ fn check(ctx: PoiseContext) -> BoxFuture<anyhow::Result<bool>> { let restrictions_flipped = chrono::Local::now().weekday() == PERMITTED_WEEKDAY; if user_is_restricted == restrictions_flipped { + tracing::debug!("authorized for restricted command"); return Ok(true); } @@ -359,12 +368,12 @@ fn check(ctx: PoiseContext) -> BoxFuture<anyhow::Result<bool>> { }; tracing::info!( - "rejecting command '{}' from user '{}': {}", - ctx.command().name, - ctx.author().name, - reason + %reason, + "reject restricted command", ); + drop(span); + util::reply(ctx, "no").await?; Ok(false) @@ -373,10 +382,10 @@ fn check(ctx: PoiseContext) -> BoxFuture<anyhow::Result<bool>> { fn before_handle<'fut>(ctx: PoiseContext<'fut>) -> Pin<Box<dyn Future<Output = ()> + Send + 'fut>> { tracing::debug!( - "got command '{}' from user '{}' ({})", - ctx.command().name, - ctx.author().name, - ctx.author().id + name = %ctx.command().name, + author = %ctx.author().name, + author_id = %ctx.author().id, + "got command", ); Box::pin(async {}) @@ -384,7 +393,7 @@ fn before_handle<'fut>(ctx: PoiseContext<'fut>) -> Pin<Box<dyn Future<Output = ( fn after_handle(ctx: PoiseContext) -> BoxFuture<()> { Box::pin(async move { - tracing::trace!("command '{}' completed successfully", ctx.command().name); + tracing::trace!(name = %ctx.command().name, "command completed successfully"); }) } |
