forked from Skynet/discord-bot
fix: slight improvement for g_id
This commit is contained in:
parent
c2a6407ef0
commit
33cebe7782
1 changed files with 5 additions and 13 deletions
|
@ -118,6 +118,7 @@ pub(crate) mod server {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub(crate) mod add {
|
pub(crate) mod add {
|
||||||
|
use serenity::model::id::GuildId;
|
||||||
use sqlx::Error;
|
use sqlx::Error;
|
||||||
// this is to managfe the server side of commands related to minecraft
|
// this is to managfe the server side of commands related to minecraft
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -166,20 +167,11 @@ pub(crate) mod server {
|
||||||
};
|
};
|
||||||
let db = db_lock.read().await;
|
let db = db_lock.read().await;
|
||||||
|
|
||||||
let server_data = match get_server_config(&db, &g_id).await {
|
match add_server(&db, &g_id, &server_minecraft).await {
|
||||||
None => {
|
|
||||||
return "No existing server config, have you used ``/add``?".to_string();
|
|
||||||
}
|
|
||||||
Some(x) => {
|
|
||||||
x
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
match add_server(&db, *server_data.server.as_u64() as i64, &server_minecraft).await {
|
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("{:?}", e);
|
println!("{:?}", e);
|
||||||
return format!("Failure to insert into Minecraft {} {}", *server_data.server.as_u64(), &server_minecraft);
|
return format!("Failure to insert into Minecraft {} {}", &g_id, &server_minecraft);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,14 +186,14 @@ pub(crate) mod server {
|
||||||
"Added/Updated minecraft_server info".to_string()
|
"Added/Updated minecraft_server info".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn add_server(db: &Pool<Sqlite>, discord: i64, minecraft: &str) -> Result<Option<Servers>, Error> {
|
async fn add_server(db: &Pool<Sqlite>, discord: &GuildId, minecraft: &str) -> Result<Option<Servers>, Error> {
|
||||||
sqlx::query_as::<_, Servers>(
|
sqlx::query_as::<_, Servers>(
|
||||||
"
|
"
|
||||||
INSERT OR REPLACE INTO minecraft (server_discord, server_minecraft)
|
INSERT OR REPLACE INTO minecraft (server_discord, server_minecraft)
|
||||||
VALUES (?1, ?2)
|
VALUES (?1, ?2)
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
.bind(discord)
|
.bind(*discord.as_u64() as i64)
|
||||||
.bind(minecraft)
|
.bind(minecraft)
|
||||||
.fetch_optional(db)
|
.fetch_optional(db)
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Reference in a new issue