Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 205 additions & 2 deletions twilight-http/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ use crate::request::{
GetEntitlements, GetSKUs,
},
},
guild::user::{GetCurrentUserVoiceState, GetUserVoiceState},
guild::{
soundboard::{
CreateGuildSoundboardSound, DeleteGuildSoundboardSound, GetGuildSoundboardSound,
ListDefaultSoundboardSounds, ListGuildSoundboardSounds, SendSoundboardSound,
UpdateGuildSoundboardSound,
},
user::{GetCurrentUserVoiceState, GetUserVoiceState},
},
};
#[allow(deprecated)]
use crate::{
Expand Down Expand Up @@ -127,7 +134,8 @@ use twilight_model::{
marker::{
ApplicationMarker, AutoModerationRuleMarker, ChannelMarker, EmojiMarker,
EntitlementMarker, GuildMarker, IntegrationMarker, MessageMarker, RoleMarker,
ScheduledEventMarker, SkuMarker, StickerMarker, UserMarker, WebhookMarker,
ScheduledEventMarker, SkuMarker, SoundboardMarker, StickerMarker, UserMarker,
WebhookMarker,
},
},
};
Expand Down Expand Up @@ -2878,6 +2886,201 @@ impl Client {
DeleteApplicationEmoji::new(self, application_id, emoji_id)
}

/// Send a soundboard sound.
///
/// The bot needs to have joined the specified voice channel before it can
/// play soundboard sounds.
///
/// You need to set the `source_guild_id` if the sound does not originate in
/// the default sounds or the guild you are playing the sound in.
///
/// # Example
/// ```no_run
/// use twilight_http::Client;
/// use twilight_model::id::Id;
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let client = Client::new("my token".to_owned());
///
/// // Plays a quack 🦆
/// client
/// .send_soundboard_sound(Id::new(12345), Id::new(1))
/// .await?;
/// # Ok(()) }
/// ```
pub const fn send_soundboard_sound(
&self,
channel_id: Id<ChannelMarker>,
sound_id: Id<SoundboardMarker>,
) -> SendSoundboardSound<'_> {
SendSoundboardSound::new(self, channel_id, sound_id)
}

/// List the default soundboard sounds.
///
/// # Example
/// ```no_run
/// use twilight_http::Client;
/// use twilight_model::id::Id;
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let client = Client::new("my token".to_owned());
///
/// let list = client
/// .list_default_soundboard_sounds()
/// .await?
/// .model()
/// .await?;
///
/// for sound in list {
/// println!("{:?}", sound);
/// }
/// # Ok(()) }
/// ```
pub const fn list_default_soundboard_sounds(&self) -> ListDefaultSoundboardSounds<'_> {
ListDefaultSoundboardSounds::new(self)
}

/// List the soundboard sounds available in a guild.
///
/// # Example
/// ```no_run
/// use twilight_http::Client;
/// use twilight_model::id::Id;
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let client = Client::new("my token".to_owned());
///
/// let list = client
/// .list_guild_soundboard_sounds(Id::new(123456))
/// .await?
/// .model()
/// .await?;
///
/// for sound in list.items {
/// println!("{:?}", sound);
/// }
/// # Ok(()) }
/// ```
pub const fn list_guild_soundboard_sounds(
&self,
guild_id: Id<GuildMarker>,
) -> ListGuildSoundboardSounds<'_> {
ListGuildSoundboardSounds::new(self, guild_id)
}

/// Get a specific soundboard sound.
///
/// # Example
/// ```no_run
/// use twilight_http::Client;
/// use twilight_model::id::Id;
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let client = Client::new("my token".to_owned());
///
/// let sound = client
/// .get_guild_soundboard_sound(Id::new(123456), Id::new(78910))
/// .await?
/// .model()
/// .await?;
///
/// println!("{:?}", sound);
/// # Ok(()) }
/// ```
pub const fn get_guild_soundboard_sound(
&self,
guild_id: Id<GuildMarker>,
sound_id: Id<SoundboardMarker>,
) -> GetGuildSoundboardSound<'_> {
GetGuildSoundboardSound::new(self, guild_id, sound_id)
}

