botpop/plugins/searchable.rb
2015-07-13 20:23:50 +02:00

25 lines
710 B
Ruby

#encoding: utf-8
module BotpopPlugins
module Searchable
MATCH = lambda do |parent, plugin|
parent.on :message, /\!(#{CONFIG.keys.join('|')}) .+/ do |m| plugin.exec_search m end
end
CONFIG = Botpop::CONFIG['searchable'] || raise(MissingConfigurationZone, 'base')
ENABLED = CONFIG['enable'].nil? ? true : CONFIG['enable']
VALUES = CONFIG.values.map{|e|"!"+e}.join(', ')
KEYS = CONFIG.keys.map{|e|"!"+e}.join(', ')
HELP = CONFIG.keys.map{|e|"!"+e+" [search]"}
def self.exec_search m
msg = BotpopBuiltins.get_msg m
url = CONFIG[m.params[1..-1].join(' ').gsub(/\!([^ ]+) .+/, '\1')]
url = url.gsub('___MSG___', msg)
m.reply url
end
end
end