add tracing

This commit is contained in:
Oliver Atkinson
2024-07-25 10:56:45 -06:00
parent f433e0e4af
commit 79638ed324
4 changed files with 160 additions and 17 deletions

View File

@@ -3,6 +3,7 @@ use std::{collections::HashMap, fmt::Display, sync::Arc};
use crate::Context;
use anyhow::Error;
use poise::serenity_prelude::{Cache, CacheHttp, ChannelId, ChannelType, GetMessages, GuildChannel, Http, Message};
use tracing::error;
struct Server {
channels: Vec<Channel>,
@@ -149,18 +150,18 @@ impl Server {
// store messages in our server object
channel.messages = mesgs;
if channel.messages.is_empty() {
eprintln!("{} was empty - (Or incorrect permissions)", channel.this.name);
error!("{} was empty - (Or incorrect permissions)", channel.this.name);
}
},
Err(e) => {
eprintln!("{}", e);
error!("{}", e);
},
}
// Clone *should* be cheap - it's Arc under the hood
Box::pin(walk_channels(&mut channel.children, cache.clone(), settings)).await;
}
}
}
}
/// Walk thru all the channels and count the saved messages. Will only give relevant data if
/// done after `scrape_all()`.
@@ -195,8 +196,8 @@ async fn index(map: HashMap<ChannelId, GuildChannel>) -> Server {
map.into_iter().for_each(|(_id, current)| {
// println!("{} {} {:?}", current.name, current.id, current.parent_id);
server.add(current);
// TODO take note of position
// Take node of vc user limit
// TODO Take note of position
// TODO Take node of vc user limit
});
server.clean();
server

View File

@@ -1,5 +1,7 @@
use once_cell::sync::Lazy;
use poise::serenity_prelude::{self as serenity, GatewayIntents};
use tracing::{debug, error, info, warn, Level};
use tracing_subscriber::EnvFilter;
mod command;
pub struct Data {} // User data, which is stored and accessible in all command invocations
@@ -12,16 +14,31 @@ static ENV: Lazy<BotEnv> = Lazy::new(|| {
#[tokio::main]
async fn main() {
// Start the tracing subscriber
let filter = EnvFilter::builder()
.parse("room_clocks=trace,poem=debug,tokio=warn")
.expect("Could not create env filter.")
;
tracing_subscriber::fmt::fmt()
.with_max_level(Level::TRACE)
.with_target(true)
.with_env_filter(filter)
.with_thread_ids(false)
.with_file(false)
.without_time()
.init();
// Generate sick text like this:
// http://www.patorjk.com/software/taag/#p=testall&f=Graffiti&t=hello%20world
println!(r#"
info!(r#"
Invite this bot with:
"#);
println!("https://discord.com/api/oauth2/authorize?client_id={}&permissions={}&scope=bot",
info!("https://discord.com/api/oauth2/authorize?client_id={}&permissions={}&scope=bot",
ENV.id,
ENV.intents.bits(),
);
print!("\n");
info!("\n");
// Setup framework
let framework = poise::Framework::builder()
@@ -65,9 +82,7 @@ fn read_env() -> BotEnv {
// ==================== ID ===========================
let id: String = std::env::var(DISCORD_ID)
.unwrap_or_else(|_| {
println!(r#"
WARN: Missing {DISCORD_ID}
> This isn't really that problematic, just that the generated invite link won't work."#);
warn!("Missing {DISCORD_ID} This isn't really that problematic, just that the generated invite link won't work.");
String::from("")
});
// ==================== Token ========================
@@ -76,8 +91,8 @@ WARN: Missing {DISCORD_ID}
// ==================== Intents ======================
let intents_env: String = std::env::var(DISCORD_INTENTS)
.unwrap_or_else(|msg| {
println!("DEBUG: what is: {msg}");
println!("ERROR: Missing {DISCORD_INTENTS}");
debug!("What is: {msg}");
error!("Missing {DISCORD_INTENTS}");
"0".to_string()
});
// ==================== Parse Intents =================
@@ -85,7 +100,7 @@ WARN: Missing {DISCORD_ID}
let intents_u64 = intents_env.parse::<u64>().unwrap_or(0u64);
let intents_truncated: GatewayIntents = GatewayIntents::from_bits_truncate(intents_u64);
if intents_truncated.bits() != intents_u64 {
println!("WARN: Intents integer got truncated from {} to {}!", intents_u64, intents_truncated.bits())
warn!("Intents integer got truncated from {} to {}!", intents_u64, intents_truncated.bits())
};
BotEnv {
intents: intents_truncated,