Favorite/unfavorite sounds
This commit is contained in:
1 parent
92d8d077df
commit
e875038851
9 files changed
+238
-1
No files matched your search
@@ -47,12 +47,14 @@ pub async fn list_sounds(_ctx: Context<'_>) -> Result<(), Error> {
|
||||
enum ListContext {
|
||||
User = 0,
|
||||
Guild = 1,
|
||||
Favorite = 2,
|
||||
}
|
||||
|
||||
impl ListContext {
|
||||
pub fn title(&self) -> &'static str {
|
||||
match self {
|
||||
ListContext::User => "Your sounds",
|
||||
ListContext::Favorite => "Your favorite sounds",
|
||||
ListContext::Guild => "Server sounds",
|
||||
}
|
||||
}
|
||||
@@ -86,6 +88,20 @@ pub async fn list_user_sounds(ctx: Context<'_>) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Show all sounds you have uploaded
|
||||
#[poise::command(slash_command, rename = "user", guild_only = true)]
|
||||
pub async fn list_favorite_sounds(ctx: Context<'_>) -> Result<(), Error> {
|
||||
let pager = SoundPager {
|
||||
nonce: 0,
|
||||
page: 0,
|
||||
context: ListContext::Favorite,
|
||||
};
|
||||
|
||||
pager.reply(ctx).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct SoundPager {
|
||||
nonce: u64,
|
||||
@@ -102,6 +118,7 @@ impl SoundPager {
|
||||
) -> Result<Vec<Sound>, sqlx::Error> {
|
||||
match self.context {
|
||||
ListContext::User => data.user_sounds(user_id, Some(self.page)).await,
|
||||
ListContext::Favorite => data.favorite_sounds(user_id, Some(self.page)).await,
|
||||
ListContext::Guild => data.guild_sounds(guild_id, Some(self.page)).await,
|
||||
}
|
||||
}
|
||||
@@ -205,6 +222,7 @@ impl SoundPager {
|
||||
let sounds = pager.get_page(data, user_id, guild_id).await?;
|
||||
let count = match pager.context {
|
||||
ListContext::User => data.count_user_sounds(user_id).await?,
|
||||
ListContext::Favorite => data.count_favorite_sounds(user_id).await?,
|
||||
ListContext::Guild => data.count_guild_sounds(guild_id).await?,
|
||||
};
|
||||
|
||||
@@ -228,6 +246,7 @@ impl SoundPager {
|
||||
.await?;
|
||||
let count = match self.context {
|
||||
ListContext::User => ctx.data().count_user_sounds(ctx.author().id).await?,
|
||||
ListContext::Favorite => ctx.data().count_favorite_sounds(ctx.author().id).await?,
|
||||
ListContext::Guild => {
|
||||
ctx.data()
|
||||
.count_guild_sounds(ctx.guild_id().unwrap())
|
||||
|
||||
Reference in new issue
Block a user