Skip to content
This repository was archived by the owner on Jun 17, 2025. It is now read-only.

Commit f7097b0

Browse files
committed
Allow /leave to forcibly reset state
1 parent 793b96a commit f7097b0

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

scripty_audio_handler/src/disconnect.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
use std::time::Duration;
22

33
use dashmap::DashMap;
4+
use scripty_data_type::get_data;
45
use serenity::{gateway::client::Context, model::id::GuildId};
56
use songbird::error::JoinError;
67

78
use crate::error::Error;
89

9-
pub async fn disconnect_from_vc(_ctx: &Context, guild_id: GuildId) -> Result<bool, Error> {
10+
pub async fn disconnect_from_vc(ctx: &Context, guild_id: GuildId) -> Result<bool, Error> {
1011
let sb = crate::get_songbird();
1112
let res = match sb.remove(guild_id).await {
1213
Ok(()) => Ok(true),
1314
Err(JoinError::NoCall) => Ok(false),
1415
Err(e) => Err(e.into()),
1516
};
1617

18+
get_data(ctx).existing_calls.force_remove_guild(&guild_id);
19+
1720
let existing = super::AUTO_LEAVE_TASKS
1821
.get_or_init(|| DashMap::with_hasher(ahash::RandomState::default()))
1922
.remove(&guild_id);

scripty_bot_utils/src/error/error_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl Display for Error {
261261
AudioTranscription(e) => format!("Failed to transcribe audio message: {}", e).into(),
262262
KiaiError(e) => format!("Kiai API error: {}", e).into(),
263263
CallAlreadyExists => "a call for this channel already exists - not trying to rejoin \
264-
the same channel"
264+
the same channel - run `/leave` if this is wrong"
265265
.into(),
266266
NoGuildDefaults => "no default configuration exists for this server".into(),
267267
BadDiscordState => "Discord sent us bad data".into(),

scripty_data_type/src/call_death_struct.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ impl CallLivenessMap {
2121
pub fn existing_channel_for_guild(&self, guild_id: &GuildId) -> Option<ChannelId> {
2222
Some(self.0.get(guild_id)?.value().0)
2323
}
24+
25+
pub fn force_remove_guild(&self, guild_id: &GuildId) -> bool {
26+
self.0.remove(guild_id).is_some()
27+
}
2428
}
2529

2630
impl Default for CallLivenessMap {
@@ -66,7 +70,8 @@ impl Drop for CallDeath {
6670
last = true;
6771
}
6872
} else {
69-
unreachable!("should be impossible to delete without the atomic value at 0");
73+
// FIXME: log this
74+
// "should be impossible to delete without the atomic value at 0"
7075
}
7176
if last {
7277
if let Some(v) = self.inner.0.remove(&self.guild_id) {

0 commit comments

Comments
 (0)