Updating auth
This commit is contained in:
@@ -12,7 +12,7 @@ use serenity::all::{
|
||||
};
|
||||
|
||||
pub async fn process_message(ctx: &Context, command: &CommandInteraction, private: bool) {
|
||||
create_message_response(&ctx, &command, "Processing...".to_string(), private).await;
|
||||
create_message_response(ctx, command, "Processing...".to_string(), private).await;
|
||||
}
|
||||
|
||||
pub async fn user_dm(ctx: &Context, user_id: &UserId, content: String) -> Option<Message> {
|
||||
|
||||
@@ -77,7 +77,7 @@ fn find_voice_channel(
|
||||
|
||||
match guild
|
||||
.voice_states
|
||||
.get(&user_id)
|
||||
.get(user_id)
|
||||
.and_then(|voice_state| voice_state.channel_id)
|
||||
{
|
||||
Some(channel) => Ok(channel),
|
||||
|
||||
@@ -9,7 +9,7 @@ use serenity::{
|
||||
|
||||
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
// Create the initial response
|
||||
process_message(&ctx, &command, false).await;
|
||||
process_message(ctx, command, false).await;
|
||||
|
||||
// Get the songbird manager
|
||||
let manager = get_songbird();
|
||||
@@ -19,8 +19,8 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
Some(guild_id) => guild_id,
|
||||
None => {
|
||||
edit_response(
|
||||
&ctx,
|
||||
&command,
|
||||
ctx,
|
||||
command,
|
||||
"Unable to find the current server ID".to_string(),
|
||||
)
|
||||
.await;
|
||||
@@ -36,14 +36,14 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
Ok(_) => {
|
||||
if is_muted {
|
||||
log::debug!("<{guild_id}> Unmuted");
|
||||
edit_response(&ctx, &command, "Unmuted".to_string()).await;
|
||||
edit_response(ctx, command, "Unmuted".to_string()).await;
|
||||
} else {
|
||||
log::debug!("<{guild_id}> Muted");
|
||||
edit_response(&ctx, &command, "Muted".to_string()).await;
|
||||
edit_response(ctx, command, "Muted".to_string()).await;
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
edit_response(&ctx, &command, format!("Failed to mute: {}", err)).await;
|
||||
edit_response(ctx, command, format!("Failed to mute: {}", err)).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ use std::sync::Arc;
|
||||
|
||||
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
// Create the initial response
|
||||
process_message(&ctx, &command, false).await;
|
||||
process_message(ctx, command, false).await;
|
||||
|
||||
// Get the songbird manager
|
||||
let manager = get_songbird();
|
||||
@@ -22,8 +22,8 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
Some(guild_id) => guild_id,
|
||||
None => {
|
||||
edit_response(
|
||||
&ctx,
|
||||
&command,
|
||||
ctx,
|
||||
command,
|
||||
"Unable to find the current server ID".to_string(),
|
||||
)
|
||||
.await;
|
||||
@@ -35,9 +35,9 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
match pause_track(manager, guild_id).await {
|
||||
Ok(_) => {
|
||||
log::debug!("<{guild_id}> Paused the track");
|
||||
edit_response(&ctx, &command, "Pausing the track".to_string()).await;
|
||||
edit_response(ctx, command, "Pausing the track".to_string()).await;
|
||||
}
|
||||
Err(err) => edit_response(&ctx, &command, format!("Failed to pause: {}", err)).await,
|
||||
Err(err) => edit_response(ctx, command, format!("Failed to pause: {}", err)).await,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,13 +32,13 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
command.guild_id.unwrap(),
|
||||
command.user.id.get()
|
||||
);
|
||||
create_message_response(&ctx, &command, "Track option is missing".to_string(), false).await;
|
||||
create_message_response(ctx, command, "Track option is missing".to_string(), false).await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// Create the initial response
|
||||
process_message(&ctx, &command, false).await;
|
||||
process_message(ctx, command, false).await;
|
||||
|
||||
// Get the songbird manager
|
||||
let manager = get_songbird();
|
||||
@@ -48,8 +48,8 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
Some(guild_id) => guild_id,
|
||||
None => {
|
||||
edit_response(
|
||||
&ctx,
|
||||
&command,
|
||||
ctx,
|
||||
command,
|
||||
"Unable to find the current server ID".to_string(),
|
||||
)
|
||||
.await;
|
||||
@@ -58,7 +58,7 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
};
|
||||
|
||||
// Join the user's voice channel
|
||||
match join_voice_channel(&ctx.cache, &manager, guild_id, &command.user.id).await {
|
||||
match join_voice_channel(&ctx.cache, manager, guild_id, &command.user.id).await {
|
||||
Ok(channel_id) => {
|
||||
log::debug!(
|
||||
"<{guild_id}> Play command executed on channel {channel_id} with track: {track_url:?}"
|
||||
@@ -67,29 +67,29 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
match enqueue_track(manager, guild_id.to_owned(), track_url).await {
|
||||
Ok(items) => {
|
||||
let mut message = format!("Added {} tracks", items.len());
|
||||
if items.len() == 0 {
|
||||
if items.is_empty() {
|
||||
message = "No tracks were played".to_string();
|
||||
log::warn!("<{guild_id}> No tracks were played");
|
||||
if let Err(err) = leave_voice_channel(&manager, guild_id).await {
|
||||
if let Err(err) = leave_voice_channel(manager, guild_id).await {
|
||||
log::error!("Failed to leave voice channel: {}", err);
|
||||
};
|
||||
} else if items.len() == 1 {
|
||||
message = format!("Added **{}**", items[0].get_title());
|
||||
}
|
||||
edit_response(&ctx, &command, message).await;
|
||||
edit_response(ctx, command, message).await;
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!("Failed to play track: {}", err);
|
||||
if let Err(err) = leave_voice_channel(&manager, guild_id).await {
|
||||
if let Err(err) = leave_voice_channel(manager, guild_id).await {
|
||||
log::error!("Failed to leave voice channel: {}", err);
|
||||
}
|
||||
edit_response(&ctx, &command, format!("Failed to play track: {}", err)).await;
|
||||
edit_response(ctx, command, format!("Failed to play track: {}", err)).await;
|
||||
}
|
||||
};
|
||||
}
|
||||
Err(err) => {
|
||||
log::warn!("<{guild_id}> Failed to join voice channel: {}", err);
|
||||
edit_response(&ctx, &command, format!("{}", err)).await;
|
||||
edit_response(ctx, command, format!("{}", err)).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ pub async fn enqueue_track(
|
||||
if let Some(handler_lock) = manager.get(guild_id) {
|
||||
let mut handler = handler_lock.lock().await;
|
||||
let guild = GuildCache::find_by_id(guild_id.get() as i64).await.unwrap();
|
||||
let valid = is_valid_url(&track_url);
|
||||
let valid = is_valid_url(track_url);
|
||||
|
||||
// Check if the URL is valid
|
||||
if !valid {
|
||||
@@ -111,7 +111,7 @@ pub async fn enqueue_track(
|
||||
return Err(Error::new(422, format!("Invalid track url: {}", track_url)));
|
||||
}
|
||||
|
||||
playlist_items = get_ytdlp_items(&track_url)?;
|
||||
playlist_items = get_ytdlp_items(track_url)?;
|
||||
|
||||
// Add each track to the queue
|
||||
for item in &playlist_items {
|
||||
@@ -122,8 +122,7 @@ pub async fn enqueue_track(
|
||||
let input: Input = source.into();
|
||||
let track_title = item.get_title().to_owned();
|
||||
|
||||
let track_handle: TrackHandle;
|
||||
track_handle = handler.enqueue_input(input).await;
|
||||
let track_handle: TrackHandle = handler.enqueue_input(input).await;
|
||||
|
||||
// Set the volume
|
||||
let _ = track_handle.set_volume(volume);
|
||||
|
||||
@@ -12,7 +12,7 @@ use std::sync::Arc;
|
||||
|
||||
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
// Create the initial response
|
||||
process_message(&ctx, &command, false).await;
|
||||
process_message(ctx, command, false).await;
|
||||
|
||||
// Get the songbird manager
|
||||
let manager = get_songbird();
|
||||
@@ -22,8 +22,8 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
Some(guild_id) => guild_id,
|
||||
None => {
|
||||
edit_response(
|
||||
&ctx,
|
||||
&command,
|
||||
ctx,
|
||||
command,
|
||||
"Unable to find the current server ID".to_string(),
|
||||
)
|
||||
.await;
|
||||
@@ -35,9 +35,9 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
match resume_track(manager, guild_id).await {
|
||||
Ok(_) => {
|
||||
log::debug!("<{guild_id}> Resumed the track");
|
||||
edit_response(&ctx, &command, "resuming the track".to_string()).await;
|
||||
edit_response(ctx, command, "resuming the track".to_string()).await;
|
||||
}
|
||||
Err(err) => edit_response(&ctx, &command, format!("Failed to resume: {}", err)).await,
|
||||
Err(err) => edit_response(ctx, command, format!("Failed to resume: {}", err)).await,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use serenity::{
|
||||
|
||||
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
// Create the initial response
|
||||
process_message(&ctx, &command, false).await;
|
||||
process_message(ctx, command, false).await;
|
||||
|
||||
// Get the songbird manager
|
||||
let manager = get_songbird();
|
||||
@@ -19,8 +19,8 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
Some(guild_id) => guild_id,
|
||||
None => {
|
||||
edit_response(
|
||||
&ctx,
|
||||
&command,
|
||||
ctx,
|
||||
command,
|
||||
"Unable to find the current server ID".to_string(),
|
||||
)
|
||||
.await;
|
||||
@@ -34,10 +34,10 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
match handler.queue().skip() {
|
||||
Ok(_) => {
|
||||
log::debug!("<{guild_id}> Skipped the track");
|
||||
edit_response(&ctx, &command, "Skipping the track".to_string()).await;
|
||||
edit_response(ctx, command, "Skipping the track".to_string()).await;
|
||||
}
|
||||
Err(err) => {
|
||||
edit_response(&ctx, &command, format!("Failed to skip: {}", err)).await;
|
||||
edit_response(ctx, command, format!("Failed to skip: {}", err)).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ use serenity::{
|
||||
|
||||
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
// Create the initial response
|
||||
process_message(&ctx, &command, false).await;
|
||||
process_message(ctx, command, false).await;
|
||||
|
||||
// Get the songbird manager
|
||||
let manager = get_songbird();
|
||||
@@ -19,8 +19,8 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
Some(g) => g,
|
||||
None => {
|
||||
edit_response(
|
||||
&ctx,
|
||||
&command,
|
||||
ctx,
|
||||
command,
|
||||
"Unable to find the current server ID".to_string(),
|
||||
)
|
||||
.await;
|
||||
@@ -33,7 +33,7 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
let handler = handler_lock.lock().await;
|
||||
handler.queue().stop();
|
||||
log::debug!("<{guild_id}> Stopped the track");
|
||||
edit_response(&ctx, &command, "Stopping the tracks".to_string()).await;
|
||||
edit_response(ctx, command, "Stopping the tracks".to_string()).await;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,19 +20,13 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
"{} attempted to change the volume without a volume option",
|
||||
command.user.id.get()
|
||||
);
|
||||
create_message_response(
|
||||
&ctx,
|
||||
&command,
|
||||
"Volume option is missing".to_string(),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
create_message_response(ctx, command, "Volume option is missing".to_string(), false).await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// Create the initial response
|
||||
process_message(&ctx, &command, false).await;
|
||||
process_message(ctx, command, false).await;
|
||||
|
||||
// Get the songbird manager
|
||||
let manager = get_songbird();
|
||||
@@ -42,8 +36,8 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
Some(guild_id) => guild_id,
|
||||
None => {
|
||||
edit_response(
|
||||
&ctx,
|
||||
&command,
|
||||
ctx,
|
||||
command,
|
||||
"Unable to find the current server ID".to_string(),
|
||||
)
|
||||
.await;
|
||||
@@ -52,15 +46,14 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
};
|
||||
|
||||
// Set the volume
|
||||
set_volume(&manager, guild_id, volume).await;
|
||||
set_volume(manager, guild_id, volume).await;
|
||||
log::debug!("<{guild_id}> Setting the volume to {}", volume);
|
||||
edit_response(&ctx, &command, format!("Setting the volume to {}", volume)).await;
|
||||
edit_response(ctx, command, format!("Setting the volume to {}", volume)).await;
|
||||
}
|
||||
|
||||
pub async fn set_volume(manager: &Arc<Songbird>, guild_id: &GuildId, volume: i32) {
|
||||
// Format volume to f32 bound between 0.0 and 1.0
|
||||
let volume = std::cmp::min(100, std::cmp::max(0, volume));
|
||||
let bound_volume = volume as f32 / 100.0;
|
||||
let bound_volume = volume.clamp(0, 100) as f32 / 100.0;
|
||||
|
||||
// Update the guild cache
|
||||
let mut guild_cache = GuildCache::find_by_id(guild_id.get() as i64).await.unwrap();
|
||||
@@ -70,7 +63,7 @@ pub async fn set_volume(manager: &Arc<Songbird>, guild_id: &GuildId, volume: i32
|
||||
// Update the volume of the songbird handler
|
||||
if let Some(handler_lock) = manager.get(guild_id.to_owned()) {
|
||||
let handler = handler_lock.lock().await;
|
||||
for (_, track_handle) in handler.queue().current_queue().iter().enumerate() {
|
||||
for track_handle in handler.queue().current_queue().iter() {
|
||||
if let Err(err) = track_handle.set_volume(bound_volume) {
|
||||
log::error!("Unable to set volume: {err}");
|
||||
}
|
||||
|
||||
@@ -17,10 +17,17 @@ use siren_core::data::events::Event;
|
||||
|
||||
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
// Create the initial response
|
||||
process_message(&ctx, &command, true).await;
|
||||
process_message(ctx, command, true).await;
|
||||
|
||||
// Process the command options
|
||||
let title = command.data.options.get(0).unwrap().value.as_str().unwrap();
|
||||
let title = command
|
||||
.data
|
||||
.options
|
||||
.first()
|
||||
.unwrap()
|
||||
.value
|
||||
.as_str()
|
||||
.unwrap();
|
||||
// let datetime_string = command.data.options.get(1).unwrap().value.as_str().unwrap();
|
||||
let description = command
|
||||
.data
|
||||
|
||||
@@ -39,7 +39,7 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
|
||||
create_message_response(
|
||||
ctx,
|
||||
&command,
|
||||
command,
|
||||
format!("Sending request to {}", user_id.mention()),
|
||||
true,
|
||||
)
|
||||
@@ -48,7 +48,7 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
let dice_string = command
|
||||
.data
|
||||
.options
|
||||
.get(0)
|
||||
.first()
|
||||
.and_then(|o| o.value.as_str())
|
||||
.map(|s| s.split_whitespace().collect::<String>())
|
||||
.unwrap();
|
||||
@@ -79,7 +79,7 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
};
|
||||
}
|
||||
Err(why) => {
|
||||
edit_response(ctx, &command, why.to_string()).await;
|
||||
edit_response(ctx, command, why.to_string()).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,19 +34,19 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
.find(|opt| opt.name == "user")
|
||||
.and_then(|o| o.value.as_mentionable());
|
||||
|
||||
create_message_response(ctx, &command, "Rolling...".to_string(), private).await;
|
||||
create_message_response(ctx, command, "Rolling...".to_string(), private).await;
|
||||
|
||||
let dice_string = match command
|
||||
.data
|
||||
.options
|
||||
.get(0)
|
||||
.first()
|
||||
.and_then(|o| o.value.as_str())
|
||||
.map(|s| s.split_whitespace().collect::<String>())
|
||||
{
|
||||
Some(dice_value) => dice_value,
|
||||
None => {
|
||||
log::warn!("Missing or invalid dice option");
|
||||
let _ = edit_response(&ctx, &command, "Dice option is missing".to_string()).await;
|
||||
let _ = edit_response(ctx, command, "Dice option is missing".to_string()).await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
@@ -63,18 +63,18 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
let roller_id = command.user.id;
|
||||
send_roll_message(ctx, total, user_id, roller_id, &response).await;
|
||||
edit_response(
|
||||
&ctx,
|
||||
ctx,
|
||||
command,
|
||||
format!("Sending dice roll results to {}", &user_id.mention()),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
None => edit_response(&ctx, &command, format!("🎲 {}\n-# {}", total, response)).await,
|
||||
None => edit_response(ctx, command, format!("🎲 {}\n-# {}", total, response)).await,
|
||||
};
|
||||
// Check for dice tracks
|
||||
}
|
||||
Err(why) => {
|
||||
edit_response(&ctx, &command, format!("Invalid dice string: {}", why)).await;
|
||||
edit_response(ctx, command, format!("Invalid dice string: {}", why)).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||
}
|
||||
}
|
||||
|
||||
create_message_response(&ctx, &command, "pong".to_string(), true).await;
|
||||
create_message_response(ctx, command, "pong".to_string(), true).await;
|
||||
}
|
||||
|
||||
pub fn register() -> CreateCommand {
|
||||
|
||||
@@ -54,7 +54,7 @@ impl EventHandler for BotHandler {
|
||||
}
|
||||
|
||||
// Handle direct messages
|
||||
if let None = msg.guild_id {
|
||||
if msg.guild_id.is_none() {
|
||||
log::trace!("Received DM from {}: {}", msg.author, msg.content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,12 @@ pub struct YtDlp {
|
||||
args: Vec<String>,
|
||||
}
|
||||
|
||||
impl Default for YtDlp {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl YtDlp {
|
||||
pub fn new() -> Self {
|
||||
let mut cmd = Command::new(YOUTUBE_DL_COMMAND);
|
||||
|
||||
Reference in New Issue
Block a user