From: M. Hecker Date: Wed, 3 Sep 2014 13:47:30 +0000 (+0200) Subject: [webservice] expose webservice to plugins X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=53cfadbb9f2b25efe4c22b2fd02f8bc33b5e9d2d;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git [webservice] expose webservice to plugins --- diff --git a/lib/rbot/core/webservice.rb b/lib/rbot/core/webservice.rb index 21acf87d..26465285 100644 --- a/lib/rbot/core/webservice.rb +++ b/lib/rbot/core/webservice.rb @@ -69,7 +69,12 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet botuser = @bot.auth.get_botuser(username) raise 'Permission Denied' if not botuser or botuser.password != password - ret = dispatch_command(command, botuser, ip) + begin + ret = dispatch_command(command, botuser, ip) + rescue + debug '[webservice] error: ' + $!.to_s + debug $@.join("\n") + end res.status = 200 if req['Accept'] == 'application/json' @@ -119,6 +124,7 @@ class WebServiceModule < CoreBotModule @port = @bot.config['webservice.port'] @host = @bot.config['webservice.host'] @server = nil + @bot.webservice = self begin start_service if @bot.config['webservice.autostart'] rescue => e @@ -184,6 +190,10 @@ class WebServiceModule < CoreBotModule m.reply s end + def register_servlet(plugin, servlet) + @server.mount('/plugin/%s' % plugin.name, servlet, plugin, @bot) + end + end webservice = WebServiceModule.new diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index f74b1530..18b9e1d4 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -202,6 +202,8 @@ class Bot # loads and opens new registry databases, used by the plugins attr_accessor :registry_factory + attr_accessor :webservice + # server we are connected to # TODO multiserver def server