From e7c5efe56e51b6c7911d5b96955a989cf0c0a092 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 18 Aug 2014 21:21:42 -0700 Subject: Match plugins against first word of command. --- bocelli/base.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'bocelli/base.rb') 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 -- cgit v1.2.3-70-g09d2