From e848c6680415a16b0895ae7d568f31dcbd4d7742 Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Sun, 8 Aug 2021 19:00:32 -0500 Subject: [PATCH] ALSO BIG SECURITY HOLE --- API/tools.lua | 25 +++++++++++++++++------ bot.lua | 27 +++++++++++++++++++++---- commands/complexCommands.lua | 9 +++++++-- commands/experimentalCommands.lua | 29 +++++++++++++++++++++++++++ commands/simpleCommands.lua | 9 +-------- docs/helpTestMode | 33 +++++++++++++++++++++++++++++++ 6 files changed, 112 insertions(+), 20 deletions(-) create mode 100644 commands/experimentalCommands.lua create mode 100644 docs/helpTestMode diff --git a/API/tools.lua b/API/tools.lua index e3ecbe5..b129bf1 100644 --- a/API/tools.lua +++ b/API/tools.lua @@ -9,12 +9,25 @@ end --Initializes commands. function tools.initialize() - 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 + if tools.testModeDetection() == false 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 + local simpleCommands = dofile("./commands/simpleCommands.lua") + local complexCommands = dofile("./commands/complexCommands.lua") + local experimentalCommands = dofile("./commands/experimentalCommands.lua") + local simpleCommands = simpleCommands.initialize() + local complexCommands = complexCommands.initialize() + local experimentalCommands = experimentalCommands.initialize() + local commandsP1 = tools.tableMerge(simpleCommands, complexCommands) + local commands = tools.tableMerge(commandsP1, experimentalCommands) + return commands + end end --Reads testmode.lua diff --git a/bot.lua b/bot.lua index 12658fd..ba6588b 100644 --- a/bot.lua +++ b/bot.lua @@ -7,25 +7,39 @@ discordia.extensions() client:once("ready", function() client:setGame("Astoria's bot, very sad!") print('Logged in as '.. client.user.username) - Commands = Tools.initialize() + Commands = Tools.initialize() + if Tools.testModeDetection() == true then + mode = "testMode" + else + mode = "normal" + end end) --Command handler client:on('messageCreate', function(message) if message.author.bot then return end - if Tools.testModeDetection() == true then + if Tools.testModeDetection() == true and mode == "normal" then + mode = "testMode" + elseif Tools.testModeDetection() == false and mode == "testMode" then + mode = "normal" + selfReinitialize() + end + if mode == "testMode" then Commands = Tools.initialize() Tools = dofile("./API/tools.lua") + p("reinitd at "..os.time()) end local args = message.content:split(" ") local lowerArgs = args[1]:lower() local command = Commands[lowerArgs] if command then command.exec(message, args) - elseif Tools.testModeDetection() == false and Tools.messageDectection(message, "reinitialize") == true then + elseif mode == "normal" and Tools.messageDectection(message, "reinitialize") == true then + p("reinitd at "..os.time()) reinitialize(message) - elseif Tools.testModeDetection() == true and Tools.messageDectection(message, "reinitialize") == true then + elseif mode == "testMode" and Tools.messageDectection(message, "reinitialize") == true then message:reply("You cannot preform this command because testMode is on!") + p("Not reinitd at "..os.time()) end end) @@ -42,6 +56,11 @@ function reinitialize(message) 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") diff --git a/commands/complexCommands.lua b/commands/complexCommands.lua index f217277..15b2f72 100644 --- a/commands/complexCommands.lua +++ b/commands/complexCommands.lua @@ -1,13 +1,16 @@ local tools = dofile("./API/tools.lua") local rng = dofile("./API/rng.lua") local complexCommands = {} - local prefix = dofile("./docs/key.lua") 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) - message.channel:send(tools.printFile("docs/help")) + if tools.testModeDetection() == true then + message.channel:send(tools.printFile("docs/helpTestMode")) + else + message.channel:send(tools.printFile("docs/help")) + end end }; @@ -21,6 +24,7 @@ local commands = { -- Define commands its a table that will contain our commands end }; +--[[ [prefix..'figlet'] = { -- Parrots input to figlet, then echos it to the same channel you are in. exec = function (message) local prefixLength = string.len(prefix) @@ -42,6 +46,7 @@ end message:delete() end }; +]] [prefix..'echo'] = { -- Echo's what you said back out, in a fix codeblock. Could be against TOS. exec = function (message) diff --git a/commands/experimentalCommands.lua b/commands/experimentalCommands.lua new file mode 100644 index 0000000..e9bed00 --- /dev/null +++ b/commands/experimentalCommands.lua @@ -0,0 +1,29 @@ +local tools = dofile("./API/tools.lua") +local rng = dofile("./API/rng.lua") +local experimentalCommands = {} +local prefix = dofile("./docs/key.lua") + +local commands = { -- Define commands its a table that will contain our commands +[prefix..'experiment'] = { + exec = function (message) + message.channel:send("Experimental mode works!") + end +}; + +[prefix..'test'] = { -- Test Command. +exec = function (message) + message.channel:send("I can add new commands on the fly, probably just going to be for testing purposes. Probably a security hole. Hence why this is the _experimental_ branch") + message:delete() +end +}; + +} + +function experimentalCommands.initialize() + return commands +end +return experimentalCommands +-- 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 diff --git a/commands/simpleCommands.lua b/commands/simpleCommands.lua index 3553b8b..9b0c466 100644 --- a/commands/simpleCommands.lua +++ b/commands/simpleCommands.lua @@ -41,14 +41,7 @@ end [prefix..'welsh'] = { -- Welsh. exec = function (message) - message.channel:send("https://cdn.discordapp.com/attachments/748713417489252503/770289379586867231/image0.gif") - message:delete() -end -}; - -[prefix..'test'] = { -- Test Command. -exec = function (message) - message.channel:send("I can add new commands on the fly, probably just going to be for testing purposes. Probably a security hole. Hence why this is the _experimental_ branch") + message.channel:send("https://cdn.discordapp.com/attachments/748713417489252503/770289379586867231/image0.gif lol") message:delete() end }; diff --git a/docs/helpTestMode b/docs/helpTestMode new file mode 100644 index 0000000..3480d5b --- /dev/null +++ b/docs/helpTestMode @@ -0,0 +1,33 @@ +```fix +Basic functions +--------------- +-figlet +Converts text to ASCII art +-cowsay +Converts text to the speech of a cow +-ping +Pong! +-roll [Argument] +Rolls a dice, by default d20! +-time +Displays the time in military time, as if you were in chicago +-helpme +^-^ + +Basic Information +----------------- +All functions start with '!' though this may change in the future +Under construction! More or less from scratch(Only just got basic I/O working!) +May have secret functions! +Mess with the code +------------------ +The source code is freely availible at +https://github.com/AstoriaFloyd/thembot +Feel free to modify, redistribute, whatever. +If you want to monitise it, sure go ahead. +This code follows the WTFPL, in all 0 of its conditions. + +Extra Information +----------------- +This bot is currently in text mode. +```