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::{ use poise::{
serenity_prelude::{self as serenity, CreateAttachment, CreateMessage}, serenity_prelude::{self as serenity, CreateAttachment, CreateMessage},
Modal, Modal,
@ -27,7 +27,7 @@ pub(crate) async fn delete_gaijin(
tracing::info!("{} {}", ctx.author().name, id.user.name); tracing::info!("{} {}", ctx.author().name, id.user.name);
if db::delete_gaijin_by_id(&ctx.data().db, id.user.id.into()).await? { if db::delete_gaijin_by_id(&ctx.data().db, id.user.id.into()).await? {
if remove_roles.unwrap_or(true) { 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}")) ctx.say(format!("Successfully deleted gaijin info for {id}"))
.await? .await?
@ -156,7 +156,7 @@ pub(crate) async fn add_gaijin(
}, },
) )
.await?; .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?; ctx.say(format!("Gaijin added: {id}")).await?;
Ok(()) 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::serenity_prelude::{self as serenity, CreateAttachment, CreateMessage};
use poise::Modal; use poise::Modal;
@ -24,8 +24,8 @@ pub(crate) async fn delete_member(
tracing::info!("{} {}", ctx.author().name, id.user.name); tracing::info!("{} {}", 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) {
crate::verify::remove_role(ctx.serenity_context(), &mut id, ctx.data().member).await?; 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().fresher).await?;
} }
ctx.say(format!("Successfully deleted member info for {id}")) ctx.say(format!("Successfully deleted member info for {id}"))
.await? .await?
@ -198,9 +198,9 @@ pub(crate) async fn add_member(
}, },
) )
.await?; .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 { 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?; ctx.say(format!("Member added: {id}")).await?;
Ok(()) Ok(())

View file

@ -1,4 +1,4 @@
use crate::PendingMember; use crate::{db, PendingMember};
use axum::{http::StatusCode, response::IntoResponse, Json}; use axum::{http::StatusCode, response::IntoResponse, Json};
#[tracing::instrument] #[tracing::instrument]
@ -29,9 +29,9 @@ pub(crate) async fn verify(
}; };
// Delete from pending if exists // 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, &pool,
PendingMember { PendingMember {
discord_id: id, discord_id: id,

View file

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

View file

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

View file

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

View file

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