From ab93b4cacfb71fc5de25be245ad7d8092de2131b Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 14 Apr 2014 23:23:53 -0700 Subject: Minor bug fixes and improved admin module. --- admin.rb | 37 ++++++++++++++++++++++++++++++------- dinobot.rb | 4 ++-- module.rb | 4 +++- test.rb | 2 +- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/admin.rb b/admin.rb index fceaa26..3cffd1f 100644 --- a/admin.rb +++ b/admin.rb @@ -2,10 +2,11 @@ require_relative 'module' module Dinobot class Admin < Module - def initialize + def initialize(bot) super - @commands << :join << :part << :listadmins << :load << :unload + @commands << :join << :part << :load << :unload + @commands << :listadmins << :listmodules << :listchannels @admins = Array.new end @@ -24,27 +25,49 @@ module Dinobot end def join(user, channel, argument) - [[:join, argument]] if is_admin?(user) + return unless is_admin?(user) + + [[:join, argument.strip]] end def part(user, channel, argument) - [[:part, argument]] if is_admin?(user) + return unless is_admin?(user) + + [[:part, argument.strip]] end def listadmins(user, channel, argument) - [[:say, channel, @admins.join(' ')]] if is_admin?(user) + return unless is_admin?(user) + + [[:say, channel, @admins.join(' ')]] end def load(user, channel, argument) return unless is_admin?(user) - argument.split.map { |x| [:load_module, x.intern] } + argument.split.each do |x| + @bot.load_module x.intern + end end def unload(user, channel, argument) return unless is_admin?(user) - argument.split.map { |x| [:unload_module, x.intern] } + argument.split.each do |x| + @bot.unload_module x.intern + end + end + + def listmodules(user, channel, argument) + return unless is_admin?(user) + + [[:say, channel, "Modules: #{@bot.modules.keys.sort.join(' ')}"]] + end + + def listchannels(user, channel, argument) + return unless is_admin?(user) + + [[:say, channel, "Channels: #{@bot.channels.sort.join(' ')}"]] end end end diff --git a/dinobot.rb b/dinobot.rb index 09964ef..c62771b 100644 --- a/dinobot.rb +++ b/dinobot.rb @@ -106,7 +106,7 @@ module Dinobot case method.first when :say send(*method) if method.length == 3 - when :join, :part, :load_module, :unload_module + when :join, :part send(*method) if method.length == 2 end end @@ -144,7 +144,7 @@ module Dinobot load "#{mod}.rb" m = Dinobot.const_get(Dinobot.constants.find { |x| x.downcase == mod }) - @modules[mod] = m.new + @modules[mod] = m.new(self) puts "== Loaded module: #{mod} (#{m})" rescue LoadError, StandardError => e diff --git a/module.rb b/module.rb index c031a7b..192aea4 100644 --- a/module.rb +++ b/module.rb @@ -2,7 +2,9 @@ module Dinobot class Module attr_accessor :commands - def initialize + def initialize(bot) + @bot = bot + @commands = [:commands] end diff --git a/test.rb b/test.rb index 735af2c..a3a5a9a 100644 --- a/test.rb +++ b/test.rb @@ -2,7 +2,7 @@ require_relative 'module' module Dinobot class Test < Module - def initialize + def initialize(bot) super @commands << :echo << :error << :timeout << :x3 << :wrongreturn << :fooify -- cgit v1.2.3-70-g09d2