From 958fd1d184d7a00172d91c39fb3648c864a5aece Mon Sep 17 00:00:00 2001 From: Astoria Floyd <39976417+AstoriaFloyd@users.noreply.github.com> Date: Tue, 10 Aug 2021 20:56:03 -0500 Subject: [PATCH 1/7] Update key.lua --- docs/key.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/key.lua b/docs/key.lua index 52fb600..37c7a5b 100644 --- a/docs/key.lua +++ b/docs/key.lua @@ -1,6 +1,6 @@ --Litterally just the prefix right now -return "exp!" +return "" -- This project is libre, and licenced under the terms of the -- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENCE, version 3.1, -- as published by dtf on July 2019. See the COPYING file or --- https://ph.dtf.wtf/w/wtfpl/#version-3-1 for more details. \ No newline at end of file +-- https://ph.dtf.wtf/w/wtfpl/#version-3-1 for more details. -- 2.43.0 From e2a7718269ec3a1fd3bb7df24438c5a7719efe58 Mon Sep 17 00:00:00 2001 From: Astoria Floyd <39976417+AstoriaFloyd@users.noreply.github.com> Date: Tue, 10 Aug 2021 21:07:14 -0500 Subject: [PATCH 2/7] Update reinitialize.lua --- docs/reinitialize.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reinitialize.lua b/docs/reinitialize.lua index 5ecbcf7..585a20e 100644 --- a/docs/reinitialize.lua +++ b/docs/reinitialize.lua @@ -1 +1 @@ -return true \ No newline at end of file +return false -- 2.43.0 From 209f1207a5c3eaeb1b5c5fa24545dd7657767121 Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Wed, 11 Aug 2021 14:47:39 -0500 Subject: [PATCH 3/7] Added yet more mode switching, cleaned up code, made userBan work in any guild --- .gitignore | 2 ++ API/tools.lua | 66 +++++++++++++++++++++++++++++++----- bot.lua | 54 ++++++++--------------------- commands/complexCommands.lua | 37 +++++--------------- docs/mode.lua | 3 +- docs/reinitialize.lua | 2 +- 6 files changed, 84 insertions(+), 80 deletions(-) diff --git a/.gitignore b/.gitignore index ca88548..4e9a7db 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ token.lua launch.json .vscode interpreter.lua +docs/reinitialize.lua +docs/mode.lua diff --git a/API/tools.lua b/API/tools.lua index 5e15c77..45ce30d 100644 --- a/API/tools.lua +++ b/API/tools.lua @@ -1,6 +1,5 @@ ---@diagnostic disable: undefined-global local tools = {} - --initializes or re-initializes the seed of RNG, based on Unix Time. function tools.seed() local seed = os.time() @@ -9,15 +8,14 @@ end --Initializes commands. function tools.initialize() - if tools.testModeDetection() == false then + if tools.getMode() == "normal" then local simpleCommands = dofile("./commands/simpleCommands.lua") local complexCommands = dofile("./commands/complexCommands.lua") local complexCommands = complexCommands.initialize() local simpleCommands = simpleCommands.initialize() local commands = tools.tableMerge(simpleCommands, complexCommands) return commands - end - if tools.testModeDetection() == true then + elseif tools.getMode() == "test" then local simpleCommands = dofile("./commands/simpleCommands.lua") local complexCommands = dofile("./commands/complexCommands.lua") local experimentalCommands = dofile("./commands/experimentalCommands.lua") @@ -27,16 +25,66 @@ function tools.initialize() local commandsP1 = tools.tableMerge(simpleCommands, complexCommands) local commands = tools.tableMerge(commandsP1, experimentalCommands) return commands + else + local simpleCommands = dofile("./commands/simpleCommands.lua") + local complexCommands = dofile("./commands/complexCommands.lua") + local complexCommands = complexCommands.initialize() + local simpleCommands = simpleCommands.initialize() + local commands = tools.tableMerge(simpleCommands, complexCommands) + return commands end end ---Reads testmode.lua -function tools.testModeDetection() - local mode = dofile("./docs/mode.lua") - if mode == "normal" then return false end - if mode == "test" then return true end +--Sets mode.lua +function tools.setMode(mode) + local file = io.open("./docs/mode.lua", "r+") + io.input(file) + io.output(file) + file:seek("set", 7) + if mode == "test" then + file:write("'test' ") + elseif mode == "normal" then + file:write("'normal'") + else + --Default to normal + file:write("'normal'") + end + file:close() +end + +function tools.getMode() + local file = io.open("./docs/mode.lua", "r") + io.input(file) + file:seek("set", 7) + local mode = file:read() + file:close() + mode = mode:gsub("%s+", "") + mode = mode:gsub("'", "") + return mode end +--Sets if we should reinitialize. +function tools.setReinit(reinit) + local reinitFile = io.open("./docs/reinitialize.lua", "r+") + io.input(reinitFile) + io.output(reinitFile) + reinitFile:seek("set", 7) + if type(reinit) == "boolean" then + if reinit == true then + reinitFile:write("true ") + elseif reinit == false then + reinitFile:write("false") + end + else + --default to no + reinitFile:write("return false") + end + reinitFile:close() +end + +function tools.getReinit() + return dofile("./docs/reinitialize.lua") +end --Reads an entire file, outputs as string. function tools.printFile(file) diff --git a/bot.lua b/bot.lua index b91dfca..f9b8893 100644 --- a/bot.lua +++ b/bot.lua @@ -8,49 +8,33 @@ client:once("ready", function() client:setGame("Astoria's bot, very sad!") print('Logged in as '.. client.user.username) Commands = Tools.initialize() - if Tools.testModeDetection() == true then - mode = "test" - else - mode = "normal" - end + mode = Tools.getMode() end) --Command handler client:on('messageCreate', function(message) if message.author.bot then return end - local shouldReinit = false - if Tools.testModeDetection() == true and mode == "normal" then - mode = "test" - shouldReinit = true - elseif Tools.testModeDetection() == false and mode == "test" then - mode = "normal" - shouldReinit = false - end + mode = Tools.getMode() if mode == "test" then - shouldReinit = true + Tools.setReinit(true) end - if dofile("./docs/reinitialize.lua") == true then - Commands = Tools.initialize() - Tools = dofile("./API/tools.lua") + if mode == "normal" and Tools.getReinit() == false then + Tools.setReinit(false) end if mode == "normal" and Tools.messageDectection(message, "reinitialize") == true then - p("reinitd at "..os.time()) - reinitialize(message) + reinitialize() 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 + if Tools.getReinit() == true then + Commands = Tools.initialize() + Tools = dofile("./API/tools.lua") + Tools.setReinit(false) end local args = message.content:split(" ") local lowerArgs = args[1]:lower() local command = Commands[lowerArgs] if command then - if shouldReinit == true then - Commands = Tools.initialize() - Tools = dofile("./API/tools.lua") - command = Commands[lowerArgs] - p("reinitd at "..os.time()) - shouldReinit = false - end command.exec(message, args) end end) @@ -61,26 +45,16 @@ function reinitialize(message) if not user:hasPermission("administrator") then message:reply("You cannot re-initialize this bot!") else - Commands = Tools.initialize() - Tools = dofile("./API/tools.lua") + Tools.setReinit(true) message:reply("Re-Initialized!") end end end -function selfReinitialize() - Commands = Tools.initialize() - Tools = dofile("./API/tools.lua") -end --When a user is banned, post a lenney. -client:on('userBan', function() - local banChannel, err = client:getChannel("872283716486066200") - if not banChannel then - p("Attempt to fetch the channel object: ", err) - return - end - banChannel:send("User was banned ( ͡° ͜ʖ ͡°)") +client:on('userBan', function(user, guild) + guild.systemChannel:send("A user was banned ( ͡° ͜ʖ ͡°)") end) --Insert Token in a .lua file with simply returns it as a string. diff --git a/commands/complexCommands.lua b/commands/complexCommands.lua index 7789114..57892f1 100644 --- a/commands/complexCommands.lua +++ b/commands/complexCommands.lua @@ -2,11 +2,12 @@ local tools = dofile("./API/tools.lua") local rng = dofile("./API/rng.lua") local complexCommands = {} local prefix = dofile("./docs/key.lua") +local mode = tools.getMode() local commands = { -- Define commands its a table that will contain our commands [prefix..'helpme'] = { -- Dumps docs/help to chat, took me forever to figure out. exec = function (message) - if tools.testModeDetection() == true then + if mode == "test" then message.channel:send(tools.printFile("docs/helpTestMode")) else message.channel:send(tools.printFile("docs/help")) @@ -78,39 +79,19 @@ end 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] == "get" then mode = tools.getMode() 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 + if arg[3] == "normal" or "test" then + mode = tostring(arg[3]) + message.channel:send("```fix\nSet mode '"..mode.."'```") + tools.setMode(mode) + tools.setReinit(true) + else 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 }; diff --git a/docs/mode.lua b/docs/mode.lua index 8550db4..8f2e6d5 100644 --- a/docs/mode.lua +++ b/docs/mode.lua @@ -1,2 +1 @@ -return 'normal' ---normal or test \ No newline at end of file +return 'normal' \ No newline at end of file diff --git a/docs/reinitialize.lua b/docs/reinitialize.lua index 5ecbcf7..1bae4d4 100644 --- a/docs/reinitialize.lua +++ b/docs/reinitialize.lua @@ -1 +1 @@ -return true \ No newline at end of file +return false \ No newline at end of file -- 2.43.0 From 4ea3e9b419fe7f063057e0270a684d13cbb904d0 Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Wed, 11 Aug 2021 16:47:38 -0500 Subject: [PATCH 4/7] correct mode to Mode --- bot.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bot.lua b/bot.lua index f9b8893..c922bcc 100644 --- a/bot.lua +++ b/bot.lua @@ -8,22 +8,22 @@ client:once("ready", function() client:setGame("Astoria's bot, very sad!") print('Logged in as '.. client.user.username) Commands = Tools.initialize() - mode = Tools.getMode() + Mode = Tools.getMode() end) --Command handler client:on('messageCreate', function(message) if message.author.bot then return end - mode = Tools.getMode() - if mode == "test" then + Mode = Tools.getMode() + if Mode == "test" then Tools.setReinit(true) end - if mode == "normal" and Tools.getReinit() == false then + if Mode == "normal" and Tools.getReinit() == false then Tools.setReinit(false) end - if mode == "normal" and Tools.messageDectection(message, "reinitialize") == true then + if Mode == "normal" and Tools.messageDectection(message, "reinitialize") == true then reinitialize() - elseif mode == "test" and Tools.messageDectection(message, "reinitialize") == true then + elseif Mode == "test" and Tools.messageDectection(message, "reinitialize") == true then message:reply("You cannot preform this command because test is on!") end if Tools.getReinit() == true then @@ -39,6 +39,7 @@ client:on('messageCreate', function(message) end end) +---@diagnostic disable-next-line: lowercase-global function reinitialize(message) local user = message.guild:getMember(message.author.id) if Tools.messageDectection(message, "reinitialize") == true then -- 2.43.0 From fa7ef45d9ff8621c80218ea835aaea6004fde8f4 Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Wed, 11 Aug 2021 17:30:07 -0500 Subject: [PATCH 5/7] Cleaned up unessesary garbage --- API/tools.lua | 1 - bot.lua | 1 - 2 files changed, 2 deletions(-) diff --git a/API/tools.lua b/API/tools.lua index 45ce30d..d40f2a7 100644 --- a/API/tools.lua +++ b/API/tools.lua @@ -1,4 +1,3 @@ ----@diagnostic disable: undefined-global local tools = {} --initializes or re-initializes the seed of RNG, based on Unix Time. function tools.seed() diff --git a/bot.lua b/bot.lua index c922bcc..1fb5810 100644 --- a/bot.lua +++ b/bot.lua @@ -39,7 +39,6 @@ client:on('messageCreate', function(message) end end) ----@diagnostic disable-next-line: lowercase-global function reinitialize(message) local user = message.guild:getMember(message.author.id) if Tools.messageDectection(message, "reinitialize") == true then -- 2.43.0 From 9b3b1425a105dae0c453c6227aea04e5e227a668 Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Wed, 11 Aug 2021 17:32:56 -0500 Subject: [PATCH 6/7] fixed missing test --- docs/mode.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/mode.lua b/docs/mode.lua index 8f2e6d5..da80feb 100644 --- a/docs/mode.lua +++ b/docs/mode.lua @@ -1 +1,2 @@ -return 'normal' \ No newline at end of file +return 'normal' +--normal or test \ No newline at end of file -- 2.43.0 From fb681c72835931a1a23bd4558373573c94431481 Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Wed, 11 Aug 2021 17:35:21 -0500 Subject: [PATCH 7/7] Changing constantly. --- .gitignore | 1 + docs/reinitialize.lua | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4e9a7db..bc2e6f1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ launch.json interpreter.lua docs/reinitialize.lua docs/mode.lua +docs/reinitialize.lua diff --git a/docs/reinitialize.lua b/docs/reinitialize.lua index 1bae4d4..5ecbcf7 100644 --- a/docs/reinitialize.lua +++ b/docs/reinitialize.lua @@ -1 +1 @@ -return false \ No newline at end of file +return true \ No newline at end of file -- 2.43.0