Reduce the amount of panics
parent
ef86e1e2d3
commit
83e432254b
|
@ -1,6 +1,11 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## 2.2.0 | TBD
|
## 2.2.1 | TBD
|
||||||
|
|
||||||
|
- Fixed a bug where uncached guilds would panic the bot
|
||||||
|
- Fixed small issue with embed styling
|
||||||
|
|
||||||
|
## 2.2.0 | August 13th 2024
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
|
|
||||||
|
|
|
@ -3721,7 +3721,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "spoticord"
|
name = "spoticord"
|
||||||
version = "2.2.0"
|
version = "2.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "spoticord"
|
name = "spoticord"
|
||||||
version = "2.2.0"
|
version = "2.2.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.75.0"
|
rust-version = "1.75.0"
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::bot::Context;
|
||||||
#[poise::command(slash_command, guild_only)]
|
#[poise::command(slash_command, guild_only)]
|
||||||
pub async fn disconnect(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn disconnect(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
let manager = ctx.data();
|
let manager = ctx.data();
|
||||||
let guild = ctx.guild().expect("poise lied to me").id;
|
let guild = ctx.guild_id().expect("poise lied to me");
|
||||||
|
|
||||||
let Some(session) = manager.get_session(SessionQuery::Guild(guild)) else {
|
let Some(session) = manager.get_session(SessionQuery::Guild(guild)) else {
|
||||||
ctx.send(
|
ctx.send(
|
||||||
|
|
|
@ -4,7 +4,7 @@ use anyhow::Result;
|
||||||
use log::error;
|
use log::error;
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
use serenity::all::{
|
use serenity::all::{
|
||||||
Channel, ChannelId, CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter, Guild, UserId,
|
Channel, ChannelId, CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter, UserId,
|
||||||
};
|
};
|
||||||
use spoticord_database::error::DatabaseError;
|
use spoticord_database::error::DatabaseError;
|
||||||
use spoticord_session::manager::SessionQuery;
|
use spoticord_session::manager::SessionQuery;
|
||||||
|
@ -15,9 +15,30 @@ use crate::bot::Context;
|
||||||
/// Join the current voice channel
|
/// Join the current voice channel
|
||||||
#[poise::command(slash_command, guild_only)]
|
#[poise::command(slash_command, guild_only)]
|
||||||
pub async fn join(ctx: Context<'_>) -> Result<()> {
|
pub async fn join(ctx: Context<'_>) -> Result<()> {
|
||||||
let guild: Guild = ctx.guild().expect("poise lied to me").clone();
|
let guild = ctx.guild_id().expect("poise lied to me");
|
||||||
let manager = ctx.data();
|
let manager = ctx.data();
|
||||||
|
|
||||||
|
let Some(guild) = guild
|
||||||
|
.to_guild_cached(ctx.serenity_context())
|
||||||
|
.map(|guild| guild.clone())
|
||||||
|
else {
|
||||||
|
error!("Unable to fetch guild from cache, how did we get here?");
|
||||||
|
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default()
|
||||||
|
.embed(
|
||||||
|
CreateEmbed::new()
|
||||||
|
.title("An error occured")
|
||||||
|
.description("This server hasn't been cached yet?")
|
||||||
|
.color(Colors::Error),
|
||||||
|
)
|
||||||
|
.ephemeral(true),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
|
||||||
let Some(channel) = guild
|
let Some(channel) = guild
|
||||||
.voice_states
|
.voice_states
|
||||||
.get(&ctx.author().id)
|
.get(&ctx.author().id)
|
||||||
|
@ -98,8 +119,6 @@ pub async fn join(ctx: Context<'_>) -> Result<()> {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.defer().await?;
|
|
||||||
|
|
||||||
let mut session_opt = manager.get_session(SessionQuery::Guild(guild.id));
|
let mut session_opt = manager.get_session(SessionQuery::Guild(guild.id));
|
||||||
|
|
||||||
// Check if this server already has a session active
|
// Check if this server already has a session active
|
||||||
|
@ -134,7 +153,8 @@ pub async fn join(ctx: Context<'_>) -> Result<()> {
|
||||||
"You are already using Spoticord in `{}`\n\n\
|
"You are already using Spoticord in `{}`\n\n\
|
||||||
Stop playing in that server first before starting a new session.",
|
Stop playing in that server first before starting a new session.",
|
||||||
spoticord_utils::discord::escape(server_name)
|
spoticord_utils::discord::escape(server_name)
|
||||||
)),
|
))
|
||||||
|
.color(Colors::Error),
|
||||||
)
|
)
|
||||||
.ephemeral(true),
|
.ephemeral(true),
|
||||||
)
|
)
|
||||||
|
@ -143,6 +163,8 @@ pub async fn join(ctx: Context<'_>) -> Result<()> {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.defer().await?;
|
||||||
|
|
||||||
if let Some(session) = &session_opt {
|
if let Some(session) = &session_opt {
|
||||||
if session.voice_channel() != channel {
|
if session.voice_channel() != channel {
|
||||||
session.disconnect().await;
|
session.disconnect().await;
|
||||||
|
@ -163,7 +185,7 @@ pub async fn join(ctx: Context<'_>) -> Result<()> {
|
||||||
CreateEmbed::new()
|
CreateEmbed::new()
|
||||||
.title("Failed to reactivate session")
|
.title("Failed to reactivate session")
|
||||||
.description(
|
.description(
|
||||||
"An error occured whilst trying to reactivate the session.",
|
"An error occured whilst trying to reactivate the session. Please try again.",
|
||||||
)
|
)
|
||||||
.color(Colors::Error),
|
.color(Colors::Error),
|
||||||
)
|
)
|
||||||
|
@ -190,7 +212,9 @@ pub async fn join(ctx: Context<'_>) -> Result<()> {
|
||||||
.embed(
|
.embed(
|
||||||
CreateEmbed::new()
|
CreateEmbed::new()
|
||||||
.title("Failed to create session")
|
.title("Failed to create session")
|
||||||
.description("An error occured whilst trying to create a session.")
|
.description(
|
||||||
|
"An error occured whilst trying to create a session. Please try again.",
|
||||||
|
)
|
||||||
.color(Colors::Error),
|
.color(Colors::Error),
|
||||||
)
|
)
|
||||||
.ephemeral(true),
|
.ephemeral(true),
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::bot::Context;
|
||||||
#[poise::command(slash_command, guild_only)]
|
#[poise::command(slash_command, guild_only)]
|
||||||
pub async fn lyrics(ctx: Context<'_>) -> Result<()> {
|
pub async fn lyrics(ctx: Context<'_>) -> Result<()> {
|
||||||
let manager = ctx.data();
|
let manager = ctx.data();
|
||||||
let guild = ctx.guild().expect("poise lied to me").id;
|
let guild = ctx.guild_id().expect("poise lied to me");
|
||||||
|
|
||||||
let Some(session) = manager.get_session(SessionQuery::Guild(guild)) else {
|
let Some(session) = manager.get_session(SessionQuery::Guild(guild)) else {
|
||||||
ctx.send(
|
ctx.send(
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::bot::Context;
|
||||||
#[poise::command(slash_command, guild_only)]
|
#[poise::command(slash_command, guild_only)]
|
||||||
pub async fn playing(ctx: Context<'_>) -> Result<()> {
|
pub async fn playing(ctx: Context<'_>) -> Result<()> {
|
||||||
let manager = ctx.data();
|
let manager = ctx.data();
|
||||||
let guild = ctx.guild().expect("poise lied to me").id;
|
let guild = ctx.guild_id().expect("poise lied to me");
|
||||||
|
|
||||||
let Some(session) = manager.get_session(SessionQuery::Guild(guild)) else {
|
let Some(session) = manager.get_session(SessionQuery::Guild(guild)) else {
|
||||||
ctx.send(
|
ctx.send(
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::bot::Context;
|
||||||
#[poise::command(slash_command, guild_only)]
|
#[poise::command(slash_command, guild_only)]
|
||||||
pub async fn stop(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn stop(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
let manager = ctx.data();
|
let manager = ctx.data();
|
||||||
let guild = ctx.guild().expect("poise lied to me").id;
|
let guild = ctx.guild_id().expect("poise lied to me");
|
||||||
|
|
||||||
let Some(session) = manager.get_session(SessionQuery::Guild(guild)) else {
|
let Some(session) = manager.get_session(SessionQuery::Guild(guild)) else {
|
||||||
ctx.send(
|
ctx.send(
|
||||||
|
|
Loading…
Reference in New Issue