diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-08-18 21:21:42 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-08-18 21:21:42 -0700 |
commit | e7c5efe56e51b6c7911d5b96955a989cf0c0a092 (patch) | |
tree | 763b9bb1cd833126ce0050e60ab33942a8e2623e /bocelli | |
parent | e633d656e00fdac51f077eff827518848235e916 (diff) | |
download | bocelli-e7c5efe56e51b6c7911d5b96955a989cf0c0a092.tar.gz bocelli-e7c5efe56e51b6c7911d5b96955a989cf0c0a092.tar.xz |
Match plugins against first word of command.
Diffstat (limited to 'bocelli')
-rw-r--r-- | bocelli/base.rb | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/bocelli/base.rb b/bocelli/base.rb index dfb7875..bea8959 100644 --- a/bocelli/base.rb +++ b/bocelli/base.rb @@ -53,17 +53,24 @@ module Bocelli end def process(str) - routes = @modules.inject([]) { |m, (_, v)| m.push(*v.routes) } - routes.push(*@routes) - - if str =~ /(\S+) PRIVMSG (\S+) :?(.*)/ + if str =~ /\A(\S+) PRIVMSG (\S+) :?(.*)/ metadata = { user: $1, channel: $2, message: $3 } - if (match = routes.detect { |k, _| match(metadata[:message], k) }) + if $3 =~ /\A(\S+) (.*)/ + if (mod = Hash[@modules.map { |k, v| [k.to_s, v] }][$1]) + if (match = mod.routes.detect { |k, _| match($2, k) }) + route, block = match + + return new(str, route, block, metadata).execute + end + end + end + + if (match = @routes.detect { |k, _| match(metadata[:message], k) }) route, block = match new(str, route, block, metadata).execute |