From 391470c936779378b2441db52376f5b588d04070 Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Fri, 19 Nov 2021 18:18:09 -0600 Subject: [PATCH] Major refactor to main bot body, now not asinine, has globals. Still working on bangs :^) --- Emery.rb | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/Emery.rb b/Emery.rb index ccb1509..804b7f3 100755 --- a/Emery.rb +++ b/Emery.rb @@ -4,25 +4,48 @@ require 'discordrb' require 'tmpdir' token = File.read("token.txt") -bot = Discordrb::Bot.new token: "#{token}" +$bot = Discordrb::Bot.new token: "#{token}" bang = '!' -def loadCommands(bot, bang) +def emery_loadModules() + $commands = {} File.foreach("modules/modules.txt", chop: true) { |line| - mod = "./modules/" + line + "/main.rb" - code = "defined? #{line.delete("\n")}_initialize" - if eval(code) == nil - load mod.delete("\n") - send("#{line.delete("\n")}_initialize", bot, bang) - else + 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") + $commands[name] = command + else + puts "Load error!" + end end } end + $queue = {} -loadCommands(bot, bang) +$voicebots = {} +$commands = {} +$bang = '!' +emery_loadModules() + +$bot.message() do |event| + message = event.content + server = event.server + author = event.author + if message.start_with?('!') + message = message.sub("!", '') + if $commands.key?(message.split.first.downcase) + send("#{$commands[message.split.first.downcase]}", event) + end + end +end + #require './pingcommand.rb' #main(bot) #tomlTest() -bot.run \ No newline at end of file +$bot.run \ No newline at end of file