Prefer selecting favorite sound over other sounds

This commit is contained in:
jude 2023-08-19 10:32:49 +01:00
parent e875038851
commit 6482af923b
2 changed files with 24 additions and 4 deletions

View File

@ -88,8 +88,8 @@ pub async fn list_user_sounds(ctx: Context<'_>) -> Result<(), Error> {
Ok(()) Ok(())
} }
/// Show all sounds you have uploaded /// Show sounds you have favorited
#[poise::command(slash_command, rename = "user", guild_only = true)] #[poise::command(slash_command, rename = "favorite", guild_only = true)]
pub async fn list_favorite_sounds(ctx: Context<'_>) -> Result<(), Error> { pub async fn list_favorite_sounds(ctx: Context<'_>) -> Result<(), Error> {
let pager = SoundPager { let pager = SoundPager {
nonce: 0, nonce: 0,

View File

@ -125,12 +125,22 @@ SELECT name, id, public, server_id, uploader_id
uploader_id = ? OR uploader_id = ? OR
server_id = ? server_id = ?
) )
ORDER BY uploader_id = ? DESC, server_id = ? DESC, public = 1 DESC, rand() ORDER BY
uploader_id = ? DESC,
EXISTS(
SELECT 1
FROM favorite_sounds
WHERE sound_id = id AND user_id = ?
),
server_id = ? DESC,
public = 1 DESC,
rand()
", ",
name, name,
user_id, user_id,
guild_id, guild_id,
user_id, user_id,
user_id,
guild_id guild_id
) )
.fetch_all(&db_pool) .fetch_all(&db_pool)
@ -146,12 +156,22 @@ SELECT name, id, public, server_id, uploader_id
uploader_id = ? OR uploader_id = ? OR
server_id = ? server_id = ?
) )
ORDER BY uploader_id = ? DESC, server_id = ? DESC, public = 1 DESC, rand() ORDER BY
uploader_id = ? DESC,
EXISTS(
SELECT 1
FROM favorite_sounds
WHERE sound_id = id AND user_id = ?
),
server_id = ? DESC,
public = 1 DESC,
rand()
", ",
name, name,
user_id, user_id,
guild_id, guild_id,
user_id, user_id,
user_id,
guild_id guild_id
) )
.fetch_all(&db_pool) .fetch_all(&db_pool)