diff options
| author | Jokler <jokler@protonmail.com> | 2020-01-26 17:53:41 +0100 |
|---|---|---|
| committer | Jokler <jokler@protonmail.com> | 2020-01-29 20:39:27 +0100 |
| commit | 09fc3800030b971da8c68217c22f5a0444d7b278 (patch) | |
| tree | 3c1ff3c89de054851ee4b2fe33b181d5457634e3 | |
| parent | af0a1b81707536caf4e498d86912f65981342072 (diff) | |
| download | pokebot-09fc3800030b971da8c68217c22f5a0444d7b278.tar.gz pokebot-09fc3800030b971da8c68217c22f5a0444d7b278.zip | |
Move duplicate code into on_client_left method
| -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(()); } |
