From fbff2860e9ba2e11794ec627db224d92b16a8c4d Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 21 Apr 2014 06:51:06 -0700 Subject: Add configuration interface module. --- module/config.rb | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 module/config.rb (limited to 'module') diff --git a/module/config.rb b/module/config.rb new file mode 100644 index 0000000..2bf8b0b --- /dev/null +++ b/module/config.rb @@ -0,0 +1,53 @@ +require_relative 'base' +require_relative '../core/config' + +module Dinobot + module Module + class Config < Base + def initialize(bot) + super + + @config = Dinobot::Core::Config.instance + + @commands << :get << :set + end + + def get(user, channel, argument) + return unless @bot.modules[:admin].is_admin?(user) + + case argument + when 'trigger' + [[:say, channel, @config.data[:trigger][:global]]] + when 'debug' + [[:say, channel, @config.data[:debug].to_s]] + else + nil + end + end + + def set(user, channel, argument) + return unless @bot.modules[:admin].is_admin?(user) + + key, val = argument.split(' ') + return unless val + + case key + when 'trigger' + @config.data[:trigger][:global] = val + @config.save + when 'debug' + case val + when 'true' + @config.data[:debug] = true + @config.save + when 'false' + @config.data[:debug] = false + @config.save + end + end + + nil + end + end + end +end -- cgit v1.2.3-70-g09d2