From 949e762b5822c653f7935ff29347733b0e092ab1 Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Tue, 10 Aug 2021 20:45:35 -0500 Subject: [PATCH] added live mode switching remotely. --- API/tools.lua | 5 +++-- bot.lua | 16 +++++++++----- commands/complexCommands.lua | 43 ++++++++++++++++++++++++++++++++++++ docs/mode.lua | 2 ++ docs/reinitialize.lua | 1 + docs/testmode.lua | 1 - 6 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 docs/mode.lua create mode 100644 docs/reinitialize.lua delete mode 100644 docs/testmode.lua diff --git a/API/tools.lua b/API/tools.lua index b129bf1..ddf031f 100644 --- a/API/tools.lua +++ b/API/tools.lua @@ -32,10 +32,11 @@ end --Reads testmode.lua function tools.testModeDetection() - return dofile("./docs/testmode.lua") + local mode = dofile("./docs/mode.lua") + if mode == "normal" then return false end + if mode == "test" then return true end end --- --Reads an entire file, outputs as string. function tools.printFile(file) diff --git a/bot.lua b/bot.lua index 5e5d328..b91dfca 100644 --- a/bot.lua +++ b/bot.lua @@ -9,7 +9,7 @@ client:once("ready", function() print('Logged in as '.. client.user.username) Commands = Tools.initialize() if Tools.testModeDetection() == true then - mode = "testMode" + mode = "test" else mode = "normal" end @@ -20,20 +20,24 @@ client:on('messageCreate', function(message) if message.author.bot then return end local shouldReinit = false if Tools.testModeDetection() == true and mode == "normal" then - mode = "testMode" + mode = "test" shouldReinit = true - elseif Tools.testModeDetection() == false and mode == "testMode" then + elseif Tools.testModeDetection() == false and mode == "test" then mode = "normal" shouldReinit = false end - if mode == "testMode" then + if mode == "test" then shouldReinit = true end + if dofile("./docs/reinitialize.lua") == true then + Commands = Tools.initialize() + Tools = dofile("./API/tools.lua") + end if mode == "normal" and Tools.messageDectection(message, "reinitialize") == true then p("reinitd at "..os.time()) reinitialize(message) - elseif mode == "testMode" and Tools.messageDectection(message, "reinitialize") == true then - message:reply("You cannot preform this command because testMode is on!") + elseif mode == "test" and Tools.messageDectection(message, "reinitialize") == true then + message:reply("You cannot preform this command because test is on!") p("Not reinitd at "..os.time()) end local args = message.content:split(" ") diff --git a/commands/complexCommands.lua b/commands/complexCommands.lua index 3f3da99..9a81351 100644 --- a/commands/complexCommands.lua +++ b/commands/complexCommands.lua @@ -73,6 +73,49 @@ end end }; +[prefix..'mode'] = { -- Echo's what you said back out, in a fix codeblock. Could be against TOS. + exec = function (message, arg) + local user = message.guild:getMember(message.author.id) + if not user:hasPermission("administrator") then + message:reply("You cannot change the mode of this bot!") + else + file = io.open("./docs/mode.lua", "r+") + io.input(file) + io.output(file) + if tools.testModeDetection() == true then + mode = "test" + else + mode = "normal" + end + if not arg[2] then message.channel:send("```fix\nNo argument. Get or Set?```") return end + if arg[2] ~= "get" and arg[2] ~= "set" then message.channel:send("```fix\nMalformed input, you put in '"..arg[2].."' not get or set.```") return end + if arg[2] == "get" then message.channel:send("```fix\nCurrent mode is '"..mode.."'```") return end + if arg[2] == "set" then + if arg[3] == "normal" then + message.channel:send("```fix\nSet mode 'normal'```") + file:seek("set", 0) + file:write("return 'normal'") + elseif arg[3] == "test" then + message.channel:send("```fix\nset mode 'test'```") + file:seek("set", 0) + file:write("return 'test' \n") + elseif arg[3] ~= "normal" or "test" then + message.channel:send("```fix\nIncorrect mode, please enter 'normal' or 'test'```") + end + io.close() + file = io.open("./docs/reinitialize.lua", "r+") + io.input(file) + io.output(file) + file:seek("set", 0) + file:write("return true ") + end + io.close() + --message.channel:send() + --message:delete() + end +end +}; + } function complexCommands.initialize() diff --git a/docs/mode.lua b/docs/mode.lua new file mode 100644 index 0000000..8550db4 --- /dev/null +++ b/docs/mode.lua @@ -0,0 +1,2 @@ +return 'normal' +--normal or test \ No newline at end of file diff --git a/docs/reinitialize.lua b/docs/reinitialize.lua new file mode 100644 index 0000000..5ecbcf7 --- /dev/null +++ b/docs/reinitialize.lua @@ -0,0 +1 @@ +return true \ No newline at end of file diff --git a/docs/testmode.lua b/docs/testmode.lua deleted file mode 100644 index 1bae4d4..0000000 --- a/docs/testmode.lua +++ /dev/null @@ -1 +0,0 @@ -return false \ No newline at end of file