Replace conversions with type-safe .into() calls

This commit is contained in:
Aadi Desai 2023-09-25 12:36:01 +01:00
parent b83f28a01c
commit 82e3eb76c1
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
5 changed files with 25 additions and 25 deletions

View file

@ -89,7 +89,7 @@ pub(crate) async fn delete_member(
remove_roles: Option<bool>, remove_roles: Option<bool>,
) -> Result<(), Error> { ) -> Result<(), Error> {
println!("Cmd: ({}) delete_member {id}", ctx.author().name); println!("Cmd: ({}) delete_member {id}", ctx.author().name);
match db::delete_member_by_id(&ctx.data().db, id.user.id.0 as i64).await? { match db::delete_member_by_id(&ctx.data().db, id.user.id.into()).await? {
true => { true => {
if remove_roles.unwrap_or(true) { if remove_roles.unwrap_or(true) {
let mut m = id.clone(); let mut m = id.clone();
@ -136,7 +136,7 @@ pub(crate) async fn get_all_members(ctx: ACtx<'_>) -> Result<(), Error> {
} }
} }
/// Unreachable, used to create command folder /// Unreachable, used to create get_member command folder
#[poise::command( #[poise::command(
slash_command, slash_command,
subcommands( subcommands(
@ -154,7 +154,7 @@ pub(crate) async fn get_member(_ctx: ACtx<'_>) -> Result<(), Error> {
#[poise::command(slash_command, rename = "id")] #[poise::command(slash_command, rename = "id")]
pub(crate) async fn get_member_by_id(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> { pub(crate) async fn get_member_by_id(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> {
println!("Cmd: ({}) get_member_by_id {id}", ctx.author().name); println!("Cmd: ({}) get_member_by_id {id}", ctx.author().name);
match db::get_member_by_id(&ctx.data().db, id.id.0 as i64).await? { match db::get_member_by_id(&ctx.data().db, id.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```"))
.await? .await?
@ -247,7 +247,7 @@ pub(crate) async fn add_member(
db::insert_member( db::insert_member(
&ctx.data().db, &ctx.data().db,
Member { Member {
discord_id: id.user.id.0 as i64, discord_id: id.user.id.into(),
shortcode, shortcode,
nickname, nickname,
realname, realname,
@ -276,7 +276,7 @@ pub(crate) async fn insert_member_from_pending(
"Cmd: ({}) insert_member_from_pending {id}", "Cmd: ({}) insert_member_from_pending {id}",
ctx.author().name ctx.author().name
); );
match db::insert_member_from_pending(&ctx.data().db, id.id.0 as i64, &nickname, fresher).await { match db::insert_member_from_pending(&ctx.data().db, id.id.into(), &nickname, fresher).await {
Ok(()) => { Ok(()) => {
ctx.say(format!("Member moved from pending to members table: {id}")) ctx.say(format!("Member moved from pending to members table: {id}"))
.await? .await?
@ -296,7 +296,7 @@ pub(crate) async fn insert_member_from_manual(
"Cmd: ({}) insert_member_from_manual {id}", "Cmd: ({}) insert_member_from_manual {id}",
ctx.author().name ctx.author().name
); );
match db::insert_member_from_manual(&ctx.data().db, id.id.0 as i64).await { match db::insert_member_from_manual(&ctx.data().db, id.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}"))
.await? .await?
@ -320,7 +320,7 @@ pub(crate) async fn count_pending(ctx: ACtx<'_>) -> Result<(), Error> {
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn delete_pending(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> { pub(crate) async fn delete_pending(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> {
println!("Cmd: ({}) delete_pending {id}", ctx.author().name); println!("Cmd: ({}) delete_pending {id}", ctx.author().name);
match db::delete_pending_by_id(&ctx.data().db, id.id.0 as i64).await? { match db::delete_pending_by_id(&ctx.data().db, id.id.into()).await? {
true => { true => {
ctx.say(format!("Successfully deleted pending member info for {id}")) ctx.say(format!("Successfully deleted pending member info for {id}"))
.await? .await?
@ -364,7 +364,7 @@ pub(crate) async fn get_all_pending(ctx: ACtx<'_>) -> Result<(), Error> {
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn get_pending(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> { pub(crate) async fn get_pending(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> {
println!("Cmd: ({}) get_pending {id}", ctx.author().name); println!("Cmd: ({}) get_pending {id}", ctx.author().name);
match db::get_pending_by_id(&ctx.data().db, id.id.0 as i64).await? { match db::get_pending_by_id(&ctx.data().db, id.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```"))
.await? .await?
@ -389,7 +389,7 @@ pub(crate) async fn add_pending(
db::insert_pending( db::insert_pending(
&ctx.data().db, &ctx.data().db,
PendingMember { PendingMember {
discord_id: id.id.0 as i64, discord_id: id.id.into(),
shortcode, shortcode,
realname, realname,
}, },
@ -440,7 +440,7 @@ pub(crate) async fn count_manual(ctx: ACtx<'_>) -> Result<(), Error> {
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn delete_manual(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> { pub(crate) async fn delete_manual(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> {
println!("Cmd: ({}) delete_manual {id}", ctx.author().name); println!("Cmd: ({}) delete_manual {id}", ctx.author().name);
match db::delete_manual_by_id(&ctx.data().db, id.id.0 as i64).await? { match db::delete_manual_by_id(&ctx.data().db, id.id.into()).await? {
true => { true => {
ctx.say(format!("Successfully deleted manual member info for {id}")) ctx.say(format!("Successfully deleted manual member info for {id}"))
.await? .await?
@ -484,7 +484,7 @@ pub(crate) async fn get_all_manual(ctx: ACtx<'_>) -> Result<(), Error> {
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn get_manual(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> { pub(crate) async fn get_manual(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> {
println!("Cmd: ({}) get_manual {id}", ctx.author().name); println!("Cmd: ({}) get_manual {id}", ctx.author().name);
match db::get_manual_by_id(&ctx.data().db, id.id.0 as i64).await? { match db::get_manual_by_id(&ctx.data().db, id.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```"))
.await? .await?
@ -511,7 +511,7 @@ pub(crate) async fn add_manual(
db::insert_manual( db::insert_manual(
&ctx.data().db, &ctx.data().db,
ManualMember { ManualMember {
discord_id: id.id.0 as i64, discord_id: id.id.into(),
shortcode, shortcode,
nickname, nickname,
realname, realname,

View file

@ -56,7 +56,7 @@ pub(crate) async fn login_2(
m: &serenity::MessageComponentInteraction, m: &serenity::MessageComponentInteraction,
data: &Data, data: &Data,
) -> Result<(), Error> { ) -> Result<(), Error> {
match crate::db::get_pending_by_id(&data.db, m.user.id.0 as i64).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}"); eprintln!("Error in login_2: {e}");
m.create_interaction_response(&ctx.http, |i| { m.create_interaction_response(&ctx.http, |i| {
@ -206,11 +206,11 @@ 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.0 as i64).await; let _ = crate::db::delete_manual_by_id(&data.db, m.user.id.into()).await;
match crate::db::insert_member_from_pending( match crate::db::insert_member_from_pending(
&data.db, &data.db,
m.user.id.0 as i64, m.user.id.into(),
&nickname, &nickname,
fresher, fresher,
) )

View file

@ -75,7 +75,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.0 as i64).await; let _ = crate::db::delete_manual_by_id(&data.db, m.user.id.into()).await;
m.create_interaction_response(&ctx.http, |i| { m.create_interaction_response(&ctx.http, |i| {
*i = Manual::create( *i = Manual::create(
@ -118,7 +118,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.0 as i64).await?; let _ = crate::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
@ -160,7 +160,7 @@ pub(crate) async fn manual_3(
let inserted = crate::db::insert_manual( let inserted = crate::db::insert_manual(
&data.db, &data.db,
crate::ManualMember { crate::ManualMember {
discord_id: m.user.id.0 as i64, discord_id: m.user.id.into(),
shortcode, shortcode,
nickname, nickname,
realname, realname,
@ -226,9 +226,9 @@ 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.0 as i64).await { match crate::db::insert_member_from_manual(&data.db, user.id.into()).await {
Ok(()) => { Ok(()) => {
let fresher = crate::db::get_member_by_id(&data.db, user.id.0 as i64) let fresher = crate::db::get_member_by_id(&data.db, user.id.into())
.await? .await?
.unwrap() .unwrap()
.fresher; .fresher;
@ -284,7 +284,7 @@ pub(crate) async fn manual_4(
} }
} }
} else { } else {
crate::db::delete_manual_by_id(&data.db, user.id.0 as i64).await?; crate::db::delete_manual_by_id(&data.db, user.id.into()).await?;
println!("{} ({}) denied via manual", user.name, user.id); println!("{} ({}) 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)

View file

@ -67,10 +67,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.0 as i64).await; let _ = crate::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.0 as i64).await; let _ = crate::db::delete_manual_by_id(&data.db, m.user.id.into()).await;
m.create_interaction_response(&ctx.http, |i| { m.create_interaction_response(&ctx.http, |i| {
*i = Membership::create( *i = Membership::create(
@ -133,7 +133,7 @@ pub(crate) async fn membership_3(
if crate::db::insert_member( if crate::db::insert_member(
&data.db, &data.db,
crate::Member { crate::Member {
discord_id: m.user.id.0 as i64, discord_id: m.user.id.into(),
shortcode, shortcode,
nickname, nickname,
realname: format!("{} {}", member.first_name, member.surname), realname: format!("{} {}", member.first_name, member.surname),

View file

@ -59,7 +59,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.0 as i64).await? { if let Some(member) = crate::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 {