use crate::{
Client,
request::application::{
command::{
CreateGlobalCommand, CreateGuildCommand, DeleteGlobalCommand, DeleteGuildCommand,
GetCommandPermissions, GetGlobalCommand, GetGlobalCommands, GetGuildCommand,
GetGuildCommandPermissions, GetGuildCommands, SetGlobalCommands, SetGuildCommands,
UpdateCommandPermissions, UpdateGlobalCommand, UpdateGuildCommand,
},
interaction::{
CreateFollowup, CreateResponse, DeleteFollowup, DeleteResponse, GetFollowup,
GetResponse, UpdateFollowup, UpdateResponse,
},
},
};
use twilight_model::{
application::command::{Command, permissions::CommandPermission},
http::interaction::InteractionResponse,
id::{
Id,
marker::{ApplicationMarker, CommandMarker, GuildMarker, InteractionMarker, MessageMarker},
},
};
#[derive(Debug)]
pub struct InteractionClient<'a> {
application_id: Id<ApplicationMarker>,
client: &'a Client,
}
impl<'a> InteractionClient<'a> {
pub(super) const fn new(client: &'a Client, application_id: Id<ApplicationMarker>) -> Self {
Self {
application_id,
client,
}
}
pub const fn create_response(
&'a self,
interaction_id: Id<InteractionMarker>,
interaction_token: &'a str,
response: &'a InteractionResponse,
) -> CreateResponse<'a> {
CreateResponse::new(self.client, interaction_id, interaction_token, response)
}
pub const fn delete_response(&'a self, interaction_token: &'a str) -> DeleteResponse<'a> {
DeleteResponse::new(self.client, self.application_id, interaction_token)
}
pub const fn response(&'a self, interaction_token: &'a str) -> GetResponse<'a> {
GetResponse::new(self.client, self.application_id, interaction_token)
}
pub const fn update_response(&'a self, interaction_token: &'a str) -> UpdateResponse<'a> {
UpdateResponse::new(self.client, self.application_id, interaction_token)
}
pub const fn create_followup(&'a self, interaction_token: &'a str) -> CreateFollowup<'a> {
CreateFollowup::new(self.client, self.application_id, interaction_token)
}
pub const fn delete_followup(
&'a self,
interaction_token: &'a str,
message_id: Id<MessageMarker>,
) -> DeleteFollowup<'a> {
DeleteFollowup::new(
self.client,
self.application_id,
interaction_token,
message_id,
)
}
pub const fn followup(
&'a self,
interaction_token: &'a str,
message_id: Id<MessageMarker>,
) -> GetFollowup<'a> {
GetFollowup::new(
self.client,
self.application_id,
interaction_token,
message_id,
)
}
pub const fn update_followup(
&'a self,
interaction_token: &'a str,
message_id: Id<MessageMarker>,
) -> UpdateFollowup<'a> {
UpdateFollowup::new(
self.client,
self.application_id,
interaction_token,
message_id,
)
}
pub const fn create_global_command(&'a self) -> CreateGlobalCommand<'a> {
CreateGlobalCommand::new(self.client, self.application_id)
}
pub const fn delete_global_command(
&self,
command_id: Id<CommandMarker>,
) -> DeleteGlobalCommand<'_> {
DeleteGlobalCommand::new(self.client, self.application_id, command_id)
}
pub const fn global_command(&self, command_id: Id<CommandMarker>) -> GetGlobalCommand<'_> {
GetGlobalCommand::new(self.client, self.application_id, command_id)
}
pub const fn global_commands(&self) -> GetGlobalCommands<'_> {
GetGlobalCommands::new(self.client, self.application_id)
}
pub const fn set_global_commands(&'a self, commands: &'a [Command]) -> SetGlobalCommands<'a> {
SetGlobalCommands::new(self.client, self.application_id, commands)
}
pub const fn update_global_command(
&self,
command_id: Id<CommandMarker>,
) -> UpdateGlobalCommand<'_> {
UpdateGlobalCommand::new(self.client, self.application_id, command_id)
}
pub const fn create_guild_command(
&'a self,
guild_id: Id<GuildMarker>,
) -> CreateGuildCommand<'a> {
CreateGuildCommand::new(self.client, self.application_id, guild_id)
}
pub const fn delete_guild_command(
&self,
guild_id: Id<GuildMarker>,
command_id: Id<CommandMarker>,
) -> DeleteGuildCommand<'_> {
DeleteGuildCommand::new(self.client, self.application_id, guild_id, command_id)
}
pub const fn guild_command(
&self,
guild_id: Id<GuildMarker>,
command_id: Id<CommandMarker>,
) -> GetGuildCommand<'_> {
GetGuildCommand::new(self.client, self.application_id, guild_id, command_id)
}
pub const fn guild_commands(&self, guild_id: Id<GuildMarker>) -> GetGuildCommands<'_> {
GetGuildCommands::new(self.client, self.application_id, guild_id)
}
pub const fn set_guild_commands(
&'a self,
guild_id: Id<GuildMarker>,
commands: &'a [Command],
) -> SetGuildCommands<'a> {
SetGuildCommands::new(self.client, self.application_id, guild_id, commands)
}
pub const fn update_guild_command(
&self,
guild_id: Id<GuildMarker>,
command_id: Id<CommandMarker>,
) -> UpdateGuildCommand<'_> {
UpdateGuildCommand::new(self.client, self.application_id, guild_id, command_id)
}
pub const fn command_permissions(
&self,
guild_id: Id<GuildMarker>,
command_id: Id<CommandMarker>,
) -> GetCommandPermissions<'_> {
GetCommandPermissions::new(self.client, self.application_id, guild_id, command_id)
}
pub const fn guild_command_permissions(
&self,
guild_id: Id<GuildMarker>,
) -> GetGuildCommandPermissions<'_> {
GetGuildCommandPermissions::new(self.client, self.application_id, guild_id)
}
pub fn update_command_permissions(
&'a self,
guild_id: Id<GuildMarker>,
command_id: Id<CommandMarker>,
permissions: &'a [CommandPermission],
) -> UpdateCommandPermissions<'a> {
UpdateCommandPermissions::new(
self.client,
self.application_id,
guild_id,
command_id,
permissions,
)
}
}
#[cfg(test)]
mod tests {
use super::InteractionClient;
use static_assertions::assert_impl_all;
use std::fmt::Debug;
assert_impl_all!(InteractionClient<'_>: Debug, Send, Sync);
}