changed to how the guild query works so that errors are more useful and it doesnt do dumb shit
This commit is contained in:
parent
75653a3e88
commit
db56118bfb
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1175,7 +1175,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "reminder_rs"
|
||||
version = "1.1.4"
|
||||
version = "1.1.5"
|
||||
dependencies = [
|
||||
"Inflector",
|
||||
"async-trait",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "reminder_rs"
|
||||
version = "1.1.4"
|
||||
version = "1.1.5"
|
||||
authors = ["jellywx <judesouthworth@pm.me>"]
|
||||
edition = "2018"
|
||||
|
||||
|
@ -41,13 +41,10 @@ SELECT prefix FROM guilds WHERE guild = ?
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn from_guild(
|
||||
guild: Guild,
|
||||
pool: &MySqlPool,
|
||||
) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> {
|
||||
pub async fn from_guild(guild: Guild, pool: &MySqlPool) -> Result<Self, sqlx::Error> {
|
||||
let guild_id = guild.id.as_u64().to_owned();
|
||||
|
||||
if let Ok(g) = sqlx::query_as!(
|
||||
match sqlx::query_as!(
|
||||
Self,
|
||||
"
|
||||
SELECT id, name, prefix FROM guilds WHERE guild = ?
|
||||
@ -57,30 +54,40 @@ SELECT id, name, prefix FROM guilds WHERE guild = ?
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
{
|
||||
g.name = guild.name;
|
||||
Ok(mut g) => {
|
||||
g.name = Some(guild.name);
|
||||
|
||||
Ok(g)
|
||||
} else {
|
||||
sqlx::query!(
|
||||
"
|
||||
Ok(g)
|
||||
}
|
||||
|
||||
Err(sqlx::Error::RowNotFound) => {
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO guilds (guild, name, prefix) VALUES (?, ?, ?)
|
||||
",
|
||||
guild_id,
|
||||
guild.name,
|
||||
*DEFAULT_PREFIX
|
||||
)
|
||||
.execute(&pool.clone())
|
||||
.await?;
|
||||
",
|
||||
guild_id,
|
||||
guild.name,
|
||||
*DEFAULT_PREFIX
|
||||
)
|
||||
.execute(&pool.clone())
|
||||
.await?;
|
||||
|
||||
Ok(sqlx::query_as!(
|
||||
Self,
|
||||
"
|
||||
Ok(sqlx::query_as!(
|
||||
Self,
|
||||
"
|
||||
SELECT id, name, prefix FROM guilds WHERE guild = ?
|
||||
",
|
||||
guild_id
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.await?)
|
||||
",
|
||||
guild_id
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.await?)
|
||||
}
|
||||
|
||||
Err(e) => {
|
||||
error!("Unexpected error in guild query: {:?}", e);
|
||||
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user