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 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/bot/music.rs') 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); } -- cgit v1.2.3-70-g09d2