Replace per-use crate:: with per-file use crate::

This commit is contained in:
Aadi Desai 2024-02-02 16:53:48 +00:00
parent ba2c820d81
commit e8502feb74
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
7 changed files with 43 additions and 50 deletions

View file

@ -1,4 +1,4 @@
use crate::{db, ACtx, Error, Gaijin};
use crate::{db, verify, ACtx, Error, Gaijin};
use poise::{
serenity_prelude::{self as serenity, CreateAttachment, CreateMessage},
Modal,
@ -27,7 +27,7 @@ pub(crate) async fn delete_gaijin(
tracing::info!("{} {}", ctx.author().name, id.user.name);
if db::delete_gaijin_by_id(&ctx.data().db, id.user.id.into()).await? {
if remove_roles.unwrap_or(true) {
crate::verify::remove_role(ctx.serenity_context(), &mut id, ctx.data().gaijin).await?;
verify::remove_role(ctx.serenity_context(), &mut id, ctx.data().gaijin).await?;
}
ctx.say(format!("Successfully deleted gaijin info for {id}"))
.await?
@ -156,7 +156,7 @@ pub(crate) async fn add_gaijin(
},
)
.await?;
crate::verify::apply_role(ctx.serenity_context(), &mut id, ctx.data().gaijin).await?;
verify::apply_role(ctx.serenity_context(), &mut id, ctx.data().gaijin).await?;
ctx.say(format!("Gaijin added: {id}")).await?;
Ok(())
}

View file

@ -1,4 +1,4 @@
use crate::{db, ACtx, Error, Member};
use crate::{db, verify, ACtx, Error, Member};
use poise::serenity_prelude::{self as serenity, CreateAttachment, CreateMessage};
use poise::Modal;
@ -24,8 +24,8 @@ pub(crate) async fn delete_member(
tracing::info!("{} {}", ctx.author().name, id.user.name);
if db::delete_member_by_id(&ctx.data().db, id.user.id.into()).await? {
if remove_roles.unwrap_or(true) {
crate::verify::remove_role(ctx.serenity_context(), &mut id, ctx.data().member).await?;
crate::verify::remove_role(ctx.serenity_context(), &mut id, ctx.data().fresher).await?;
verify::remove_role(ctx.serenity_context(), &mut id, ctx.data().member).await?;
verify::remove_role(ctx.serenity_context(), &mut id, ctx.data().fresher).await?;
}
ctx.say(format!("Successfully deleted member info for {id}"))
.await?
@ -198,9 +198,9 @@ pub(crate) async fn add_member(
},
)
.await?;
crate::verify::apply_role(ctx.serenity_context(), &mut id, ctx.data().member).await?;
verify::apply_role(ctx.serenity_context(), &mut id, ctx.data().member).await?;
if fresher {
crate::verify::apply_role(ctx.serenity_context(), &mut id, ctx.data().fresher).await?;
verify::apply_role(ctx.serenity_context(), &mut id, ctx.data().fresher).await?;
}
ctx.say(format!("Member added: {id}")).await?;
Ok(())

View file

@ -1,4 +1,4 @@
use crate::PendingMember;
use crate::{db, PendingMember};
use axum::{http::StatusCode, response::IntoResponse, Json};
#[tracing::instrument]
@ -29,9 +29,9 @@ pub(crate) async fn verify(
};
// Delete from pending if exists
let _ = crate::db::delete_pending_by_id(&pool, id).await;
let _ = db::delete_pending_by_id(&pool, id).await;
match crate::db::insert_pending(
match db::insert_pending(
&pool,
PendingMember {
discord_id: id,

View file

@ -1,4 +1,4 @@
use crate::{Data, Error};
use crate::{db, verify, Data, Error};
use poise::serenity_prelude::{
self as serenity, CreateActionRow, CreateButton, CreateEmbed, CreateInteractionResponse,
CreateInteractionResponseMessage, CreateMessage,
@ -55,7 +55,7 @@ pub(crate) async fn login_2(
m: &serenity::ComponentInteraction,
data: &Data,
) -> Result<(), Error> {
match crate::db::get_pending_by_id(&data.db, m.user.id.into()).await {
match db::get_pending_by_id(&data.db, m.user.id.into()).await {
Err(e) => {
tracing::error!("{e}");
m.create_response(
@ -196,15 +196,10 @@ pub(crate) async fn login_6(
match Nickname::parse(m.data.clone()) {
Ok(Nickname { nickname }) => {
// Delete from manual if exists
let _ = crate::db::delete_manual_by_id(&data.db, m.user.id.into()).await;
let _ = db::delete_manual_by_id(&data.db, m.user.id.into()).await;
match crate::db::insert_member_from_pending(
&data.db,
m.user.id.into(),
&nickname,
fresher,
)
.await
match db::insert_member_from_pending(&data.db, m.user.id.into(), &nickname, fresher)
.await
{
Ok(p) => {
tracing::info!(
@ -214,9 +209,9 @@ pub(crate) async fn login_6(
if fresher { " (fresher)" } else { "" }
);
let mut mm = m.member.clone().unwrap();
crate::verify::apply_role(ctx, &mut mm, data.member).await?;
verify::apply_role(ctx, &mut mm, data.member).await?;
if fresher {
crate::verify::apply_role(ctx, &mut mm, data.fresher).await?;
verify::apply_role(ctx, &mut mm, data.fresher).await?;
}
let msg = if fresher {
"Congratulations, you have completed verification and now \
@ -251,10 +246,9 @@ pub(crate) async fn login_6(
.await?;
let _ = mm.remove_role(&ctx.http, data.non_member).await;
if mm.roles.contains(&data.old_member) {
crate::verify::remove_role(ctx, &mut mm, data.old_member).await?;
verify::remove_role(ctx, &mut mm, data.old_member).await?;
} else {
crate::verify::welcome_user(&ctx.http, &data.gn_ch_id, &m.user, fresher)
.await?;
verify::welcome_user(&ctx.http, &data.gn_ch_id, &m.user, fresher).await?;
}
}
Err(e) => {

View file

@ -1,4 +1,4 @@
use crate::{Data, Error};
use crate::{db, verify, Data, Error, ManualMember};
use poise::serenity_prelude::{
self as serenity, CreateActionRow, CreateButton, CreateEmbed, CreateInteractionResponse,
CreateInteractionResponseMessage, CreateMessage,
@ -74,7 +74,7 @@ pub(crate) async fn manual_2(
fresher: bool,
) -> Result<(), Error> {
// Delete from manual if exists
let _ = crate::db::delete_manual_by_id(&data.db, m.user.id.into()).await;
let _ = db::delete_manual_by_id(&data.db, m.user.id.into()).await;
m.create_response(
&ctx.http,
@ -119,7 +119,7 @@ pub(crate) async fn manual_3(
}
// Delete from pending if exists
let _ = crate::db::delete_pending_by_id(&data.db, m.user.id.into()).await?;
let _ = db::delete_pending_by_id(&data.db, m.user.id.into()).await?;
let prompt_sent = data
.au_ch_id
@ -153,9 +153,9 @@ pub(crate) async fn manual_3(
.await
.is_ok();
let inserted = crate::db::insert_manual(
let inserted = db::insert_manual(
&data.db,
crate::ManualMember {
ManualMember {
discord_id: m.user.id.into(),
shortcode,
nickname,
@ -223,7 +223,7 @@ pub(crate) async fn manual_4(
let mut member = data.server.member(&ctx.http, &user).await?;
if verify {
match crate::db::insert_member_from_manual(&data.db, user.id.into()).await {
match db::insert_member_from_manual(&data.db, user.id.into()).await {
Ok(mm) => {
let fresher = crate::db::get_member_by_id(&data.db, user.id.into())
.await?
@ -235,9 +235,9 @@ pub(crate) async fn manual_4(
user.id,
if fresher { " (fresher)" } else { "" }
);
crate::verify::apply_role(ctx, &mut member, data.member).await?;
if fresher {
crate::verify::apply_role(ctx, &mut member, data.fresher).await?;
verify::apply_role(ctx, &mut member, data.member).await?;
verify::apply_role(ctx, &mut member, data.fresher).await?;
}
m.create_response(
&ctx.http,
@ -259,9 +259,9 @@ pub(crate) async fn manual_4(
.await?;
let _ = member.remove_role(&ctx.http, data.non_member).await;
if member.roles.contains(&data.old_member) {
crate::verify::remove_role(ctx, &mut member, data.old_member).await?;
verify::remove_role(ctx, &mut member, data.old_member).await?;
} else {
crate::verify::welcome_user(&ctx.http, &data.gn_ch_id, &user, fresher).await?;
verify::welcome_user(&ctx.http, &data.gn_ch_id, &user, fresher).await?;
}
}
Err(e) => {
@ -277,7 +277,7 @@ pub(crate) async fn manual_4(
}
}
} else {
crate::db::delete_manual_by_id(&data.db, user.id.into()).await?;
db::delete_manual_by_id(&data.db, user.id.into()).await?;
tracing::info!("{} ({}) denied via manual", user.name, user.id);
m.create_response(
&ctx.http,

View file

@ -1,4 +1,4 @@
use crate::{Data, Error};
use crate::{db, ea, verify, Data, Error, Member};
use poise::serenity_prelude::{
self as serenity, CreateActionRow, CreateButton, CreateEmbed, CreateInteractionResponse,
CreateInteractionResponseMessage, CreateMessage,
@ -68,10 +68,10 @@ pub(crate) async fn membership_2(
fresher: bool,
) -> Result<(), Error> {
// Delete from pending if exists
let _ = crate::db::delete_pending_by_id(&data.db, m.user.id.into()).await;
let _ = db::delete_pending_by_id(&data.db, m.user.id.into()).await;
// Delete from manual if exists
let _ = crate::db::delete_manual_by_id(&data.db, m.user.id.into()).await;
let _ = db::delete_manual_by_id(&data.db, m.user.id.into()).await;
m.create_response(
&ctx.http,
@ -101,7 +101,7 @@ pub(crate) async fn membership_3(
shortcode,
nickname,
}) => {
let members = match crate::ea::get_members_list(&data.ea_key, &data.ea_url).await {
let members = match ea::get_members_list(&data.ea_key, &data.ea_url).await {
Ok(v) => v,
Err(e) => {
tracing::error!("{e}");
@ -135,9 +135,9 @@ pub(crate) async fn membership_3(
return Ok(());
};
let realname = format!("{} {}", member.first_name, member.surname);
if crate::db::insert_member(
if db::insert_member(
&data.db,
crate::Member {
Member {
discord_id: m.user.id.into(),
shortcode,
nickname: nickname.clone(),
@ -155,9 +155,9 @@ pub(crate) async fn membership_3(
if fresher { " (fresher)" } else { "" }
);
let mut mm = m.member.clone().unwrap();
crate::verify::apply_role(ctx, &mut mm, data.member).await?;
verify::apply_role(ctx, &mut mm, data.member).await?;
if fresher {
crate::verify::apply_role(ctx, &mut mm, data.fresher).await?;
verify::apply_role(ctx, &mut mm, data.fresher).await?;
}
m.create_response(
&ctx.http,
@ -191,10 +191,9 @@ pub(crate) async fn membership_3(
.await?;
let _ = mm.remove_role(&ctx.http, data.non_member).await;
if mm.roles.contains(&data.old_member) {
crate::verify::remove_role(ctx, &mut mm, data.old_member).await?;
verify::remove_role(ctx, &mut mm, data.old_member).await?;
} else {
crate::verify::welcome_user(&ctx.http, &data.gn_ch_id, &m.user, fresher)
.await?;
verify::welcome_user(&ctx.http, &data.gn_ch_id, &m.user, fresher).await?;
}
return Ok(());
}

View file

@ -1,4 +1,4 @@
use crate::{Data, Error};
use crate::{db, Data, Error};
use poise::serenity_prelude::{
self as serenity, CacheHttp, CreateActionRow, CreateButton, CreateInteractionResponse,
CreateInteractionResponseMessage, CreateMessage,
@ -73,7 +73,7 @@ pub(crate) async fn start(
init: bool,
) -> Result<(), Error> {
// Check if user is already verified
if let Some(member) = crate::db::get_member_by_id(&data.db, m.user.id.into()).await? {
if let Some(member) = db::get_member_by_id(&data.db, m.user.id.into()).await? {
let mut mm = m.member.clone().unwrap();
apply_role(ctx, &mut mm, data.member).await?;
if member.fresher {