Enable clippy::pedantic lint in code

Add `allow` for unreachable async functions
Reduce unnecessary code in main function using 2 functions
This commit is contained in:
Aadi Desai 2023-09-29 19:16:27 +01:00
parent 497b4576bc
commit 4ddd0315f4
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
4 changed files with 61 additions and 49 deletions

View file

@ -2,6 +2,7 @@ use crate::{db, ACtx, Error};
use poise::serenity_prelude as serenity;
/// Unreachable, used to create edit_member command folder
#[allow(clippy::unused_async)]
#[poise::command(
slash_command,
subcommands(

View file

@ -81,6 +81,7 @@ pub(crate) async fn get_all_members(ctx: ACtx<'_>) -> Result<(), Error> {
}
/// Unreachable, used to create get_member command folder
#[allow(clippy::unused_async)]
#[poise::command(
slash_command,
subcommands(

View file

@ -2,6 +2,7 @@ use crate::{db, ACtx, Error};
use poise::serenity_prelude as serenity;
/// Unreachable, used to create whois command folder
#[allow(clippy::unused_async)]
#[poise::command(
slash_command,
subcommands("whois_by_id", "whois_by_nickname", "whois_by_realname")

View file

@ -1,3 +1,4 @@
#![warn(clippy::pedantic)]
use anyhow::Context as _;
use poise::serenity_prelude as serenity;
@ -55,29 +56,7 @@ async fn poise(
#[shuttle_shared_db::Postgres] pool: sqlx::PgPool,
) -> Result<service::NanoBot, shuttle_runtime::Error> {
// Set Up Tracing Subscriber
use tracing_subscriber as ts;
use ts::prelude::*;
ts::registry()
.with(
ts::fmt::layer()
.without_time()
.with_filter(ts::EnvFilter::new(
"info,nano=info,shuttle=trace,serenity=off",
)),
)
.with(
ts::fmt::layer()
.without_time()
.fmt_fields(ts::fmt::format::debug_fn(|w, f, v| {
if f.name() == "message" {
write!(w, "{v:?}")
} else {
write!(w, "")
}
}))
.with_filter(ts::EnvFilter::new("off,serenity=info")),
)
.init();
init_tracing_subscriber();
tracing::info!("Tracing Subscriber Set Up");
// Run SQLx Migrations
@ -144,32 +123,7 @@ async fn poise(
// Build Poise Instance
let discord = poise::Framework::builder()
.options(poise::FrameworkOptions {
commands: vec![
cmds::cmds(),
cmds::setup(),
cmds::count_members(),
cmds::delete_member(),
cmds::get_all_members(),
cmds::get_member(),
cmds::add_member(),
cmds::insert_member_from_pending(),
cmds::insert_member_from_manual(),
cmds::edit_member(),
cmds::set_members_non_fresher(),
cmds::count_pending(),
cmds::delete_pending(),
cmds::get_all_pending(),
cmds::get_pending(),
cmds::add_pending(),
cmds::delete_all_pending(),
cmds::count_manual(),
cmds::delete_manual(),
cmds::get_all_manual(),
cmds::get_manual(),
cmds::add_manual(),
cmds::delete_all_manual(),
cmds::whois(),
],
commands: all_commands(),
event_handler: { |c, e, f, d| Box::pin(event_handler(c, e, f, d)) },
..Default::default()
})
@ -255,3 +209,58 @@ async fn event_handler(
}
Ok(())
}
fn init_tracing_subscriber() {
use tracing_subscriber as ts;
use ts::prelude::*;
ts::registry()
.with(
ts::fmt::layer()
.without_time()
.with_filter(ts::EnvFilter::new(
"info,nano=info,shuttle=trace,serenity=off",
)),
)
.with(
ts::fmt::layer()
.without_time()
.fmt_fields(ts::fmt::format::debug_fn(|w, f, v| {
if f.name() == "message" {
write!(w, "{v:?}")
} else {
write!(w, "")
}
}))
.with_filter(ts::EnvFilter::new("off,serenity=info")),
)
.init();
}
fn all_commands() -> Vec<poise::Command<Data, Error>> {
vec![
cmds::cmds(),
cmds::setup(),
cmds::count_members(),
cmds::delete_member(),
cmds::get_all_members(),
cmds::get_member(),
cmds::add_member(),
cmds::insert_member_from_pending(),
cmds::insert_member_from_manual(),
cmds::edit_member(),
cmds::set_members_non_fresher(),
cmds::count_pending(),
cmds::delete_pending(),
cmds::get_all_pending(),
cmds::get_pending(),
cmds::add_pending(),
cmds::delete_all_pending(),
cmds::count_manual(),
cmds::delete_manual(),
cmds::get_all_manual(),
cmds::get_manual(),
cmds::add_manual(),
cmds::delete_all_manual(),
cmds::whois(),
]
}