Skip to content

Commit

Permalink
Fix panics
Browse files Browse the repository at this point in the history
  • Loading branch information
tazz4843 committed Feb 2, 2024
1 parent c7ab7b7 commit a557e2a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
10 changes: 8 additions & 2 deletions scripty_audio_handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub use disconnect::disconnect_from_vc;
pub use error::{Error, ErrorKind};
pub use scripty_stt::{check_model_language, get_model_languages};
use serenity::all::{ChannelId, GuildId};
pub use songbird::error::JoinError;
use songbird::{driver::DecodeMode, Config, Songbird};
use songbird::{driver::DecodeMode, Config};
pub use songbird::{error::JoinError, Songbird};
use tokio::sync::oneshot::Sender;

pub fn get_songbird_config() -> Config {
Expand All @@ -36,6 +36,12 @@ pub async fn get_voice_channel_id(guild_id: GuildId) -> Option<ChannelId> {
current_channel.map(|c| ChannelId::new(c.get()))
}

pub fn set_songbird(sb: Arc<Songbird>) {
SONGBIRD
.set(sb)
.expect("should not call set_songbird more than once");
}

pub fn get_songbird() -> Arc<Songbird> {
SONGBIRD.get().expect("songbird not registered").clone()
}
Expand Down
6 changes: 6 additions & 0 deletions scripty_bot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ pub async fn entrypoint() {
.set(data.clone())
.expect("user data setup called more than once: bug?");

let songbird = scripty_audio_handler::Songbird::serenity_from_config(
scripty_audio_handler::get_songbird_config(),
);
scripty_audio_handler::set_songbird(songbird.clone());

let mut client =
serenity::Client::builder(&cfg.tokens.discord, framework_opts::get_gateway_intents())
.data(data.clone())
.framework(framework)
.voice_manager::<scripty_audio_handler::Songbird>(songbird)
.event_handler(handler::BotEventHandler)
.raw_event_handler(handler::RawEventHandler)
.status(OnlineStatus::Idle)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::time::Duration;
use std::{sync::Arc, time::Duration};

Check warning on line 1 in scripty_bot_utils/src/background_tasks/tasks/status_update.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

unused import: `sync::Arc`

warning: unused import: `sync::Arc` --> scripty_bot_utils/src/background_tasks/tasks/status_update.rs:1:11 | 1 | use std::{sync::Arc, time::Duration}; | ^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default

use serenity::{
all::{ActivityType, OnlineStatus},
Expand Down

0 comments on commit a557e2a

Please sign in to comment.