use interactions instead of chat commands
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,34 +1,81 @@
|
||||
use std::{error::Error, num::NonZeroU64};
|
||||
use twilight_model::channel::Message;
|
||||
|
||||
use crate::state::State;
|
||||
use std::error::Error;
|
||||
use tracing::debug;
|
||||
use twilight_model::{
|
||||
application::interaction::Interaction,
|
||||
channel::message::MessageFlags,
|
||||
http::interaction::{InteractionResponse, InteractionResponseType},
|
||||
id::{
|
||||
marker::{GuildMarker, UserMarker},
|
||||
Id,
|
||||
},
|
||||
};
|
||||
use twilight_util::builder::InteractionResponseDataBuilder;
|
||||
|
||||
pub(crate) async fn join(
|
||||
msg: Message,
|
||||
pub(crate) async fn join_channel(
|
||||
state: State,
|
||||
guild_id: Id<GuildMarker>,
|
||||
user_id: Id<UserMarker>,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
||||
let guild_id = msg.guild_id.ok_or("No guild id attached to the message.")?;
|
||||
let user_id = msg.author.id;
|
||||
debug!("join user {:?} in guild {:?}", user_id, guild_id);
|
||||
|
||||
let channel_id = state
|
||||
.cache
|
||||
.voice_state(user_id, guild_id)
|
||||
.ok_or("Cannot get voice state for user")?
|
||||
.channel_id();
|
||||
let channel_id =
|
||||
NonZeroU64::new(channel_id.into()).ok_or("Joined voice channel must have nonzero ID.")?;
|
||||
|
||||
// join the voice channel
|
||||
state
|
||||
.songbird
|
||||
.join(guild_id, channel_id)
|
||||
.join(guild_id.cast(), channel_id)
|
||||
.await
|
||||
.map_err(|e| format!("Could not join voice channel: {:?}", e))?;
|
||||
|
||||
// signal that we are not listening
|
||||
if let Some(call_lock) = state.songbird.get(guild_id) {
|
||||
if let Some(call_lock) = state.songbird.get(guild_id.cast()) {
|
||||
let mut call = call_lock.lock().await;
|
||||
call.deafen(true).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn join(
|
||||
interaction: Interaction,
|
||||
state: State,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
||||
debug!(
|
||||
"join command in guild {:?} in channel {:?} by {:?}",
|
||||
interaction.guild_id,
|
||||
interaction.channel,
|
||||
interaction.author(),
|
||||
);
|
||||
|
||||
let Some(guild_id) = interaction.guild_id else {
|
||||
return Ok(());
|
||||
};
|
||||
let Some(author_id) = interaction.author_id() else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
join_channel(state.clone(), guild_id, author_id).await?;
|
||||
|
||||
let interaction_response_data = InteractionResponseDataBuilder::new()
|
||||
.content("Bin da Brudi!")
|
||||
.flags(MessageFlags::EPHEMERAL)
|
||||
.build();
|
||||
|
||||
let response = InteractionResponse {
|
||||
kind: InteractionResponseType::ChannelMessageWithSource,
|
||||
data: Some(interaction_response_data),
|
||||
};
|
||||
|
||||
state
|
||||
.http
|
||||
.interaction(interaction.application_id)
|
||||
.create_response(interaction.id, &interaction.token, &response)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user