diff options
| author | Jokler <jokler.contact@gmail.com> | 2019-02-21 04:11:52 +0100 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2019-02-21 04:11:52 +0100 |
| commit | f5554ef8a8af5e9d5c6604c9130d65c71e31be81 (patch) | |
| tree | 8318c222c9dd3dcc9dc22e611df1028ea16afc5d /src | |
| parent | 79146633203db377a6669ede5ff5bcb1b34d4d05 (diff) | |
| download | frippy-f5554ef8a8af5e9d5c6604c9130d65c71e31be81.tar.gz frippy-f5554ef8a8af5e9d5c6604c9130d65c71e31be81.zip | |
Unicode: Always send a notice on error
Diffstat (limited to 'src')
| -rw-r--r-- | src/plugins/unicode.rs | 44 |
1 files changed, 22 insertions, 22 deletions
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<C: FrippyClient> Unicode<C> { } 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::<Vec<String>>() - .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::<Vec<String>>() + .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<C: FrippyClient> Plugin for Unicode<C> { } 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) { |
