generics for Database pool

This commit is contained in:
2022-01-30 15:55:53 +00:00
parent c364343fe9
commit eb5ea3167d
8 changed files with 49 additions and 69 deletions

View File

@ -29,11 +29,10 @@ pub async fn upload_new_sound(
if !name.is_empty() && name.len() <= 20 {
if !is_numeric(&name) {
let pool = ctx.data().database.clone();
// need to check the name is not currently in use by the user
let count_name =
Sound::count_named_user_sounds(ctx.author().id, &name, pool.clone()).await?;
Sound::count_named_user_sounds(ctx.author().id, &name, &ctx.data().database)
.await?;
if count_name > 0 {
ctx.say(
"You are already using that name. Please choose a unique name for your upload.",
@ -41,7 +40,7 @@ pub async fn upload_new_sound(
.await?;
} else {
// need to check how many sounds user currently has
let count = Sound::count_user_sounds(ctx.author().id, pool.clone()).await?;
let count = Sound::count_user_sounds(ctx.author().id, &ctx.data().database).await?;
let mut permit_upload = true;
// need to check if user is patreon or nah
@ -93,7 +92,7 @@ pub async fn upload_new_sound(
url.as_str(),
ctx.guild_id().unwrap(),
ctx.author().id,
pool,
&ctx.data().database,
)
.await
{
@ -160,7 +159,7 @@ pub async fn delete_sound(
};
if sound.uploader_id == Some(uid) || has_perms {
sound.delete(pool).await?;
sound.delete(&pool).await?;
ctx.say("Sound has been deleted").await?;
} else {
@ -209,7 +208,7 @@ pub async fn change_public(
ctx.say("Sound has been set to public 🔓").await?;
}
sound.commit(pool).await?
sound.commit(&pool).await?
}
}
@ -238,9 +237,7 @@ pub async fn download_file(
match sound.first() {
Some(sound) => {
let source = sound
.store_sound_source(ctx.data().database.clone())
.await?;
let source = sound.store_sound_source(&ctx.data().database).await?;
let file = File::open(&source).await?;
let name = format!("{}-{}.opus", sound.id, sound.name);

View File

@ -15,11 +15,7 @@ pub async fn change_volume(
if let Some(volume) = volume {
guild_data.write().await.volume = volume as u8;
guild_data
.read()
.await
.commit(ctx.data().database.clone())
.await?;
guild_data.read().await.commit(&ctx.data().database).await?;
ctx.say(format!("Volume changed to {}%", volume)).await?;
} else {
@ -91,11 +87,7 @@ pub async fn disable_greet_sound(ctx: Context<'_>) -> Result<(), Error> {
if let Ok(guild_data) = guild_data_opt {
guild_data.write().await.allow_greets = false;
guild_data
.read()
.await
.commit(ctx.data().database.clone())
.await?;
guild_data.read().await.commit(&ctx.data().database).await?;
}
ctx.say("Greet sounds have been disabled in this server")
@ -112,11 +104,7 @@ pub async fn enable_greet_sound(ctx: Context<'_>) -> Result<(), Error> {
if let Ok(guild_data) = guild_data_opt {
guild_data.write().await.allow_greets = true;
guild_data
.read()
.await
.commit(ctx.data().database.clone())
.await?;
guild_data.read().await.commit(&ctx.data().database).await?;
}
ctx.say("Greet sounds have been enable in this server")