/// Create a guild soundboard sound.
///
/// # Notes:
/// - `name` field must be between 2 and 32 characters.
/// - `sound` field must be a data URI of the mp3 or ogg sound data,
/// base64 encoded, similar to image data
///
/// # Example:
/// ```no_run
/// use twilight_http::Client;
/// use twilight_model::id::Id;
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let client = Client::new("my token".to_owned());
///
/// const LOW_RESOLUTION_IRON_PIPE: &str = "data:audio/mp3;base64,SUQzBAAAAAAAI1RTU...";
///
/// client
/// .create_guild_soundboard_sound(Id::new(12345), "IRON_PIPE", LOW_RESOLUTION_IRON_PIPE)
/// .await?;
/// # Ok(()) }
/// ```
pub fn create_guild_soundboard_sound<'a>(
&'a self,
guild_id: Id<GuildMarker>,
name: &'a str,
sound: &'a str,
) -> CreateGuildSoundboardSound<'a> {
CreateGuildSoundboardSound::new(self, guild_id, name, sound)
}

/// Update a guild soundboard sound.
///
/// # Example:
/// ```no_run
/// use twilight_http::Client;
/// use twilight_model::id::Id;
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let client = Client::new("my token".to_owned());
///
/// client
/// .update_guild_soundboard_sound(Id::new(12345), Id::new(67890))
/// .name("LOUD iron pipe")
/// .await?;
/// # Ok(()) }
/// ```
pub const fn update_guild_soundboard_sound(
&self,
guild_id: Id<GuildMarker>,
sound_id: Id<SoundboardMarker>,
) -> UpdateGuildSoundboardSound<'_> {
UpdateGuildSoundboardSound::new(self, guild_id, sound_id)
}

/// Delete a guild soundboard sound.
///
/// # Example:
/// ```no_run
/// use twilight_http::Client;
/// use twilight_model::id::Id;
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let client = Client::new("my token".to_owned());
///
/// client
/// .delete_guild_soundboard_sound(Id::new(12345), Id::new(67890))
/// .await?;
/// # Ok(()) }
/// ```
pub const fn delete_guild_soundboard_sound(
&self,
guild_id: Id<GuildMarker>,
sound_id: Id<SoundboardMarker>,
) -> DeleteGuildSoundboardSound<'_> {
DeleteGuildSoundboardSound::new(self, guild_id, sound_id)
}

/// Execute a request, returning a future resolving to a [`Response`].
///
/// # Errors
Expand Down
6 changes: 6 additions & 0 deletions twilight-http/src/request/audit_reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ mod private {
integration::DeleteGuildIntegration,
member::{AddRoleToMember, RemoveMember, RemoveRoleFromMember, UpdateGuildMember},
role::{CreateRole, DeleteRole, UpdateRole, UpdateRolePositions},
soundboard::{
CreateGuildSoundboardSound, DeleteGuildSoundboardSound, UpdateGuildSoundboardSound,
},
sticker::{CreateGuildSticker, UpdateGuildSticker},
update_guild_onboarding::UpdateGuildOnboarding,
},
Expand All @@ -59,6 +62,7 @@ mod private {
impl Sealed for CreateGuildExternalScheduledEvent<'_> {}
impl Sealed for CreateGuildPrune<'_> {}
impl Sealed for CreateGuildScheduledEvent<'_> {}
impl Sealed for CreateGuildSoundboardSound<'_> {}
impl Sealed for CreateGuildStageInstanceScheduledEvent<'_> {}
impl Sealed for CreateGuildSticker<'_> {}
impl Sealed for CreateGuildVoiceScheduledEvent<'_> {}
Expand All @@ -72,6 +76,7 @@ mod private {
impl Sealed for DeleteChannelPermissionConfigured<'_> {}
impl Sealed for DeleteEmoji<'_> {}
impl Sealed for DeleteGuildIntegration<'_> {}
impl Sealed for DeleteGuildSoundboardSound<'_> {}
impl Sealed for DeleteInvite<'_> {}
impl Sealed for DeleteMessage<'_> {}
impl Sealed for DeleteMessages<'_> {}
Expand All @@ -92,6 +97,7 @@ mod private {
impl Sealed for UpdateGuildMfa<'_> {}
impl Sealed for UpdateGuildOnboarding<'_> {}
impl Sealed for UpdateGuildScheduledEvent<'_> {}
impl Sealed for UpdateGuildSoundboardSound<'_> {}
impl Sealed for UpdateGuildSticker<'_> {}
impl Sealed for UpdateGuildWidgetSettings<'_> {}
impl Sealed for UpdateRole<'_> {}
Expand Down
1 change: 1 addition & 0 deletions twilight-http/src/request/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod emoji;
pub mod integration;
pub mod member;
pub mod role;
pub mod soundboard;
pub mod sticker;
pub mod update_guild_channel_positions;
pub mod update_guild_onboarding;
Expand Down
Loading
Loading