diff options
-rw-r--r-- | admin.rb | 37 | ||||
-rw-r--r-- | dinobot.rb | 4 | ||||
-rw-r--r-- | module.rb | 4 | ||||
-rw-r--r-- | test.rb | 2 |
4 files changed, 36 insertions, 11 deletions
@@ -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 @@ -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 @@ -2,7 +2,9 @@ module Dinobot class Module attr_accessor :commands - def initialize + def initialize(bot) + @bot = bot + @commands = [:commands] end @@ -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 |