From 51c9d0fdd5726d68830a91c7c89fddf5181ec517 Mon Sep 17 00:00:00 2001 From: Marrub Date: Sun, 6 Aug 2017 19:30:24 -0400 Subject: [PATCH] Leave server implementations to determine commands --- source/mod_util.rb | 4 ++-- source/module.rb | 8 ++++---- source/server.rb | 16 +++++----------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/source/mod_util.rb b/source/mod_util.rb index 8da430b..dd36d01 100644 --- a/source/mod_util.rb +++ b/source/mod_util.rb @@ -6,8 +6,8 @@ class Mod_Util < Vrobot4::Module::Module register :testf, "Test function." end - def testf msg, argv - puts "test function run", msg, argv + def testf m, argv + puts "test function run", m, argv end end diff --git a/source/module.rb b/source/module.rb index 435f9ed..9372dcd 100644 --- a/source/module.rb +++ b/source/module.rb @@ -7,8 +7,8 @@ module Vrobot4::Module @help_str = help end - def run msg, argv - @function.call(msg, argv) + def run m, argv + @function.call(m, argv) end end @@ -25,8 +25,8 @@ module Vrobot4::Module @commands.each {|cmd| yield cmd} end - def onCommand msg, cmdname, argv - @commands[cmdname].run(msg, argv) if @commands.has_key? cmdname + def onCommand m, cnam, argv + @commands[cnam].run(m, argv) if @commands.has_key? cnam end end diff --git a/source/server.rb b/source/server.rb index 94886c3..bb61866 100644 --- a/source/server.rb +++ b/source/server.rb @@ -8,10 +8,6 @@ module Vrobot4::Server def initialize msg @msg = msg end - - def to_s - @msg - end end class Channel @@ -26,15 +22,13 @@ module Vrobot4::Server @modules << mod end - def onMessage msg - if msg.start_with? '.' - onCommand msg, nil, nil - end - log :MSG, msg.to_s + def onMessage m + Vrobot4.log :DEBUG, "message:", m.to_s end - def onCommand msg, cmdname, argv - @modules.each {|mod| mod.onCommand msg, cmdname, argv} + def onCommand m, cnam, argv + Vrobot4.log :DEBUG, "command:", m.to_s, cnam.to_s, argv.to_s + @modules.each {|mod| mod.onCommand m, cnam, argv} end end