From f5554ef8a8af5e9d5c6604c9130d65c71e31be81 Mon Sep 17 00:00:00 2001 From: Jokler Date: Thu, 21 Feb 2019 04:11:52 +0100 Subject: Unicode: Always send a notice on error --- src/plugins/unicode.rs | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/plugins/unicode.rs b/src/plugins/unicode.rs index 0736ac7..56c8666 100644 --- a/src/plugins/unicode.rs +++ b/src/plugins/unicode.rs @@ -31,27 +31,27 @@ impl Unicode { } fn format_response(&self, content: &str) -> String { - let character = content.chars().next(); - if let Some(c) = character { - let mut buf = [0; 4]; - - let byte_string = c - .encode_utf8(&mut buf) - .as_bytes() - .iter() - .map(|b| format!("{:#b}", b)) - .collect::>() - .join(","); - - let name = self.get_name(c); - - format!( - "{} is '{}' | UTF-8: {2:#x} ({2}), Bytes: [{3}]", - c, name, c as u32, byte_string - ) - } else { - String::from("No non-space character was found.") - } + let character = content + .chars() + .next() + .expect("content contains at least one character"); + + let mut buf = [0; 4]; + + let byte_string = character + .encode_utf8(&mut buf) + .as_bytes() + .iter() + .map(|b| format!("{:#b}", b)) + .collect::>() + .join(","); + + let name = self.get_name(character); + + format!( + "{} is '{}' | UTF-8: {2:#x} ({2}), Bytes: [{3}]", + character, name, character as u32, byte_string + ) } } @@ -67,7 +67,7 @@ impl Plugin for Unicode { } fn command(&self, client: &Self::Client, command: PluginCommand) -> Result<(), FrippyError> { - if command.tokens.is_empty() { + if command.tokens.is_empty() || command.tokens[0].is_empty() { let msg = "No non-space character was found."; if let Err(e) = client.send_notice(command.source, msg) { -- cgit v1.2.3-70-g09d2