diff --git a/src/bot.rb b/src/bot.rb index 8654978..56b38dc 100644 --- a/src/bot.rb +++ b/src/bot.rb @@ -27,7 +27,7 @@ class FrugalityBot @db = Database.new load_commands - setup_events + startup_bot end def run @@ -37,34 +37,22 @@ class FrugalityBot private def load_commands - # 1. We look for all .rb files in "src/commands/..." - comm_files = Dir[File.join(__dir__, 'commands', '*.rb')] - - comm_files.each do |file| - require file # We import the file - - # We convert filename to module name - # This mean that 'echo.rb' turns into 'Echo' - # 'server_info' would turn into 'ServerInfo' - filename = File.basename(file, '.rb') - module_name = filename.split('_').map(&:capitalize).join - - begin - comm_module = Commands.const_get(module_name) - - comm_module.register(@bot, @db) - puts "Loaded command: #{module_name}" - sleep(1.5) - rescue NameError => e - puts "Could not load #{filename}: Module 'Commands::#{module_name}' was not found." - rescue StandardError => e - puts "Error loading: #{filename}: #{e.message}" - end + Dir["#{File.dirname(__FILE__)}/commands/**/*.rb"].each do |file| + require file + end + + Commands.constants.each do |const| + cmd = Commands.const_get(const) + + if cmd.is_a?(Module) && cmd.respond_to?(:register) + cmd.register(@bot, @db) + puts "Loaded command: #{const}" + sleep(1.5) + end end - puts "Commands loaded." end - def setup_events + def startup_bot @bot.ready do puts "#{@bot.profile.username} is online" @bot.update_status("online", "Checking the economy...", nil, 0, false, 0) diff --git a/src/commands/echo.rb b/src/commands/testing/echo.rb similarity index 100% rename from src/commands/echo.rb rename to src/commands/testing/echo.rb diff --git a/src/commands/embed.rb b/src/commands/testing/embed.rb similarity index 100% rename from src/commands/embed.rb rename to src/commands/testing/embed.rb diff --git a/src/commands/ping.rb b/src/commands/testing/ping.rb similarity index 100% rename from src/commands/ping.rb rename to src/commands/testing/ping.rb