Use tracing macros over (e)println

This commit is contained in:
Aadi Desai 2023-09-29 01:06:37 +01:00
parent 4fc6a9e59f
commit f8eee82843
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
10 changed files with 132 additions and 118 deletions

34
Cargo.lock generated
View file

@ -641,13 +641,12 @@ dependencies = [
[[package]] [[package]]
name = "flume" name = "flume"
version = "0.10.14" version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"futures-sink", "futures-sink",
"pin-project",
"spin 0.9.8", "spin 0.9.8",
] ]
@ -1313,6 +1312,7 @@ dependencies = [
"shuttle-shared-db", "shuttle-shared-db",
"sqlx", "sqlx",
"tokio", "tokio",
"tracing",
"url", "url",
] ]
@ -2542,9 +2542,9 @@ dependencies = [
[[package]] [[package]]
name = "sqlx" name = "sqlx"
version = "0.7.1" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e58421b6bc416714d5115a2ca953718f6c621a51b68e4f4922aea5a4391a721" checksum = "0e50c216e3624ec8e7ecd14c6a6a6370aad6ee5d8cfc3ab30b5162eeeef2ed33"
dependencies = [ dependencies = [
"sqlx-core", "sqlx-core",
"sqlx-macros", "sqlx-macros",
@ -2555,9 +2555,9 @@ dependencies = [
[[package]] [[package]]
name = "sqlx-core" name = "sqlx-core"
version = "0.7.1" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd4cef4251aabbae751a3710927945901ee1d97ee96d757f6880ebb9a79bfd53" checksum = "8d6753e460c998bbd4cd8c6f0ed9a64346fcca0723d6e75e52fdc351c5d2169d"
dependencies = [ dependencies = [
"ahash", "ahash",
"atoi", "atoi",
@ -2596,9 +2596,9 @@ dependencies = [
[[package]] [[package]]
name = "sqlx-macros" name = "sqlx-macros"
version = "0.7.1" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "208e3165167afd7f3881b16c1ef3f2af69fa75980897aac8874a0696516d12c2" checksum = "9a793bb3ba331ec8359c1853bd39eed32cdd7baaf22c35ccf5c92a7e8d1189ec"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2609,9 +2609,9 @@ dependencies = [
[[package]] [[package]]
name = "sqlx-macros-core" name = "sqlx-macros-core"
version = "0.7.1" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a4a8336d278c62231d87f24e8a7a74898156e34c1c18942857be2acb29c7dfc" checksum = "0a4ee1e104e00dedb6aa5ffdd1343107b0a4702e862a84320ee7cc74782d96fc"
dependencies = [ dependencies = [
"dotenvy", "dotenvy",
"either", "either",
@ -2635,9 +2635,9 @@ dependencies = [
[[package]] [[package]]
name = "sqlx-mysql" name = "sqlx-mysql"
version = "0.7.1" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ca69bf415b93b60b80dc8fda3cb4ef52b2336614d8da2de5456cc942a110482" checksum = "864b869fdf56263f4c95c45483191ea0af340f9f3e3e7b4d57a61c7c87a970db"
dependencies = [ dependencies = [
"atoi", "atoi",
"base64 0.21.4", "base64 0.21.4",
@ -2677,9 +2677,9 @@ dependencies = [
[[package]] [[package]]
name = "sqlx-postgres" name = "sqlx-postgres"
version = "0.7.1" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0db2df1b8731c3651e204629dd55e52adbae0462fa1bdcbed56a2302c18181e" checksum = "eb7ae0e6a97fb3ba33b23ac2671a5ce6e3cabe003f451abd5a56e7951d975624"
dependencies = [ dependencies = [
"atoi", "atoi",
"base64 0.21.4", "base64 0.21.4",
@ -2716,9 +2716,9 @@ dependencies = [
[[package]] [[package]]
name = "sqlx-sqlite" name = "sqlx-sqlite"
version = "0.7.1" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4c21bf34c7cae5b283efb3ac1bcc7670df7561124dc2f8bdc0b59be40f79a2" checksum = "d59dc83cf45d89c555a577694534fcd1b55c545a816c816ce51f20bbe56a4f3f"
dependencies = [ dependencies = [
"atoi", "atoi",
"flume", "flume",

View file

@ -20,10 +20,11 @@ serde = { version = "1.0.188", features = ["derive"] }
shuttle-runtime = "0.27.0" shuttle-runtime = "0.27.0"
shuttle-secrets = "0.27.0" shuttle-secrets = "0.27.0"
shuttle-shared-db = { version = "0.27.0", features = ["postgres"] } shuttle-shared-db = { version = "0.27.0", features = ["postgres"] }
sqlx = { version = "0.7.1", features = [ sqlx = { version = "0.7.2", features = [
"macros", "macros",
"postgres", "postgres",
"runtime-tokio-native-tls", "runtime-tokio-native-tls",
] } ] }
tokio = "1.32.0" tokio = "1.32.0"
tracing = "0.1.37"
url = "2.4.1" url = "2.4.1"

View file

@ -3,14 +3,16 @@ use poise::serenity_prelude as serenity;
use poise::Modal; use poise::Modal;
/// Buttons to (de-)register application commands globally or by guild /// Buttons to (de-)register application commands globally or by guild
#[tracing::instrument(skip_all)]
#[poise::command(prefix_command, owners_only)] #[poise::command(prefix_command, owners_only)]
pub(crate) async fn cmds(ctx: poise::Context<'_, Data, Error>) -> Result<(), Error> { pub(crate) async fn cmds(ctx: poise::Context<'_, Data, Error>) -> Result<(), Error> {
println!("Cmd: ({}) cmds", ctx.author().name); tracing::info!("{}", ctx.author().name);
poise::builtins::register_application_commands_buttons(ctx).await?; poise::builtins::register_application_commands_buttons(ctx).await?;
Ok(()) Ok(())
} }
/// Send (customisable) verification introduction message in specified channel /// Send (customisable) verification introduction message in specified channel
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn setup( pub(crate) async fn setup(
ctx: ACtx<'_>, ctx: ACtx<'_>,
@ -35,7 +37,7 @@ pub(crate) async fn setup(
text: Option<String>, text: Option<String>,
} }
println!("Cmd: ({}) setup {}", ctx.author().name, channel.name()); tracing::info!("{} {}", ctx.author().name, channel.name());
if let Some(Setup { if let Some(Setup {
message, message,
@ -73,9 +75,10 @@ pub(crate) async fn setup(
} }
/// Get the number of members in the members table /// Get the number of members in the members table
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn count_members(ctx: ACtx<'_>) -> Result<(), Error> { pub(crate) async fn count_members(ctx: ACtx<'_>) -> Result<(), Error> {
println!("Cmd: ({}) count_members", ctx.author().name); tracing::info!("{}", ctx.author().name);
let count = db::count_members(&ctx.data().db).await?; let count = db::count_members(&ctx.data().db).await?;
ctx.say(format!("There are {count} entries in the members table")) ctx.say(format!("There are {count} entries in the members table"))
.await?; .await?;
@ -83,17 +86,14 @@ pub(crate) async fn count_members(ctx: ACtx<'_>) -> Result<(), Error> {
} }
/// Delete member info by Discord ID /// Delete member info by Discord ID
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn delete_member( pub(crate) async fn delete_member(
ctx: ACtx<'_>, ctx: ACtx<'_>,
id: serenity::Member, id: serenity::Member,
remove_roles: Option<bool>, remove_roles: Option<bool>,
) -> Result<(), Error> { ) -> Result<(), Error> {
println!( tracing::info!("{} {}", ctx.author().name, id.user.name,);
"Cmd: ({}) delete_member {}",
ctx.author().name,
id.user.name,
);
if db::delete_member_by_id(&ctx.data().db, id.user.id.into()).await? { if db::delete_member_by_id(&ctx.data().db, id.user.id.into()).await? {
if remove_roles.unwrap_or(true) { if remove_roles.unwrap_or(true) {
let mut m = id.clone(); let mut m = id.clone();
@ -110,6 +110,7 @@ pub(crate) async fn delete_member(
} }
/// Print all members in members table /// Print all members in members table
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn get_all_members(ctx: ACtx<'_>) -> Result<(), Error> { pub(crate) async fn get_all_members(ctx: ACtx<'_>) -> Result<(), Error> {
#[derive(Modal)] #[derive(Modal)]
@ -119,7 +120,7 @@ pub(crate) async fn get_all_members(ctx: ACtx<'_>) -> Result<(), Error> {
confirm: String, confirm: String,
} }
println!("Cmd: ({}) get_all_members", ctx.author().name); tracing::info!("{}", ctx.author().name);
if let Some(Confirm { confirm }) = Confirm::execute(ctx).await? { if let Some(Confirm { confirm }) = Confirm::execute(ctx).await? {
if confirm.to_lowercase().contains("yes") { if confirm.to_lowercase().contains("yes") {
@ -135,7 +136,7 @@ pub(crate) async fn get_all_members(ctx: ACtx<'_>) -> Result<(), Error> {
.await?; .await?;
} }
Err(e) => { Err(e) => {
eprintln!("Error: {e}"); tracing::error!("{e}");
ctx.say("Failed to create members db file").await?; ctx.say("Failed to create members db file").await?;
} }
} }
@ -166,13 +167,10 @@ pub(crate) async fn get_member(_ctx: ACtx<'_>) -> Result<(), Error> {
} }
/// Get member info by Discord ID /// Get member info by Discord ID
#[tracing::instrument(skip_all)]
#[poise::command(slash_command, rename = "id")] #[poise::command(slash_command, rename = "id")]
pub(crate) async fn get_member_by_id(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> { pub(crate) async fn get_member_by_id(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> {
println!( tracing::info!("{} {}", ctx.author().name, id.user.name,);
"Cmd: ({}) get_member_by_id {}",
ctx.author().name,
id.user.name,
);
match db::get_member_by_id(&ctx.data().db, id.user.id.into()).await? { match db::get_member_by_id(&ctx.data().db, id.user.id.into()).await? {
Some(m) => { Some(m) => {
ctx.say(format!("Member info for {id}:\n```rust\n{m:#?}\n```")) ctx.say(format!("Member info for {id}:\n```rust\n{m:#?}\n```"))
@ -184,12 +182,10 @@ pub(crate) async fn get_member_by_id(ctx: ACtx<'_>, id: serenity::Member) -> Res
} }
/// Get member info by Shortcode /// Get member info by Shortcode
#[tracing::instrument(skip_all)]
#[poise::command(slash_command, rename = "shortcode")] #[poise::command(slash_command, rename = "shortcode")]
pub(crate) async fn get_member_by_shortcode(ctx: ACtx<'_>, shortcode: String) -> Result<(), Error> { pub(crate) async fn get_member_by_shortcode(ctx: ACtx<'_>, shortcode: String) -> Result<(), Error> {
println!( tracing::info!("{} {shortcode}", ctx.author().name);
"Cmd: ({}) get_member_by_shortcode {shortcode}",
ctx.author().name
);
match db::get_member_by_shortcode(&ctx.data().db, &shortcode).await? { match db::get_member_by_shortcode(&ctx.data().db, &shortcode).await? {
Some(m) => { Some(m) => {
ctx.say(format!( ctx.say(format!(
@ -206,12 +202,10 @@ pub(crate) async fn get_member_by_shortcode(ctx: ACtx<'_>, shortcode: String) ->
} }
/// Get member info by Nickname /// Get member info by Nickname
#[tracing::instrument(skip_all)]
#[poise::command(slash_command, rename = "nick")] #[poise::command(slash_command, rename = "nick")]
pub(crate) async fn get_member_by_nickname(ctx: ACtx<'_>, nickname: String) -> Result<(), Error> { pub(crate) async fn get_member_by_nickname(ctx: ACtx<'_>, nickname: String) -> Result<(), Error> {
println!( tracing::info!("{} {nickname}", ctx.author().name);
"Cmd: ({}) get_member_by_nickname {nickname}",
ctx.author().name
);
match db::get_member_by_nickname(&ctx.data().db, &nickname).await? { match db::get_member_by_nickname(&ctx.data().db, &nickname).await? {
Some(m) => { Some(m) => {
ctx.say(format!( ctx.say(format!(
@ -228,12 +222,10 @@ pub(crate) async fn get_member_by_nickname(ctx: ACtx<'_>, nickname: String) -> R
} }
/// Get member info by Real Name /// Get member info by Real Name
#[tracing::instrument(skip_all)]
#[poise::command(slash_command, rename = "name")] #[poise::command(slash_command, rename = "name")]
pub(crate) async fn get_member_by_realname(ctx: ACtx<'_>, realname: String) -> Result<(), Error> { pub(crate) async fn get_member_by_realname(ctx: ACtx<'_>, realname: String) -> Result<(), Error> {
println!( tracing::info!("{} {realname}", ctx.author().name);
"Cmd: ({}) get_member_by_realname {realname}",
ctx.author().name
);
match db::get_member_by_realname(&ctx.data().db, &realname).await? { match db::get_member_by_realname(&ctx.data().db, &realname).await? {
Some(m) => { Some(m) => {
ctx.say(format!( ctx.say(format!(
@ -250,6 +242,7 @@ pub(crate) async fn get_member_by_realname(ctx: ACtx<'_>, realname: String) -> R
} }
/// Add a member to the members table /// Add a member to the members table
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn add_member( pub(crate) async fn add_member(
ctx: ACtx<'_>, ctx: ACtx<'_>,
@ -259,8 +252,8 @@ pub(crate) async fn add_member(
realname: String, realname: String,
fresher: bool, fresher: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
println!( tracing::info!(
"Cmd: ({}) add_member {}, {shortcode}, {realname}, {nickname}", "{} {}, {shortcode}, {realname}, {nickname}",
ctx.author().name, ctx.author().name,
id.user.name, id.user.name,
); );
@ -285,6 +278,7 @@ pub(crate) async fn add_member(
} }
/// Manually add member to members table from pending table /// Manually add member to members table from pending table
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn insert_member_from_pending( pub(crate) async fn insert_member_from_pending(
ctx: ACtx<'_>, ctx: ACtx<'_>,
@ -292,11 +286,7 @@ pub(crate) async fn insert_member_from_pending(
nickname: String, nickname: String,
fresher: bool, fresher: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
println!( tracing::info!("{} {}", ctx.author().name, id.user.name,);
"Cmd: ({}) insert_member_from_pending {}",
ctx.author().name,
id.user.name,
);
match db::insert_member_from_pending(&ctx.data().db, id.user.id.into(), &nickname, fresher) match db::insert_member_from_pending(&ctx.data().db, id.user.id.into(), &nickname, fresher)
.await .await
{ {
@ -310,16 +300,13 @@ pub(crate) async fn insert_member_from_pending(
} }
/// Manually add member to members table from manual table /// Manually add member to members table from manual table
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn insert_member_from_manual( pub(crate) async fn insert_member_from_manual(
ctx: ACtx<'_>, ctx: ACtx<'_>,
id: serenity::Member, id: serenity::Member,
) -> Result<(), Error> { ) -> Result<(), Error> {
println!( tracing::info!("{} {}", ctx.author().name, id.user.name,);
"Cmd: ({}) insert_member_from_manual {}",
ctx.author().name,
id.user.name,
);
match db::insert_member_from_manual(&ctx.data().db, id.user.id.into()).await { match db::insert_member_from_manual(&ctx.data().db, id.user.id.into()).await {
Ok(()) => { Ok(()) => {
ctx.say(format!("Member moved from manual to members table: {id}")) ctx.say(format!("Member moved from manual to members table: {id}"))
@ -345,16 +332,14 @@ pub(crate) async fn edit_member(_ctx: ACtx<'_>) -> Result<(), Error> {
} }
/// Edit member Shortcode /// Edit member Shortcode
#[tracing::instrument(skip_all)]
#[poise::command(slash_command, rename = "shortcode")] #[poise::command(slash_command, rename = "shortcode")]
pub(crate) async fn edit_member_shortcode( pub(crate) async fn edit_member_shortcode(
ctx: ACtx<'_>, ctx: ACtx<'_>,
id: serenity::Member, id: serenity::Member,
shortcode: String, shortcode: String,
) -> Result<(), Error> { ) -> Result<(), Error> {
println!( tracing::info!("{} {shortcode}", ctx.author().name);
"Cmd: ({}) edit_member_shortcode {shortcode}",
ctx.author().name
);
if db::edit_member_shortcode(&ctx.data().db, id.user.id.into(), &shortcode).await? { if db::edit_member_shortcode(&ctx.data().db, id.user.id.into(), &shortcode).await? {
ctx.say(format!("{id} Shortcode updated to {shortcode}")) ctx.say(format!("{id} Shortcode updated to {shortcode}"))
.await?; .await?;
@ -366,16 +351,14 @@ pub(crate) async fn edit_member_shortcode(
} }
/// Edit member Nickname /// Edit member Nickname
#[tracing::instrument(skip_all)]
#[poise::command(slash_command, rename = "nick")] #[poise::command(slash_command, rename = "nick")]
pub(crate) async fn edit_member_nickname( pub(crate) async fn edit_member_nickname(
ctx: ACtx<'_>, ctx: ACtx<'_>,
id: serenity::Member, id: serenity::Member,
nickname: String, nickname: String,
) -> Result<(), Error> { ) -> Result<(), Error> {
println!( tracing::info!("{} {nickname}", ctx.author().name);
"Cmd: ({}) edit_member_nickname {nickname}",
ctx.author().name
);
if db::edit_member_nickname(&ctx.data().db, id.user.id.into(), &nickname).await? { if db::edit_member_nickname(&ctx.data().db, id.user.id.into(), &nickname).await? {
ctx.say(format!("{id} Nick updated to {nickname}")).await?; ctx.say(format!("{id} Nick updated to {nickname}")).await?;
} else { } else {
@ -385,16 +368,14 @@ pub(crate) async fn edit_member_nickname(
} }
/// Edit member Real Name /// Edit member Real Name
#[tracing::instrument(skip_all)]
#[poise::command(slash_command, rename = "name")] #[poise::command(slash_command, rename = "name")]
pub(crate) async fn edit_member_realname( pub(crate) async fn edit_member_realname(
ctx: ACtx<'_>, ctx: ACtx<'_>,
id: serenity::Member, id: serenity::Member,
realname: String, realname: String,
) -> Result<(), Error> { ) -> Result<(), Error> {
println!( tracing::info!("{} {realname}", ctx.author().name);
"Cmd: ({}) edit_member_realname {realname}",
ctx.author().name
);
if db::edit_member_realname(&ctx.data().db, id.user.id.into(), &realname).await? { if db::edit_member_realname(&ctx.data().db, id.user.id.into(), &realname).await? {
ctx.say(format!("{id} Name updated to {realname}")).await?; ctx.say(format!("{id} Name updated to {realname}")).await?;
} else { } else {
@ -404,17 +385,14 @@ pub(crate) async fn edit_member_realname(
} }
/// Edit member fresher status /// Edit member fresher status
#[tracing::instrument(skip_all)]
#[poise::command(slash_command, rename = "fresher")] #[poise::command(slash_command, rename = "fresher")]
pub(crate) async fn edit_member_fresher( pub(crate) async fn edit_member_fresher(
ctx: ACtx<'_>, ctx: ACtx<'_>,
id: serenity::Member, id: serenity::Member,
fresher: bool, fresher: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
println!( tracing::info!("{} {} {fresher}", ctx.author().name, id.user.name,);
"Cmd: ({}) edit_member_fresher {} {fresher}",
ctx.author().name,
id.user.name,
);
if db::edit_member_fresher(&ctx.data().db, id.user.id.into(), fresher).await? { if db::edit_member_fresher(&ctx.data().db, id.user.id.into(), fresher).await? {
ctx.say(format!("{id} Fresher status updated to {fresher}")) ctx.say(format!("{id} Fresher status updated to {fresher}"))
.await?; .await?;
@ -426,9 +404,10 @@ pub(crate) async fn edit_member_fresher(
} }
/// Set all members to non-freshers /// Set all members to non-freshers
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn set_members_non_fresher(ctx: ACtx<'_>) -> Result<(), Error> { pub(crate) async fn set_members_non_fresher(ctx: ACtx<'_>) -> Result<(), Error> {
println!("Cmd: ({}) set_members_non_fresher", ctx.author().name); tracing::info!("{}", ctx.author().name);
let updated = db::set_members_non_fresher(&ctx.data().db).await?; let updated = db::set_members_non_fresher(&ctx.data().db).await?;
ctx.say(format!("{updated} updated to non-fresher, removing roles")) ctx.say(format!("{updated} updated to non-fresher, removing roles"))
.await?; .await?;
@ -440,9 +419,10 @@ pub(crate) async fn set_members_non_fresher(ctx: ACtx<'_>) -> Result<(), Error>
} }
/// Get the number of pending members in the pending table /// Get the number of pending members in the pending table
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn count_pending(ctx: ACtx<'_>) -> Result<(), Error> { pub(crate) async fn count_pending(ctx: ACtx<'_>) -> Result<(), Error> {
println!("Cmd: ({}) count_pending", ctx.author().name); tracing::info!("{}", ctx.author().name);
let count = db::count_pending(&ctx.data().db).await?; let count = db::count_pending(&ctx.data().db).await?;
ctx.say(format!("There are {count} entries in the pending table")) ctx.say(format!("There are {count} entries in the pending table"))
.await?; .await?;
@ -450,13 +430,10 @@ pub(crate) async fn count_pending(ctx: ACtx<'_>) -> Result<(), Error> {
} }
/// Delete pending member info by Discord ID /// Delete pending member info by Discord ID
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn delete_pending(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> { pub(crate) async fn delete_pending(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> {
println!( tracing::info!("{} {}", ctx.author().name, id.user.name,);
"Cmd: ({}) delete_pending {}",
ctx.author().name,
id.user.name,
);
if db::delete_pending_by_id(&ctx.data().db, id.user.id.into()).await? { if db::delete_pending_by_id(&ctx.data().db, id.user.id.into()).await? {
ctx.say(format!("Successfully deleted pending member info for {id}")) ctx.say(format!("Successfully deleted pending member info for {id}"))
.await? .await?
@ -468,6 +445,7 @@ pub(crate) async fn delete_pending(ctx: ACtx<'_>, id: serenity::Member) -> Resul
} }
/// Print all pending members in pending table /// Print all pending members in pending table
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn get_all_pending(ctx: ACtx<'_>) -> Result<(), Error> { pub(crate) async fn get_all_pending(ctx: ACtx<'_>) -> Result<(), Error> {
#[derive(Modal)] #[derive(Modal)]
@ -477,7 +455,7 @@ pub(crate) async fn get_all_pending(ctx: ACtx<'_>) -> Result<(), Error> {
confirm: String, confirm: String,
} }
println!("Cmd: ({}) get_all_pending", ctx.author().name); tracing::info!("{}", ctx.author().name);
if let Some(ConfirmPending { confirm }) = ConfirmPending::execute(ctx).await? { if let Some(ConfirmPending { confirm }) = ConfirmPending::execute(ctx).await? {
if confirm.to_lowercase().contains("yes") { if confirm.to_lowercase().contains("yes") {
@ -493,7 +471,7 @@ pub(crate) async fn get_all_pending(ctx: ACtx<'_>) -> Result<(), Error> {
.await?; .await?;
} }
Err(e) => { Err(e) => {
eprintln!("Error: {e}"); tracing::error!("{e}");
ctx.say("Failed to create pending db file").await?; ctx.say("Failed to create pending db file").await?;
} }
} }
@ -510,9 +488,10 @@ pub(crate) async fn get_all_pending(ctx: ACtx<'_>) -> Result<(), Error> {
} }
/// Get pending member info by Discord ID /// Get pending member info by Discord ID
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn get_pending(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> { pub(crate) async fn get_pending(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> {
println!("Cmd: ({}) get_pending {}", ctx.author().name, id.user.name); tracing::info!("{} {}", ctx.author().name, id.user.name);
match db::get_pending_by_id(&ctx.data().db, id.user.id.into()).await? { match db::get_pending_by_id(&ctx.data().db, id.user.id.into()).await? {
Some(p) => { Some(p) => {
ctx.say(format!("Pending info for {id}:\n```rust\n{p:#?}\n```")) ctx.say(format!("Pending info for {id}:\n```rust\n{p:#?}\n```"))
@ -524,6 +503,7 @@ pub(crate) async fn get_pending(ctx: ACtx<'_>, id: serenity::Member) -> Result<(
} }
/// Manually add pending member to pending table /// Manually add pending member to pending table
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn add_pending( pub(crate) async fn add_pending(
ctx: ACtx<'_>, ctx: ACtx<'_>,
@ -531,8 +511,8 @@ pub(crate) async fn add_pending(
shortcode: String, shortcode: String,
realname: String, realname: String,
) -> Result<(), Error> { ) -> Result<(), Error> {
println!( tracing::info!(
"Cmd: ({}) add_pending {}, {shortcode}, {realname}", "{} {}, {shortcode}, {realname}",
ctx.author().name, ctx.author().name,
id.user.name, id.user.name,
); );
@ -550,6 +530,7 @@ pub(crate) async fn add_pending(
} }
/// Delete all pending members in pending table /// Delete all pending members in pending table
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn delete_all_pending(ctx: ACtx<'_>) -> Result<(), Error> { pub(crate) async fn delete_all_pending(ctx: ACtx<'_>) -> Result<(), Error> {
#[derive(Modal)] #[derive(Modal)]
@ -559,7 +540,7 @@ pub(crate) async fn delete_all_pending(ctx: ACtx<'_>) -> Result<(), Error> {
confirm: String, confirm: String,
} }
println!("Cmd: ({}) delete_all_pending", ctx.author().name); tracing::info!("{}", ctx.author().name);
if let Some(ConfirmPurgePending { confirm }) = ConfirmPurgePending::execute(ctx).await? { if let Some(ConfirmPurgePending { confirm }) = ConfirmPurgePending::execute(ctx).await? {
if confirm.to_lowercase().contains("yes") { if confirm.to_lowercase().contains("yes") {
@ -578,9 +559,10 @@ pub(crate) async fn delete_all_pending(ctx: ACtx<'_>) -> Result<(), Error> {
} }
/// Get the number of manual members in the manual table /// Get the number of manual members in the manual table
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn count_manual(ctx: ACtx<'_>) -> Result<(), Error> { pub(crate) async fn count_manual(ctx: ACtx<'_>) -> Result<(), Error> {
println!("Cmd: ({}) count_manual", ctx.author().name); tracing::info!("{}", ctx.author().name);
let count = db::count_manual(&ctx.data().db).await?; let count = db::count_manual(&ctx.data().db).await?;
ctx.say(format!("There are {count} entries in the manual table")) ctx.say(format!("There are {count} entries in the manual table"))
.await?; .await?;
@ -588,13 +570,10 @@ pub(crate) async fn count_manual(ctx: ACtx<'_>) -> Result<(), Error> {
} }
/// Delete manual member info by Discord ID /// Delete manual member info by Discord ID
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn delete_manual(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> { pub(crate) async fn delete_manual(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> {
println!( tracing::info!("{} {}", ctx.author().name, id.user.name,);
"Cmd: ({}) delete_manual {}",
ctx.author().name,
id.user.name,
);
if db::delete_manual_by_id(&ctx.data().db, id.user.id.into()).await? { if db::delete_manual_by_id(&ctx.data().db, id.user.id.into()).await? {
ctx.say(format!("Successfully deleted manual member info for {id}")) ctx.say(format!("Successfully deleted manual member info for {id}"))
.await? .await?
@ -606,6 +585,7 @@ pub(crate) async fn delete_manual(ctx: ACtx<'_>, id: serenity::Member) -> Result
} }
/// Print all manual members in manual table /// Print all manual members in manual table
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn get_all_manual(ctx: ACtx<'_>) -> Result<(), Error> { pub(crate) async fn get_all_manual(ctx: ACtx<'_>) -> Result<(), Error> {
#[derive(Modal)] #[derive(Modal)]
@ -615,7 +595,7 @@ pub(crate) async fn get_all_manual(ctx: ACtx<'_>) -> Result<(), Error> {
confirm: String, confirm: String,
} }
println!("Cmd: ({}) get_all_manual", ctx.author().name); tracing::info!("{}", ctx.author().name);
if let Some(ConfirmManual { confirm }) = ConfirmManual::execute(ctx).await? { if let Some(ConfirmManual { confirm }) = ConfirmManual::execute(ctx).await? {
if confirm.to_lowercase().contains("yes") { if confirm.to_lowercase().contains("yes") {
@ -631,7 +611,7 @@ pub(crate) async fn get_all_manual(ctx: ACtx<'_>) -> Result<(), Error> {
.await?; .await?;
} }
Err(e) => { Err(e) => {
eprintln!("Error: {e}"); tracing::error!("{e}");
ctx.say("Failed to create manual db file").await?; ctx.say("Failed to create manual db file").await?;
} }
} }
@ -648,9 +628,10 @@ pub(crate) async fn get_all_manual(ctx: ACtx<'_>) -> Result<(), Error> {
} }
/// Get manual member info by Discord ID /// Get manual member info by Discord ID
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn get_manual(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> { pub(crate) async fn get_manual(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> {
println!("Cmd: ({}) get_manual {}", ctx.author().name, id.user.name); tracing::info!("{} {}", ctx.author().name, id.user.name);
match db::get_manual_by_id(&ctx.data().db, id.user.id.into()).await? { match db::get_manual_by_id(&ctx.data().db, id.user.id.into()).await? {
Some(m) => { Some(m) => {
ctx.say(format!("Manual info for {id}:\n```rust\n{m:#?}\n```")) ctx.say(format!("Manual info for {id}:\n```rust\n{m:#?}\n```"))
@ -662,6 +643,7 @@ pub(crate) async fn get_manual(ctx: ACtx<'_>, id: serenity::Member) -> Result<()
} }
/// Manually add manual member to manual table /// Manually add manual member to manual table
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn add_manual( pub(crate) async fn add_manual(
ctx: ACtx<'_>, ctx: ACtx<'_>,
@ -671,8 +653,8 @@ pub(crate) async fn add_manual(
realname: String, realname: String,
fresher: bool, fresher: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
println!( tracing::info!(
"Cmd: ({}) add_manual {}, {shortcode}, {realname}, {nickname}", "{} {}, {shortcode}, {realname}, {nickname}",
ctx.author().name, ctx.author().name,
id.user.name, id.user.name,
); );
@ -692,6 +674,7 @@ pub(crate) async fn add_manual(
} }
/// Delete all manual members in manual table /// Delete all manual members in manual table
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn delete_all_manual(ctx: ACtx<'_>) -> Result<(), Error> { pub(crate) async fn delete_all_manual(ctx: ACtx<'_>) -> Result<(), Error> {
#[derive(Modal)] #[derive(Modal)]
@ -701,7 +684,7 @@ pub(crate) async fn delete_all_manual(ctx: ACtx<'_>) -> Result<(), Error> {
confirm: String, confirm: String,
} }
println!("Cmd: ({}) delete_all_manual", ctx.author().name); tracing::info!("{}", ctx.author().name);
if let Some(ConfirmPurgeManual { confirm }) = ConfirmPurgeManual::execute(ctx).await? { if let Some(ConfirmPurgeManual { confirm }) = ConfirmPurgeManual::execute(ctx).await? {
if confirm.to_lowercase().contains("yes") { if confirm.to_lowercase().contains("yes") {
@ -729,9 +712,10 @@ pub(crate) async fn whois(_ctx: ACtx<'_>) -> Result<(), Error> {
} }
/// (Public) Get member info by Discord ID /// (Public) Get member info by Discord ID
#[tracing::instrument(skip_all)]
#[poise::command(slash_command, rename = "id")] #[poise::command(slash_command, rename = "id")]
pub(crate) async fn whois_by_id(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> { pub(crate) async fn whois_by_id(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> {
println!("Cmd: ({}) whois_by_id {}", ctx.author().name, id.user.name); tracing::info!("{} {}", ctx.author().name, id.user.name);
match db::get_member_by_id(&ctx.data().db, id.user.id.into()).await? { match db::get_member_by_id(&ctx.data().db, id.user.id.into()).await? {
Some(m) => { Some(m) => {
ctx.send(|c| c.content(format!("{id}: {}", m.nickname)).ephemeral(true)) ctx.send(|c| c.content(format!("{id}: {}", m.nickname)).ephemeral(true))
@ -749,9 +733,10 @@ pub(crate) async fn whois_by_id(ctx: ACtx<'_>, id: serenity::Member) -> Result<(
} }
/// (Public) Get member info by Nickname (Exact) /// (Public) Get member info by Nickname (Exact)
#[tracing::instrument(skip_all)]
#[poise::command(slash_command, rename = "nick")] #[poise::command(slash_command, rename = "nick")]
pub(crate) async fn whois_by_nickname(ctx: ACtx<'_>, nickname: String) -> Result<(), Error> { pub(crate) async fn whois_by_nickname(ctx: ACtx<'_>, nickname: String) -> Result<(), Error> {
println!("Cmd: ({}) whois_by_nickname {nickname}", ctx.author().name); tracing::info!("{} {nickname}", ctx.author().name);
if let Some(m) = db::get_member_by_nickname(&ctx.data().db, &nickname).await? { if let Some(m) = db::get_member_by_nickname(&ctx.data().db, &nickname).await? {
ctx.send(|c| { ctx.send(|c| {
c.content(format!("{nickname}: <@{}>", m.discord_id)) c.content(format!("{nickname}: <@{}>", m.discord_id))
@ -783,9 +768,10 @@ pub(crate) async fn whois_by_nickname(ctx: ACtx<'_>, nickname: String) -> Result
} }
/// (Public) Get member info by Real Name (Exact) /// (Public) Get member info by Real Name (Exact)
#[tracing::instrument(skip_all)]
#[poise::command(slash_command, rename = "name")] #[poise::command(slash_command, rename = "name")]
pub(crate) async fn whois_by_realname(ctx: ACtx<'_>, realname: String) -> Result<(), Error> { pub(crate) async fn whois_by_realname(ctx: ACtx<'_>, realname: String) -> Result<(), Error> {
println!("Cmd: ({}) whois_by_realname {realname}", ctx.author().name); tracing::info!("{} {realname}", ctx.author().name);
if let Some(m) = db::get_member_by_realname(&ctx.data().db, &realname).await? { if let Some(m) = db::get_member_by_realname(&ctx.data().db, &realname).await? {
ctx.send(|c| { ctx.send(|c| {
c.content(format!("{realname}: <@{}>", m.discord_id)) c.content(format!("{realname}: <@{}>", m.discord_id))

View file

@ -7,6 +7,7 @@ pub struct Member {
pub order_no: usize, pub order_no: usize,
} }
#[tracing::instrument(skip_all)]
pub(crate) async fn get_members_list( pub(crate) async fn get_members_list(
api_key: &str, api_key: &str,
url: &str, url: &str,

View file

@ -101,6 +101,7 @@ async fn poise(
.parse::<u64>() .parse::<u64>()
.expect("SERVER_ID not valid u64") .expect("SERVER_ID not valid u64")
.into(); .into();
tracing::info!("Secrets loaded");
// Build Axum Router // Build Axum Router
let router = axum::Router::new().route( let router = axum::Router::new().route(
@ -178,12 +179,12 @@ async fn event_handler(
) -> Result<(), Error> { ) -> Result<(), Error> {
match event { match event {
poise::Event::GuildMemberAddition { new_member } => { poise::Event::GuildMemberAddition { new_member } => {
println!("Member joined:\n{new_member:#?}"); tracing::info!("Member joined: {}", new_member.user.name);
} }
poise::Event::InteractionCreate { poise::Event::InteractionCreate {
interaction: serenity::Interaction::MessageComponent(m), interaction: serenity::Interaction::MessageComponent(m),
} => { } => {
println!("Interaction: {} by \"{}\"", m.data.custom_id, m.user.name); tracing::info!("Interaction: {} by {}", m.data.custom_id, m.user.name);
match m.data.custom_id.as_str() { match m.data.custom_id.as_str() {
"register.global" | "unregister.global" | "register.guild" | "unregister.guild" => { "register.global" | "unregister.global" | "register.guild" | "unregister.guild" => {
} }
@ -205,7 +206,7 @@ async fn event_handler(
"manual_2n" => verify::manual_2(ctx, m, data, false).await?, "manual_2n" => verify::manual_2(ctx, m, data, false).await?,
id if id.starts_with("verify-") => verify::manual_4(ctx, m, data, id).await?, id if id.starts_with("verify-") => verify::manual_4(ctx, m, data, id).await?,
_ => { _ => {
println!("Unknown interaction, printing:\n{m:#?}"); tracing::info!("Unknown interaction, printing:\n{m:#?}");
verify::unknown(ctx, m).await?; verify::unknown(ctx, m).await?;
} }
} }
@ -213,7 +214,7 @@ async fn event_handler(
poise::Event::InteractionCreate { poise::Event::InteractionCreate {
interaction: serenity::Interaction::ModalSubmit(m), interaction: serenity::Interaction::ModalSubmit(m),
} => { } => {
println!("Modal submit: {} by \"{}\"", m.data.custom_id, m.user.name); tracing::info!("Modal submit: {} by {}", m.data.custom_id, m.user.name);
match m.data.custom_id.as_str() { match m.data.custom_id.as_str() {
"login_6f" => verify::login_6(ctx, m, data, true).await?, "login_6f" => verify::login_6(ctx, m, data, true).await?,
"login_6n" => verify::login_6(ctx, m, data, false).await?, "login_6n" => verify::login_6(ctx, m, data, false).await?,

View file

@ -9,6 +9,7 @@ pub(crate) struct Verify {
key: String, key: String,
} }
#[tracing::instrument(skip_all)]
pub(crate) async fn verify( pub(crate) async fn verify(
pool: sqlx::PgPool, pool: sqlx::PgPool,
payload: Option<Json<Verify>>, payload: Option<Json<Verify>>,
@ -36,7 +37,12 @@ pub(crate) async fn verify(
.await .await
{ {
Ok(_) => { Ok(_) => {
println!("ID {} added: {}, {}", id, verify.shortcode, verify.fullname); tracing::info!(
"ID {} added: {}, {}",
id,
verify.shortcode,
verify.fullname
);
(StatusCode::OK, "Member added to `pending` database").into_response() (StatusCode::OK, "Member added to `pending` database").into_response()
} }
Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, format!("{e}")).into_response(), Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, format!("{e}")).into_response(),

View file

@ -11,6 +11,7 @@ const LOGIN_INTRO: &str = indoc::indoc! {"
You can then complete the remaining details in the next step! You can then complete the remaining details in the next step!
"}; "};
#[tracing::instrument(skip_all)]
pub(crate) async fn login_1( pub(crate) async fn login_1(
ctx: &serenity::Context, ctx: &serenity::Context,
m: &serenity::MessageComponentInteraction, m: &serenity::MessageComponentInteraction,
@ -51,6 +52,7 @@ const LOGIN_FORM: &str = indoc::indoc! {"
The last step is a short form with some extra details The last step is a short form with some extra details
"}; "};
#[tracing::instrument(skip_all)]
pub(crate) async fn login_2( pub(crate) async fn login_2(
ctx: &serenity::Context, ctx: &serenity::Context,
m: &serenity::MessageComponentInteraction, m: &serenity::MessageComponentInteraction,
@ -58,7 +60,7 @@ pub(crate) async fn login_2(
) -> Result<(), Error> { ) -> Result<(), Error> {
match crate::db::get_pending_by_id(&data.db, m.user.id.into()).await { match crate::db::get_pending_by_id(&data.db, m.user.id.into()).await {
Err(e) => { Err(e) => {
eprintln!("Error in login_2: {e}"); tracing::error!("{e}");
m.create_interaction_response(&ctx.http, |i| { m.create_interaction_response(&ctx.http, |i| {
i.kind(serenity::InteractionResponseType::ChannelMessageWithSource) i.kind(serenity::InteractionResponseType::ChannelMessageWithSource)
.interaction_response_data(|d| { .interaction_response_data(|d| {
@ -105,6 +107,7 @@ pub(crate) async fn login_2(
Ok(()) Ok(())
} }
#[tracing::instrument(skip_all)]
pub(crate) async fn login_3( pub(crate) async fn login_3(
ctx: &serenity::Context, ctx: &serenity::Context,
m: &serenity::MessageComponentInteraction, m: &serenity::MessageComponentInteraction,
@ -139,6 +142,7 @@ pub(crate) async fn login_3(
Ok(()) Ok(())
} }
#[tracing::instrument(skip_all)]
pub(crate) async fn login_4( pub(crate) async fn login_4(
ctx: &serenity::Context, ctx: &serenity::Context,
m: &serenity::MessageComponentInteraction, m: &serenity::MessageComponentInteraction,
@ -177,6 +181,7 @@ struct Nickname {
nickname: String, nickname: String,
} }
#[tracing::instrument(skip_all)]
pub(crate) async fn login_5( pub(crate) async fn login_5(
ctx: &serenity::Context, ctx: &serenity::Context,
m: &serenity::MessageComponentInteraction, m: &serenity::MessageComponentInteraction,
@ -197,6 +202,7 @@ pub(crate) async fn login_5(
Ok(()) Ok(())
} }
#[tracing::instrument(skip_all)]
pub(crate) async fn login_6( pub(crate) async fn login_6(
ctx: &serenity::Context, ctx: &serenity::Context,
m: &serenity::ModalSubmitInteraction, m: &serenity::ModalSubmitInteraction,
@ -217,7 +223,7 @@ pub(crate) async fn login_6(
.await .await
{ {
Ok(()) => { Ok(()) => {
println!( tracing::info!(
"{} ({}) added via login{}", "{} ({}) added via login{}",
m.user.name, m.user.name,
m.user.id, m.user.id,
@ -261,7 +267,7 @@ pub(crate) async fn login_6(
} }
} }
Err(e) => { Err(e) => {
eprintln!("Error: {e}"); tracing::error!("Error: {e}");
m.create_interaction_response(&ctx.http, |i| { m.create_interaction_response(&ctx.http, |i| {
i.kind(serenity::InteractionResponseType::ChannelMessageWithSource) i.kind(serenity::InteractionResponseType::ChannelMessageWithSource)
.interaction_response_data(|d| { .interaction_response_data(|d| {
@ -274,7 +280,7 @@ pub(crate) async fn login_6(
} }
} }
Err(e) => { Err(e) => {
eprintln!("Error: {e}"); tracing::error!("{e}");
} }
}; };
Ok(()) Ok(())

View file

@ -16,6 +16,7 @@ const MANUAL_INTRO: &str = indoc::indoc! {"
First, are you a fresher? First, are you a fresher?
"}; "};
#[tracing::instrument(skip_all)]
pub(crate) async fn manual_1( pub(crate) async fn manual_1(
ctx: &serenity::Context, ctx: &serenity::Context,
m: &serenity::MessageComponentInteraction, m: &serenity::MessageComponentInteraction,
@ -68,6 +69,7 @@ struct Manual {
nickname: String, nickname: String,
} }
#[tracing::instrument(skip_all)]
pub(crate) async fn manual_2( pub(crate) async fn manual_2(
ctx: &serenity::Context, ctx: &serenity::Context,
m: &serenity::MessageComponentInteraction, m: &serenity::MessageComponentInteraction,
@ -92,6 +94,7 @@ pub(crate) async fn manual_2(
Ok(()) Ok(())
} }
#[tracing::instrument(skip_all)]
pub(crate) async fn manual_3( pub(crate) async fn manual_3(
ctx: &serenity::Context, ctx: &serenity::Context,
m: &serenity::ModalSubmitInteraction, m: &serenity::ModalSubmitInteraction,
@ -185,7 +188,7 @@ pub(crate) async fn manual_3(
.await?; .await?;
return Ok(()); return Ok(());
} }
Err(e) => eprintln!("Error: {e}"), Err(e) => tracing::error!("{e}"),
}; };
m.create_interaction_response(&ctx.http, |i| { m.create_interaction_response(&ctx.http, |i| {
i.kind(serenity::InteractionResponseType::ChannelMessageWithSource) i.kind(serenity::InteractionResponseType::ChannelMessageWithSource)
@ -198,6 +201,7 @@ pub(crate) async fn manual_3(
Ok(()) Ok(())
} }
#[tracing::instrument(skip_all)]
pub(crate) async fn manual_4( pub(crate) async fn manual_4(
ctx: &serenity::Context, ctx: &serenity::Context,
m: &serenity::MessageComponentInteraction, m: &serenity::MessageComponentInteraction,
@ -225,7 +229,7 @@ pub(crate) async fn manual_4(
.await? .await?
.unwrap() .unwrap()
.fresher; .fresher;
println!( tracing::info!(
"{} ({}) added via manual{}", "{} ({}) added via manual{}",
user.name, user.name,
user.id, user.id,
@ -253,7 +257,7 @@ pub(crate) async fn manual_4(
} }
} }
Err(e) => { Err(e) => {
eprintln!("Error: {e}"); tracing::error!("{e}");
m.create_interaction_response(&ctx.http, |i| { m.create_interaction_response(&ctx.http, |i| {
i.kind(serenity::InteractionResponseType::ChannelMessageWithSource) i.kind(serenity::InteractionResponseType::ChannelMessageWithSource)
.interaction_response_data(|d| { .interaction_response_data(|d| {
@ -265,7 +269,7 @@ pub(crate) async fn manual_4(
} }
} else { } else {
crate::db::delete_manual_by_id(&data.db, user.id.into()).await?; crate::db::delete_manual_by_id(&data.db, user.id.into()).await?;
println!("{} ({}) denied via manual", user.name, user.id); tracing::info!("{} ({}) denied via manual", user.name, user.id);
m.create_interaction_response(&ctx.http, |i| { m.create_interaction_response(&ctx.http, |i| {
i.kind(serenity::InteractionResponseType::UpdateMessage) i.kind(serenity::InteractionResponseType::UpdateMessage)
.interaction_response_data(|d| { .interaction_response_data(|d| {

View file

@ -12,6 +12,7 @@ const MEMBERSHIP_INTRO: &str = indoc::indoc! {"
First, are you a fresher? First, are you a fresher?
"}; "};
#[tracing::instrument(skip_all)]
pub(crate) async fn membership_1( pub(crate) async fn membership_1(
ctx: &serenity::Context, ctx: &serenity::Context,
m: &serenity::MessageComponentInteraction, m: &serenity::MessageComponentInteraction,
@ -60,6 +61,7 @@ struct Membership {
nickname: String, nickname: String,
} }
#[tracing::instrument(skip_all)]
pub(crate) async fn membership_2( pub(crate) async fn membership_2(
ctx: &serenity::Context, ctx: &serenity::Context,
m: &serenity::MessageComponentInteraction, m: &serenity::MessageComponentInteraction,
@ -87,6 +89,7 @@ pub(crate) async fn membership_2(
Ok(()) Ok(())
} }
#[tracing::instrument(skip_all)]
pub(crate) async fn membership_3( pub(crate) async fn membership_3(
ctx: &serenity::Context, ctx: &serenity::Context,
m: &serenity::ModalSubmitInteraction, m: &serenity::ModalSubmitInteraction,
@ -102,7 +105,7 @@ pub(crate) async fn membership_3(
let members = match crate::ea::get_members_list(&data.ea_key, &data.ea_url).await { let members = match crate::ea::get_members_list(&data.ea_key, &data.ea_url).await {
Ok(v) => v, Ok(v) => v,
Err(e) => { Err(e) => {
eprintln!("Error: {e}"); tracing::error!("{e}");
m.create_interaction_response(&ctx.http, |i| { m.create_interaction_response(&ctx.http, |i| {
i.kind(serenity::InteractionResponseType::ChannelMessageWithSource) i.kind(serenity::InteractionResponseType::ChannelMessageWithSource)
.interaction_response_data(|d| { .interaction_response_data(|d| {
@ -140,7 +143,7 @@ pub(crate) async fn membership_3(
.await .await
.is_ok() .is_ok()
{ {
println!( tracing::info!(
"{} ({}) added via membership{}", "{} ({}) added via membership{}",
m.user.name, m.user.name,
m.user.id, m.user.id,
@ -183,7 +186,7 @@ pub(crate) async fn membership_3(
return Ok(()); return Ok(());
} }
} }
Err(e) => eprintln!("Error: {e}"), Err(e) => tracing::error!("{e}"),
}; };
m.create_interaction_response(&ctx.http, |i| { m.create_interaction_response(&ctx.http, |i| {
i.kind(serenity::InteractionResponseType::ChannelMessageWithSource) i.kind(serenity::InteractionResponseType::ChannelMessageWithSource)

View file

@ -20,6 +20,7 @@ const INFO_MSG: &str = indoc::indoc! {"
If you have any questions, feel free to ping or message <@99217900254035968> If you have any questions, feel free to ping or message <@99217900254035968>
"}; "};
#[tracing::instrument(skip_all)]
pub(crate) async fn info( pub(crate) async fn info(
ctx: &serenity::Context, ctx: &serenity::Context,
m: &serenity::MessageComponentInteraction, m: &serenity::MessageComponentInteraction,
@ -32,6 +33,7 @@ pub(crate) async fn info(
Ok(()) Ok(())
} }
#[tracing::instrument(skip_all)]
pub(crate) async fn unknown( pub(crate) async fn unknown(
ctx: &serenity::Context, ctx: &serenity::Context,
m: &serenity::MessageComponentInteraction, m: &serenity::MessageComponentInteraction,
@ -54,6 +56,7 @@ const START_MSG: &str = indoc::indoc! {"
- 🚗 Manual verification, eg. using College ID Card or Acceptance Letter - 🚗 Manual verification, eg. using College ID Card or Acceptance Letter
"}; "};
#[tracing::instrument(skip_all)]
pub(crate) async fn start( pub(crate) async fn start(
ctx: &serenity::Context, ctx: &serenity::Context,
m: &serenity::MessageComponentInteraction, m: &serenity::MessageComponentInteraction,
@ -112,6 +115,7 @@ pub(crate) async fn start(
Ok(()) Ok(())
} }
#[tracing::instrument(skip_all)]
pub(crate) async fn apply_role( pub(crate) async fn apply_role(
ctx: &serenity::Context, ctx: &serenity::Context,
member: &mut serenity::Member, member: &mut serenity::Member,
@ -120,6 +124,7 @@ pub(crate) async fn apply_role(
Ok(member.add_role(&ctx.http, role).await?) Ok(member.add_role(&ctx.http, role).await?)
} }
#[tracing::instrument(skip_all)]
pub(crate) async fn remove_role( pub(crate) async fn remove_role(
ctx: &serenity::Context, ctx: &serenity::Context,
member: &mut serenity::Member, member: &mut serenity::Member,
@ -128,6 +133,7 @@ pub(crate) async fn remove_role(
Ok(member.remove_role(&ctx.http, role).await?) Ok(member.remove_role(&ctx.http, role).await?)
} }
#[tracing::instrument(skip_all)]
pub(crate) async fn welcome_user( pub(crate) async fn welcome_user(
http: impl AsRef<serenity::http::Http>, http: impl AsRef<serenity::http::Http>,
channel: &serenity::ChannelId, channel: &serenity::ChannelId,