aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugin.rs
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-03-19 03:26:09 +0100
committerJokler <jokler.contact@gmail.com>2018-03-19 03:26:09 +0100
commit0e84a9c5cad2c5b8d4a2a9cff67c106ce4a47dfa (patch)
treec6f20859805190a7beb6366a5cee89f23cba407e /src/plugin.rs
parent47627f9219c75290125f980761b4ec9b5f6fe1f4 (diff)
downloadfrippy-0e84a9c5cad2c5b8d4a2a9cff67c106ce4a47dfa.tar.gz
frippy-0e84a9c5cad2c5b8d4a2a9cff67c106ce4a47dfa.zip
Use a prefix from the config instead of the nick
Diffstat (limited to 'src/plugin.rs')
-rw-r--r--src/plugin.rs37
1 files changed, 13 insertions, 24 deletions
diff --git a/src/plugin.rs b/src/plugin.rs
index bc428d5..6c81741 100644
--- a/src/plugin.rs
+++ b/src/plugin.rs
@@ -66,35 +66,24 @@ impl PluginCommand {
/// Creates a `PluginCommand` from [`Message`](../../irc/proto/message/struct.Message.html)
/// if it contains a [`PRIVMSG`](../../irc/proto/command/enum.Command.html#variant.PRIVMSG)
/// that starts with the provided `nick`.
- pub fn from(nick: &str, message: &Message) -> Option<PluginCommand> {
+ pub fn try_from(prefix: &str, message: &Message) -> Option<PluginCommand> {
// Get the actual message out of PRIVMSG
if let Command::PRIVMSG(_, ref content) = message.command {
- // Split content by spaces and filter empty tokens
+ // Split content by spaces
let mut tokens: Vec<String> = content.split(' ').map(ToOwned::to_owned).collect();
- // Commands start with our name
- if tokens[0].to_lowercase().starts_with(nick) {
- // Remove the bot's name from the first token
- tokens[0].drain(..nick.len());
-
- // We assume that only ':' and ',' are used as suffixes on IRC
- // If there are any other chars we assume that it is not ment for the bot
- tokens[0] = tokens[0].chars().filter(|&c| !":,".contains(c)).collect();
- if !tokens[0].is_empty() {
- return None;
- }
-
- // The first token contained the name of the bot
- tokens.remove(0);
-
- Some(PluginCommand {
- source: message.source_nickname().unwrap().to_string(),
- target: message.response_target().unwrap().to_string(),
- tokens: tokens,
- })
- } else {
- None
+ // Commands start with a prefix
+ if !tokens[0].to_lowercase().starts_with(prefix) {
+ return None;
}
+ // Remove the prefix from the first token
+ tokens[0].drain(..prefix.len());
+
+ Some(PluginCommand {
+ source: message.source_nickname().unwrap().to_string(),
+ target: message.response_target().unwrap().to_string(),
+ tokens: tokens,
+ })
} else {
None
}