From bea9003ea8f96563d1cb9b75c0033cf66fd401dd Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Sat, 20 Nov 2021 17:56:29 -0600 Subject: [PATCH] New command handler format. Less janky. --- Emery.rb | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/Emery.rb b/Emery.rb index 804b7f3..a4e0c03 100755 --- a/Emery.rb +++ b/Emery.rb @@ -3,33 +3,34 @@ require 'discordrb' require 'tmpdir' -token = File.read("token.txt") -$bot = Discordrb::Bot.new token: "#{token}" -bang = '!' - def emery_loadModules() $commands = {} + # Yes this gets redefined. Why? Because I like having all my variables in one place but it also needs to be cleared again File.foreach("modules/modules.txt", chop: true) { |line| - mod = "./modules/" + line.delete("\n") + "/main.rb" - mod2 = line.delete("\n") - if(File.exist?(mod)) - load mod.delete("\n") - if eval("defined? " + "#{mod2}_getName") == "method" - puts "Load success!" - name = send("#{mod2}_getName") - command = send("#{line.delete("\n")}_getCommand") + # For every line in the file, do below + modPath = "./modules/" + line.delete("\n") + "/main.rb" + mod = line.delete("\n") + if(File.exist?(modPath)) + puts "Load success in #{mod}!" + load modPath + if eval("defined? " + "#{mod}_getCommand") == "method" + name, command = send("#{mod}_getCommand") $commands[name] = command else - puts "Load error!" + puts "Load error in #{mod}!" end end } end +token = File.read("token.txt") +$bot = Discordrb::Bot.new token: "#{token}" $queue = {} $voicebots = {} $commands = {} $bang = '!' +#find a way for this to be server-specific with a fallback option + emery_loadModules() $bot.message() do |event| @@ -44,8 +45,4 @@ $bot.message() do |event| end end -#require './pingcommand.rb' - -#main(bot) -#tomlTest() $bot.run \ No newline at end of file