mirror of
https://github.com/supleed2/nanobot.git
synced 2024-12-22 14:15:51 +00:00
Fix clippy::pedantic
lints
This commit is contained in:
parent
eb77798c35
commit
69e7a5a4f4
45
src/cmds.rs
45
src/cmds.rs
|
@ -18,7 +18,6 @@ pub(crate) async fn setup(
|
|||
#[channel_types("Text", "News")]
|
||||
channel: serenity::GuildChannel,
|
||||
) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) setup", ctx.author().name);
|
||||
#[derive(Modal)]
|
||||
struct Setup {
|
||||
#[name = "Contents of the verification intro message"]
|
||||
|
@ -36,6 +35,8 @@ pub(crate) async fn setup(
|
|||
text: Option<String>,
|
||||
}
|
||||
|
||||
println!("Cmd: ({}) setup", ctx.author().name);
|
||||
|
||||
if let Some(Setup {
|
||||
message,
|
||||
emoji,
|
||||
|
@ -89,22 +90,17 @@ pub(crate) async fn delete_member(
|
|||
remove_roles: Option<bool>,
|
||||
) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) delete_member {id}", ctx.author().name);
|
||||
match db::delete_member_by_id(&ctx.data().db, id.user.id.into()).await? {
|
||||
true => {
|
||||
if db::delete_member_by_id(&ctx.data().db, id.user.id.into()).await? {
|
||||
if remove_roles.unwrap_or(true) {
|
||||
let mut m = id.clone();
|
||||
crate::verify::remove_role(ctx.serenity_context(), &mut m, ctx.data().member)
|
||||
.await?;
|
||||
crate::verify::remove_role(ctx.serenity_context(), &mut m, ctx.data().fresher)
|
||||
.await?;
|
||||
crate::verify::remove_role(ctx.serenity_context(), &mut m, ctx.data().member).await?;
|
||||
crate::verify::remove_role(ctx.serenity_context(), &mut m, ctx.data().fresher).await?;
|
||||
}
|
||||
ctx.say(format!("Successfully deleted member info for {id}"))
|
||||
.await?
|
||||
}
|
||||
false => {
|
||||
} else {
|
||||
ctx.say(format!("Failed to delete member info for {id}"))
|
||||
.await?
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
@ -112,7 +108,6 @@ pub(crate) async fn delete_member(
|
|||
/// Print all members in members table
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn get_all_members(ctx: ACtx<'_>) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) get_all_members", ctx.author().name);
|
||||
#[derive(Modal)]
|
||||
struct Confirm {
|
||||
#[name = "This will output the members db as text"]
|
||||
|
@ -120,6 +115,8 @@ pub(crate) async fn get_all_members(ctx: ACtx<'_>) -> Result<(), Error> {
|
|||
confirm: String,
|
||||
}
|
||||
|
||||
println!("Cmd: ({}) get_all_members", ctx.author().name);
|
||||
|
||||
if let Some(Confirm { confirm }) = Confirm::execute(ctx).await? {
|
||||
if confirm.to_lowercase().contains("yes") {
|
||||
let members = db::get_all_members(&ctx.data().db).await?;
|
||||
|
@ -320,15 +317,12 @@ pub(crate) async fn count_pending(ctx: ACtx<'_>) -> Result<(), Error> {
|
|||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn delete_pending(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) delete_pending {id}", ctx.author().name);
|
||||
match db::delete_pending_by_id(&ctx.data().db, id.id.into()).await? {
|
||||
true => {
|
||||
if db::delete_pending_by_id(&ctx.data().db, id.id.into()).await? {
|
||||
ctx.say(format!("Successfully deleted pending member info for {id}"))
|
||||
.await?
|
||||
}
|
||||
false => {
|
||||
} else {
|
||||
ctx.say(format!("Failed to delete pending member info for {id}"))
|
||||
.await?
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
@ -336,7 +330,6 @@ pub(crate) async fn delete_pending(ctx: ACtx<'_>, id: serenity::User) -> Result<
|
|||
/// Print all pending members in pending table
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn get_all_pending(ctx: ACtx<'_>) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) get_all_pending", ctx.author().name);
|
||||
#[derive(Modal)]
|
||||
struct ConfirmPending {
|
||||
#[name = "This will output the pending db as text"]
|
||||
|
@ -344,6 +337,8 @@ pub(crate) async fn get_all_pending(ctx: ACtx<'_>) -> Result<(), Error> {
|
|||
confirm: String,
|
||||
}
|
||||
|
||||
println!("Cmd: ({}) get_all_pending", ctx.author().name);
|
||||
|
||||
if let Some(ConfirmPending { confirm }) = ConfirmPending::execute(ctx).await? {
|
||||
if confirm.to_lowercase().contains("yes") {
|
||||
let pending = db::get_all_pending(&ctx.data().db).await?;
|
||||
|
@ -402,7 +397,6 @@ pub(crate) async fn add_pending(
|
|||
/// Delete all pending members in pending table
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn delete_all_pending(ctx: ACtx<'_>) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) delete_all_pending", ctx.author().name);
|
||||
#[derive(Modal)]
|
||||
struct ConfirmPurgePending {
|
||||
#[name = "This will wipe the pending db"]
|
||||
|
@ -410,6 +404,8 @@ pub(crate) async fn delete_all_pending(ctx: ACtx<'_>) -> Result<(), Error> {
|
|||
confirm: String,
|
||||
}
|
||||
|
||||
println!("Cmd: ({}) delete_all_pending", ctx.author().name);
|
||||
|
||||
if let Some(ConfirmPurgePending { confirm }) = ConfirmPurgePending::execute(ctx).await? {
|
||||
if confirm.to_lowercase().contains("yes") {
|
||||
let deleted = db::delete_all_pending(&ctx.data().db).await?;
|
||||
|
@ -440,15 +436,12 @@ pub(crate) async fn count_manual(ctx: ACtx<'_>) -> Result<(), Error> {
|
|||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn delete_manual(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) delete_manual {id}", ctx.author().name);
|
||||
match db::delete_manual_by_id(&ctx.data().db, id.id.into()).await? {
|
||||
true => {
|
||||
if db::delete_manual_by_id(&ctx.data().db, id.id.into()).await? {
|
||||
ctx.say(format!("Successfully deleted manual member info for {id}"))
|
||||
.await?
|
||||
}
|
||||
false => {
|
||||
} else {
|
||||
ctx.say(format!("Failed to delete manual member info for {id}"))
|
||||
.await?
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
@ -456,7 +449,6 @@ pub(crate) async fn delete_manual(ctx: ACtx<'_>, id: serenity::User) -> Result<(
|
|||
/// Print all manual members in manual table
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn get_all_manual(ctx: ACtx<'_>) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) get_all_manual", ctx.author().name);
|
||||
#[derive(Modal)]
|
||||
struct ConfirmManual {
|
||||
#[name = "This will output the manual db as text"]
|
||||
|
@ -464,6 +456,8 @@ pub(crate) async fn get_all_manual(ctx: ACtx<'_>) -> Result<(), Error> {
|
|||
confirm: String,
|
||||
}
|
||||
|
||||
println!("Cmd: ({}) get_all_manual", ctx.author().name);
|
||||
|
||||
if let Some(ConfirmManual { confirm }) = ConfirmManual::execute(ctx).await? {
|
||||
if confirm.to_lowercase().contains("yes") {
|
||||
let manual = db::get_all_manual(&ctx.data().db).await?;
|
||||
|
@ -526,7 +520,6 @@ pub(crate) async fn add_manual(
|
|||
/// Delete all manual members in manual table
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn delete_all_manual(ctx: ACtx<'_>) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) delete_all_manual", ctx.author().name);
|
||||
#[derive(Modal)]
|
||||
struct ConfirmPurgeManual {
|
||||
#[name = "This will wipe the manual db"]
|
||||
|
@ -534,6 +527,8 @@ pub(crate) async fn delete_all_manual(ctx: ACtx<'_>) -> Result<(), Error> {
|
|||
confirm: String,
|
||||
}
|
||||
|
||||
println!("Cmd: ({}) delete_all_manual", ctx.author().name);
|
||||
|
||||
if let Some(ConfirmPurgeManual { confirm }) = ConfirmPurgeManual::execute(ctx).await? {
|
||||
if confirm.to_lowercase().contains("yes") {
|
||||
let deleted = db::delete_all_manual(&ctx.data().db).await?;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct EaMember {
|
||||
pub struct Member {
|
||||
pub first_name: String,
|
||||
pub surname: String,
|
||||
pub login: String,
|
||||
|
@ -10,13 +10,13 @@ pub struct EaMember {
|
|||
pub(crate) async fn get_members_list(
|
||||
api_key: &str,
|
||||
url: &str,
|
||||
) -> Result<Vec<EaMember>, reqwest::Error> {
|
||||
) -> Result<Vec<Member>, reqwest::Error> {
|
||||
let members = reqwest::Client::new()
|
||||
.get(url)
|
||||
.header("X-API-Key", api_key)
|
||||
.send()
|
||||
.await?
|
||||
.json::<Vec<EaMember>>()
|
||||
.json::<Vec<Member>>()
|
||||
.await?;
|
||||
Ok(members)
|
||||
}
|
||||
|
|
|
@ -97,12 +97,9 @@ async fn poise(
|
|||
.into();
|
||||
|
||||
// Build Axum Router
|
||||
use axum::routing::{get, post};
|
||||
let router = axum::Router::new()
|
||||
.route("/", get(routes::hello_world))
|
||||
.route(
|
||||
let router = axum::Router::new().route(
|
||||
"/verify",
|
||||
post({
|
||||
axum::routing::post({
|
||||
let pool = pool.clone();
|
||||
let key = secret_store
|
||||
.get("VERIFY_KEY")
|
||||
|
@ -172,7 +169,7 @@ async fn event_handler(
|
|||
) -> Result<(), Error> {
|
||||
match event {
|
||||
poise::Event::GuildMemberAddition { new_member } => {
|
||||
println!("Member joined:\n{:#?}", new_member)
|
||||
println!("Member joined:\n{new_member:#?}");
|
||||
}
|
||||
poise::Event::InteractionCreate {
|
||||
interaction: serenity::Interaction::MessageComponent(m),
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
use crate::PendingMember;
|
||||
use axum::{http::StatusCode, response::IntoResponse, Json};
|
||||
|
||||
pub(crate) async fn hello_world() -> impl IntoResponse {
|
||||
(StatusCode::OK, "Hello world!")
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, serde::Serialize)]
|
||||
pub(crate) struct Verify {
|
||||
id: String,
|
||||
|
@ -22,12 +18,10 @@ pub(crate) async fn verify(
|
|||
None => (StatusCode::BAD_REQUEST, "Invalid request body").into_response(),
|
||||
Some(Json(verify)) => {
|
||||
if verify.key == key {
|
||||
let id = match verify.id.parse::<i64>() {
|
||||
Ok(i) => i,
|
||||
Err(_) => {
|
||||
let Ok(id) = verify.id.parse::<i64>() else {
|
||||
return (StatusCode::BAD_REQUEST, "Invalid request body").into_response();
|
||||
}
|
||||
};
|
||||
|
||||
// Delete from pending if exists
|
||||
let _ = crate::db::delete_pending_by_id(&pool, id).await;
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ pub(crate) async fn login_2(
|
|||
.ephemeral(true)
|
||||
})
|
||||
})
|
||||
.await?
|
||||
.await?;
|
||||
}
|
||||
Ok(None) => {
|
||||
m.create_interaction_response(&ctx.http, |i| {
|
||||
|
@ -76,7 +76,7 @@ pub(crate) async fn login_2(
|
|||
.ephemeral(true)
|
||||
})
|
||||
})
|
||||
.await?
|
||||
.await?;
|
||||
}
|
||||
Ok(Some(_)) => {
|
||||
m.create_interaction_response(&ctx.http, |i| {
|
||||
|
@ -99,7 +99,7 @@ pub(crate) async fn login_2(
|
|||
})
|
||||
})
|
||||
})
|
||||
.await?
|
||||
.await?;
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
|
@ -245,9 +245,9 @@ pub(crate) async fn login_6(
|
|||
data.au_ch_id
|
||||
.send_message(&ctx.http, |cm| {
|
||||
cm.add_embed(|e| {
|
||||
e.thumbnail(m.user.avatar_url().unwrap_or(
|
||||
"https://cdn.discordapp.com/embed/avatars/0.png".to_string(),
|
||||
))
|
||||
e.thumbnail(
|
||||
m.user.avatar_url().unwrap_or(super::AVATAR.to_string()),
|
||||
)
|
||||
.title("Member verified via login")
|
||||
.description(&m.user)
|
||||
.field("Fresher", fresher, true)
|
||||
|
@ -279,12 +279,12 @@ pub(crate) async fn login_6(
|
|||
.ephemeral(true)
|
||||
})
|
||||
})
|
||||
.await?
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error: {e}")
|
||||
eprintln!("Error: {e}");
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
|
|
|
@ -125,9 +125,7 @@ pub(crate) async fn manual_3(
|
|||
.send_message(&ctx.http, |cm| {
|
||||
cm.add_embed(|e| {
|
||||
e.title("New verification request from")
|
||||
.thumbnail(m.user.avatar_url().unwrap_or(
|
||||
"https://cdn.discordapp.com/embed/avatars/0.png".to_string(),
|
||||
))
|
||||
.thumbnail(m.user.avatar_url().unwrap_or(super::AVATAR.to_string()))
|
||||
.description(&m.user)
|
||||
.field("Real Name (To be checked)", &realname, true)
|
||||
.field("Imperial Shortcode (To be checked", &shortcode, true)
|
||||
|
@ -206,12 +204,7 @@ pub(crate) async fn manual_4(
|
|||
data: &Data,
|
||||
id: &str,
|
||||
) -> Result<(), Error> {
|
||||
let verify = match id.chars().nth(7) {
|
||||
Some('y') => true,
|
||||
Some('n') => false,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
let verify = matches!(id.chars().nth(7), Some('y'));
|
||||
let user = id
|
||||
.chars()
|
||||
.skip(9)
|
||||
|
@ -246,9 +239,7 @@ pub(crate) async fn manual_4(
|
|||
i.kind(serenity::InteractionResponseType::UpdateMessage)
|
||||
.interaction_response_data(|d| {
|
||||
d.components(|c| c).embed(|e| {
|
||||
e.thumbnail(user.avatar_url().unwrap_or(
|
||||
"https://cdn.discordapp.com/embed/avatars/0.png".to_string(),
|
||||
))
|
||||
e.thumbnail(user.avatar_url().unwrap_or(super::AVATAR.to_string()))
|
||||
.title("Member verified via manual")
|
||||
.description(&user)
|
||||
.field("Fresher", fresher, true)
|
||||
|
@ -280,7 +271,7 @@ pub(crate) async fn manual_4(
|
|||
d.content(format!("Failed to add user {user} to member database"))
|
||||
})
|
||||
})
|
||||
.await?
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -292,14 +283,12 @@ pub(crate) async fn manual_4(
|
|||
d.components(|c| c).embed(|e| {
|
||||
e.title("Member denied via manual")
|
||||
.description(&user)
|
||||
.thumbnail(user.avatar_url().unwrap_or(
|
||||
"https://cdn.discordapp.com/embed/avatars/0.png".to_string(),
|
||||
))
|
||||
.thumbnail(user.avatar_url().unwrap_or(super::AVATAR.to_string()))
|
||||
.timestamp(serenity::Timestamp::now())
|
||||
})
|
||||
})
|
||||
})
|
||||
.await?
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -114,12 +114,10 @@ pub(crate) async fn membership_3(
|
|||
return Ok(());
|
||||
}
|
||||
};
|
||||
let member = match members
|
||||
let Some(member) = members
|
||||
.iter()
|
||||
.find(|&member| member.order_no.to_string() == order && member.login == shortcode)
|
||||
{
|
||||
Some(m) => m,
|
||||
None => {
|
||||
else {
|
||||
m.create_interaction_response(&ctx.http, |i| {
|
||||
let msg = "Sorry, your order was not found, please check the \
|
||||
order number and that it is for your current year's membership";
|
||||
|
@ -128,7 +126,6 @@ pub(crate) async fn membership_3(
|
|||
})
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
if crate::db::insert_member(
|
||||
&data.db,
|
||||
|
@ -171,9 +168,7 @@ pub(crate) async fn membership_3(
|
|||
data.au_ch_id
|
||||
.send_message(&ctx.http, |cm| {
|
||||
cm.add_embed(|e| {
|
||||
e.thumbnail(m.user.avatar_url().unwrap_or(
|
||||
"https://cdn.discordapp.com/embed/avatars/0.png".to_string(),
|
||||
))
|
||||
e.thumbnail(m.user.avatar_url().unwrap_or(super::AVATAR.to_string()))
|
||||
.title("Member verified via membership")
|
||||
.description(&m.user)
|
||||
.field("Fresher", fresher, true)
|
||||
|
|
|
@ -10,6 +10,8 @@ pub(crate) use membership::*;
|
|||
pub(crate) mod manual;
|
||||
pub(crate) use manual::*;
|
||||
|
||||
const AVATAR: &str = "https://cdn.discordapp.com/embed/avatars/0.png";
|
||||
|
||||
const INFO_MSG: &str = indoc::indoc! {"
|
||||
Nano is a Discord bot written with serenity-rs/poise and tokio-rs/axum.
|
||||
|
||||
|
@ -72,7 +74,7 @@ pub(crate) async fn start(
|
|||
.ephemeral(true)
|
||||
})
|
||||
})
|
||||
.await?
|
||||
.await?;
|
||||
} else {
|
||||
m.create_interaction_response(&ctx.http, |i| {
|
||||
i.kind(if init {
|
||||
|
@ -105,7 +107,7 @@ pub(crate) async fn start(
|
|||
})
|
||||
})
|
||||
})
|
||||
.await?
|
||||
.await?;
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue