diff options
| -rw-r--r-- | src/bot/music.rs | 17 | ||||
| -rw-r--r-- | src/main.rs | 1 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/bot/music.rs b/src/bot/music.rs index fd1a7da..0bb5274 100644 --- a/src/bot/music.rs +++ b/src/bot/music.rs @@ -336,17 +336,11 @@ impl MusicBot { client: _, old_channel, } => { - let my_channel = self.my_channel(); - if old_channel == my_channel && self.user_count(my_channel) <= 1 { - self.quit(String::from("Channel is empty")); - } + self.on_client_left_channel(old_channel); } MusicBotMessage::ClientDisconnected { id: _, client } => { let old_channel = client.channel; - let my_channel = self.my_channel(); - if old_channel == my_channel && self.user_count(my_channel) <= 1 { - self.quit(String::from("Channel is empty")); - } + self.on_client_left_channel(old_channel); } MusicBotMessage::StateChange(state) => { self.on_state(state)?; @@ -357,6 +351,13 @@ impl MusicBot { Ok(()) } + fn on_client_left_channel(&self, old_channel: ChannelId) { + let my_channel = self.my_channel(); + if old_channel == my_channel && self.user_count(my_channel) <= 1 { + self.quit(String::from("Channel is empty")); + } + } + pub fn quit(&self, reason: String) { self.player.quit(reason); } diff --git a/src/main.rs b/src/main.rs index ae1bed7..d24b6b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -106,6 +106,7 @@ fn run() -> Result<(), Box<dyn std::error::Error>> { let toml = toml::to_string(&config)?; let mut file = File::create(&args.config_path)?; file.write_all(toml.as_bytes())?; + return Ok(()); } |
