]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
[webservice] expose webservice to plugins
authorM. Hecker <apoc@sixserv.org>
Wed, 3 Sep 2014 13:47:30 +0000 (15:47 +0200)
committerM. Hecker <apoc@sixserv.org>
Wed, 3 Sep 2014 13:47:30 +0000 (15:47 +0200)
lib/rbot/core/webservice.rb
lib/rbot/ircbot.rb

index 21acf87d0d3623d36cd3b5776fb9094386dae2a4..26465285f65b5d476112c1a41ffa0310cdc76fe7 100644 (file)
@@ -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
index f74b1530cd51f8d1a1d4fcd0f525cad7b2eed8f5..18b9e1d4ac35ff2e05e5b47d226e6a6e9b26b1f7 100644 (file)
@@ -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