From aadd43f69f0235234f072becb7cee7cb119bcd51 Mon Sep 17 00:00:00 2001 From: Marrub Date: Wed, 9 Aug 2017 03:52:34 -0400 Subject: [PATCH] Add per-module configurations --- source/main.rb | 17 +++++++++++------ source/mod_base.rb | 5 +++-- source/mod_discord.rb | 2 +- source/mod_fun.rb | 11 +++++------ source/mod_util.rb | 2 +- source/module.rb | 3 ++- source/server.rb | 4 ++-- 7 files changed, 25 insertions(+), 19 deletions(-) diff --git a/source/main.rb b/source/main.rb index 6e8969e..d80ae2e 100644 --- a/source/main.rb +++ b/source/main.rb @@ -35,22 +35,27 @@ module Vrobot4 log :INFO, "vrobot version", Version - begin; cfg = YAML.load IO.read(cfgname) - rescue; log :ERROR, "error reading bot config:", $!; exit; end + begin + cfg = YAML.load IO.read(cfgname) + rescue + log :ERROR, "error reading bot config:", $! + return + end Vrobot4.debug = cfg["debug"] if cfg.key? "debug" - cfg["loadmods"].each {|mod| load mod, true} begin bots = [] cfg["bots"].each {|botinfo| bots << loadBot(botinfo)} log :DEBUGV, "bots:", bots.to_s - runBots bots rescue - log :ERROR, "error loading bot config:", $! - exit + log :ERROR, "error loading bot config:", + $!.to_s + "\n" + $!.backtrace.first(3).join("\n") + return end + + runBots bots end end diff --git a/source/mod_base.rb b/source/mod_base.rb index c89b8dd..a80a4d1 100644 --- a/source/mod_base.rb +++ b/source/mod_base.rb @@ -1,6 +1,6 @@ module Vrobot4::Server class Mod_Base < Vrobot4::Module::Module - def initialize + def initialize info super register :c_help, "help", "Prints documentation for commands." register :c_die, "die", "Kills all bot instances.", roles: "o" @@ -37,7 +37,8 @@ module Vrobot4::Server "bye", "dedededed", "Thanks, bye!", - "GOTTAGOBYE"].sample + "GOTTAGOBYE", + "the orks insisted upon dying"].sample exit end diff --git a/source/mod_discord.rb b/source/mod_discord.rb index 7c1c17b..bf4dbd0 100644 --- a/source/mod_discord.rb +++ b/source/mod_discord.rb @@ -1,7 +1,7 @@ class Mod_Discord < Vrobot4::Module::Module Vrobot4::Module.add_module_type self, "Discord", server: "Discord" - def initialize + def initialize info super register :c_roles, "roles", "Gets a list of roles on your user." register :c_purge, "purge", "Prunes messages from a channel.", roles: "o" diff --git a/source/mod_fun.rb b/source/mod_fun.rb index 343473a..be721aa 100644 --- a/source/mod_fun.rb +++ b/source/mod_fun.rb @@ -4,9 +4,9 @@ require 'json' class Mod_Fun < Vrobot4::Module::Module Vrobot4::Module.add_module_type self, "Fun" - Qdb = "http://greyserv.net/qdb" + QDB = "http://greyserv.net/qdb" - def initialize + def initialize info super register :c_carmack, "carmack", "mmmmmmmmmm" register :c_revenant, "revenant", "AAAAAAAAA" @@ -59,11 +59,10 @@ class Mod_Fun < Vrobot4::Module::Module def c_quote m, argv check_args argv, "", "N" if argv.length == 0 - res = open(Qdb + "/interface.cgi").read - max = JSON.parse(res)["numQuotes"] - 1 - m.reply_b open(Qdb + "/q/" + (rand(max) + 1).to_s).read + max = JSON.parse(open(QDB + "/interface.cgi").read)["numQuotes"] - 1 + m.reply_b open(QDB + "/q/" + (rand(max) + 1).to_s).read else - m.reply_b open(Qdb + "/q/" + argv[0].to_i.to_s).read + m.reply_b open(QDB + "/q/" + argv[0].to_i.to_s).read end end diff --git a/source/mod_util.rb b/source/mod_util.rb index 2b6ef6b..7896fab 100644 --- a/source/mod_util.rb +++ b/source/mod_util.rb @@ -1,7 +1,7 @@ class Mod_Util < Vrobot4::Module::Module Vrobot4::Module.add_module_type self, "Utilities" - def initialize + def initialize info super register :c_rand, "rand", "Returns a random number. Example: .rand 500" register :c_decide, "decide", "Decides between one or more choices." diff --git a/source/module.rb b/source/module.rb index cd6f4b6..d90e0c1 100644 --- a/source/module.rb +++ b/source/module.rb @@ -27,8 +27,9 @@ module Vrobot4::Module end class Module - def initialize + def initialize info @commands = {} + @info = info Vrobot4.log :DEBUG, "initialized", self.to_s end diff --git a/source/server.rb b/source/server.rb index 40e41aa..2bbf701 100644 --- a/source/server.rb +++ b/source/server.rb @@ -35,7 +35,7 @@ module Vrobot4::Server def initialize info @info = info - @modules = [Mod_Base.new] + @modules = [Mod_Base.new(nil)] load_permissions info["permissions"] if info.key? "permissions" end @@ -45,7 +45,7 @@ module Vrobot4::Server mt[:servflags] and mt[:servflags] !~ flags raise ArgumentError, "Module " + mod + " not valid for this server" end - @modules << mt[:type].new + @modules << mt[:type].new(@info.key?(mod) ? @info[mod] : nil) end def drop_mod mod