From 09fc3800030b971da8c68217c22f5a0444d7b278 Mon Sep 17 00:00:00 2001 From: Jokler Date: Sun, 26 Jan 2020 17:53:41 +0100 Subject: Move duplicate code into on_client_left method --- src/bot/music.rs | 17 +++++++++-------- 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> { let toml = toml::to_string(&config)?; let mut file = File::create(&args.config_path)?; file.write_all(toml.as_bytes())?; + return Ok(()); } -- cgit v1.2.3-70-g09d2