Rewrite SpoticordSession and small QoL updates

This commit is contained in:
DaXcess
2022-11-23 18:08:57 +01:00
parent 2223de1c30
commit a53c885b6c
10 changed files with 532 additions and 427 deletions
+6 -7
View File
@@ -1,4 +1,4 @@
use log::{error, trace};
use log::error;
use serenity::{
builder::CreateApplicationCommand,
model::prelude::{interaction::application_command::ApplicationCommandInteraction, Channel},
@@ -167,13 +167,13 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
}
let data = ctx.data.read().await;
let mut session_manager = data.get::<SessionManager>().unwrap().clone();
let session_manager = data.get::<SessionManager>().unwrap().clone();
// Check if another session is already active in this server
let mut session_opt = session_manager.get_session(guild.id).await;
if let Some(session) = &session_opt {
if let Some(owner) = session.get_owner().await {
if let Some(owner) = session.owner().await {
let msg = if owner == command.user.id {
"You are already controlling the bot"
} else {
@@ -206,7 +206,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
.description(
format!(
"You are already playing music in another server ({}).\nStop playing in that server first before joining this one.",
ctx.cache.guild(session.get_guild_id()).unwrap().name
ctx.cache.guild(session.guild_id().await).unwrap().name
)).status(Status::Error).build(),
true,
)
@@ -218,8 +218,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
defer_message(&ctx, &command, false).await;
if let Some(session) = &session_opt {
trace!("{} != {}", session.get_channel_id(), channel_id);
if session.get_channel_id() != channel_id {
if session.channel_id().await != channel_id {
session.disconnect().await;
session_opt = None;
@@ -228,7 +227,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
}
}
if let Some(session) = &session_opt {
if let Some(session) = session_opt.as_mut() {
if let Err(why) = session.update_owner(&ctx, command.user.id).await {
// Need to link first
if let SessionCreateError::NoSpotifyError = why {
+1 -1
View File
@@ -36,7 +36,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
}
};
if let Some(owner) = session.get_owner().await {
if let Some(owner) = session.owner().await {
if owner != command.user.id {
// This message was generated by AI, and I love it.
respond_message(
+2 -2
View File
@@ -48,7 +48,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
}
};
let owner = match session.get_owner().await {
let owner = match session.owner().await {
Some(owner) => owner,
None => {
not_playing.await;
@@ -58,7 +58,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
};
// Get Playback Info from session
let pbi = match session.get_playback_info().await {
let pbi = match session.playback_info().await {
Some(pbi) => pbi,
None => {
not_playing.await;