diff options
-rw-r--r-- | core/config.rb | 8 | ||||
-rw-r--r-- | core/store.rb | 8 | ||||
-rw-r--r-- | dinobot.rb | 23 | ||||
-rw-r--r-- | module/admin.rb | 6 | ||||
-rw-r--r-- | module/config.rb | 10 |
5 files changed, 36 insertions, 19 deletions
diff --git a/core/config.rb b/core/config.rb index 466e435..36511ed 100644 --- a/core/config.rb +++ b/core/config.rb @@ -20,6 +20,14 @@ module Dinobot end end + def [](key) + @data[key] + end + + def []=(key, value) + @data[key] = value + end + def save @store.save end diff --git a/core/store.rb b/core/store.rb index ba49733..5e1cf67 100644 --- a/core/store.rb +++ b/core/store.rb @@ -14,6 +14,14 @@ module Dinobot @data ||= Hash.new end + def [](key) + @data[key] + end + + def []=(key, value) + @data[key] = value + end + def read @store.transaction(true) do @data = @store[:data] @@ -98,16 +98,16 @@ module Dinobot end def add_alias(from, to) - @aliases.data[:global] = Hash.new unless @aliases.data[:global] + @aliases[:global] = Hash.new unless @aliases[:global] - @aliases.data[:global][from] = to + @aliases[:global][from] = to @aliases.save end def remove_alias(from) - return unless @aliases.data[:global] + return unless @aliases[:global] - @aliases.data[:global].delete(from) + @aliases[:global].delete(from) @aliases.save end @@ -134,10 +134,10 @@ module Dinobot m = Dinobot::Core::MessageInfo.new(user, channel, message) return unless message =~ - /\A#{Regexp.escape(@config.data[:trigger][:global])}/ + /\A#{Regexp.escape(@config[:trigger][:global])}/ command = message - .sub(/\A#{Regexp.escape(@config.data[:trigger][:global])}/, '') + .sub(/\A#{Regexp.escape(@config[:trigger][:global])}/, '') exec_command(m, command) process_response(m) if m.response? @@ -146,8 +146,8 @@ module Dinobot def exec_command(m, command) # FIXME: Improve and add debug output. - if @aliases.data[:global] - @aliases.data[:global].each do |k, v| + if @aliases[:global] + @aliases[:global].each do |k, v| command.sub!(/\A#{Regexp.escape(k)}\b/, v) end end @@ -159,11 +159,12 @@ module Dinobot mod = mod.intern if m.response? - prev = m.response + tmp = m.response m.response = [] - prev.each do |x| + tmp.each do |x| if x.first == :say + # FIXME: Retain original channel value? @modules[mod].call(m, "#{command} #{x[2]}") else m.respond x @@ -178,7 +179,7 @@ module Dinobot def process_response(m) m.response.each do |x| - @logger.info "Executing method: #{x.inspect}" if @config.data[:debug] + @logger.info "Executing method: #{x.inspect}" if @config[:debug] send(*x) end end diff --git a/module/admin.rb b/module/admin.rb index f26a652..957be7d 100644 --- a/module/admin.rb +++ b/module/admin.rb @@ -12,21 +12,21 @@ module Dinobot @commands << :join << :part << :quit << :load << :unload @commands << :listadmins << :listmodules << :listchannels - @admins = @store.data[:admins] + @admins = @store[:admins] @admins ||= Array.new end def add(user) @admins << user unless @admins.include?(user) - @store.data[:admins] = @admins + @store[:admins] = @admins @store.save end def remove(user) @admins.delete(user) - @store.data[:admins] = @admins + @store[:admins] = @admins @store.save end diff --git a/module/config.rb b/module/config.rb index cf71bd4..0082260 100644 --- a/module/config.rb +++ b/module/config.rb @@ -17,9 +17,9 @@ module Dinobot case args when 'trigger' - m.respond [:say, m.channel, @config.data[:trigger][:global]] + m.respond [:say, m.channel, @config[:trigger][:global]] when 'debug' - m.respond [:say, m.channel, @config.data[:debug].to_s] + m.respond [:say, m.channel, @config[:debug].to_s] end end @@ -31,15 +31,15 @@ module Dinobot case key when 'trigger' - @config.data[:trigger][:global] = val + @config[:trigger][:global] = val @config.save when 'debug' case val when 'true' - @config.data[:debug] = true + @config[:debug] = true @config.save when 'false' - @config.data[:debug] = false + @config[:debug] = false @config.save end end |