Split greet sound enabling
This commit is contained in:
@@ -1,17 +1,25 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use poise::serenity_prelude::{async_trait, model::id::GuildId};
|
||||
use sqlx::Executor;
|
||||
use sqlx::{Executor, Type};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use crate::{Context, Data, Database};
|
||||
|
||||
#[derive(Copy, Clone, Type, PartialEq)]
|
||||
#[repr(i32)]
|
||||
pub enum AllowGreet {
|
||||
Enabled = 1,
|
||||
GuildOnly = 0,
|
||||
Disabled = -1,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct GuildData {
|
||||
pub id: u64,
|
||||
pub prefix: String,
|
||||
pub volume: u8,
|
||||
pub allow_greets: bool,
|
||||
pub allow_greets: AllowGreet,
|
||||
pub allowed_role: Option<u64>,
|
||||
}
|
||||
|
||||
@@ -109,7 +117,7 @@ INSERT INTO servers (id)
|
||||
id: guild_id.as_u64().to_owned(),
|
||||
prefix: String::from("?"),
|
||||
volume: 100,
|
||||
allow_greets: true,
|
||||
allow_greets: AllowGreet::Enabled,
|
||||
allowed_role: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ pub trait JoinSoundCtx {
|
||||
&self,
|
||||
user_id: U,
|
||||
guild_id: Option<G>,
|
||||
guild_only: bool,
|
||||
) -> Option<u32>;
|
||||
async fn update_join_sound<U: Into<UserId> + Send + Sync, G: Into<GuildId> + Send + Sync>(
|
||||
&self,
|
||||
@@ -17,12 +18,17 @@ pub trait JoinSoundCtx {
|
||||
) -> Result<(), sqlx::Error>;
|
||||
}
|
||||
|
||||
struct JoinSound {
|
||||
join_sound_id: u32,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl JoinSoundCtx for Data {
|
||||
async fn join_sound<U: Into<UserId> + Send + Sync, G: Into<GuildId> + Send + Sync>(
|
||||
&self,
|
||||
user_id: U,
|
||||
guild_id: Option<G>,
|
||||
guild_only: bool,
|
||||
) -> Option<u32> {
|
||||
let user_id = user_id.into();
|
||||
let guild_id = guild_id.map(|g| g.into());
|
||||
@@ -37,19 +43,37 @@ impl JoinSoundCtx for Data {
|
||||
join_sound_id
|
||||
} else {
|
||||
let join_sound_id = {
|
||||
let join_id_res = sqlx::query!(
|
||||
"
|
||||
let join_id_res = if guild_only {
|
||||
sqlx::query_as!(
|
||||
JoinSound,
|
||||
"
|
||||
SELECT join_sound_id
|
||||
FROM join_sounds
|
||||
WHERE user = ?
|
||||
AND guild = ?
|
||||
ORDER BY guild IS NULL
|
||||
",
|
||||
user_id.as_u64(),
|
||||
guild_id.map(|g| g.0)
|
||||
)
|
||||
.fetch_one(&self.database)
|
||||
.await
|
||||
} else {
|
||||
sqlx::query_as!(
|
||||
JoinSound,
|
||||
"
|
||||
SELECT join_sound_id
|
||||
FROM join_sounds
|
||||
WHERE user = ?
|
||||
AND (guild IS NULL OR guild = ?)
|
||||
ORDER BY guild IS NULL
|
||||
",
|
||||
user_id.as_u64(),
|
||||
guild_id.map(|g| g.0)
|
||||
)
|
||||
.fetch_one(&self.database)
|
||||
.await;
|
||||
user_id.as_u64(),
|
||||
guild_id.map(|g| g.0)
|
||||
)
|
||||
.fetch_one(&self.database)
|
||||
.await
|
||||
};
|
||||
|
||||
if let Ok(row) = join_id_res {
|
||||
Some(row.join_sound_id)
|
||||
|
||||
Reference in New Issue
Block a user