From 250ad85bbe50cccbd37fcd462fa8794254970b0a Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Sun, 8 Aug 2021 15:07:57 -0500 Subject: [PATCH 1/4] Adding small thing for potential zerobrane work. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fa8f83f..ca88548 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ gateway.json token.lua launch.json .vscode +interpreter.lua -- 2.43.0 From fe16508fe1e3e5b09225ff17845dd180ecea43e5 Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Sun, 8 Aug 2021 17:44:45 -0500 Subject: [PATCH 2/4] Added testmode functionality. Created experimental branch --- API/tools.lua | 9 +++- bot.lua | 41 +++++++++++-------- commands/complexCommands.lua | 37 +++++++++-------- commands/simpleCommands.lua | 75 ++++++++++++++++++++-------------- docs/{settings.lua => key.lua} | 2 +- docs/testmode.lua | 1 + startBot.sh | 0 7 files changed, 99 insertions(+), 66 deletions(-) rename docs/{settings.lua => key.lua} (75%) create mode 100644 docs/testmode.lua mode change 100644 => 100755 startBot.sh diff --git a/API/tools.lua b/API/tools.lua index acda8aa..e3ecbe5 100644 --- a/API/tools.lua +++ b/API/tools.lua @@ -17,6 +17,13 @@ function tools.initialize() return commands end +--Reads testmode.lua +function tools.testModeDetection() + return dofile("./docs/testmode.lua") +end + +-- + --Reads an entire file, outputs as string. function tools.printFile(file) local rawFile = io.open(file, r) @@ -51,7 +58,7 @@ end --Now deprecated function tools.messageDectection(message, search) local distinctMessage = string.lower(message.content) - local key = require("./docs/settings.lua") + local key = dofile("./docs/key.lua") local keyedSearch = key .. search if string.find(distinctMessage, keyedSearch) == 1 then return true diff --git a/bot.lua b/bot.lua index 53b8863..12658fd 100644 --- a/bot.lua +++ b/bot.lua @@ -12,28 +12,35 @@ end) --Command handler client:on('messageCreate', function(message) - if message.author.bot then return end - local args = message.content:split(" ") - local lowerArgs = args[1]:lower() - local command = Commands[lowerArgs] - if command then - command.exec(message, args) - end + if message.author.bot then return end + if Tools.testModeDetection() == true then + Commands = Tools.initialize() + Tools = dofile("./API/tools.lua") + 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 + reinitialize(message) + elseif Tools.testModeDetection() == true and Tools.messageDectection(message, "reinitialize") == true then + message:reply("You cannot preform this command because testMode is on!") + end end) ---Re-Init detector. Only command that itself cannot be fully re-initialized -client:on('messageCreate', function(message) +function reinitialize(message) local user = message.guild:getMember(message.author.id) if Tools.messageDectection(message, "reinitialize") == true then - if not user:hasPermission("administrator") then - message:reply("You cannot re-initialize this bot!") - else - Commands = Tools.initialize() - Tools = dofile("./API/tools.lua") - message:reply("Re-Initialized!") + if not user:hasPermission("administrator") then + message:reply("You cannot re-initialize this bot!") + else + Commands = Tools.initialize() + Tools = dofile("./API/tools.lua") + message:reply("Re-Initialized!") + end end - end -end) +end --When a user is banned, post a lenney. client:on('userBan', function() diff --git a/commands/complexCommands.lua b/commands/complexCommands.lua index cca265d..f217277 100644 --- a/commands/complexCommands.lua +++ b/commands/complexCommands.lua @@ -2,57 +2,62 @@ local tools = dofile("./API/tools.lua") local rng = dofile("./API/rng.lua") local complexCommands = {} -local prefix = dofile("./docs/settings.lua") +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) + exec = function (message) message.channel:send(tools.printFile("docs/help")) end - }; +}; + [prefix..'roll'] = { -- Rolls a d20, check RNG for more info. - exec = function (message, arg) + exec = function (message, arg) if not arg[2] then message.channel:send(rng.d20()) else message.channel:send(rng.roll(arg)) end - end - }; +end +}; + [prefix..'figlet'] = { -- Parrots input to figlet, then echos it to the same channel you are in. - exec = function (message) + exec = function (message) local prefixLength = string.len(prefix) local figletthis = string.sub(message.content, 7+prefixLength) local figlet = tools.figlet(figletthis) local result = "```fix" .. "\n" .. figlet .. "```" message.channel:send(result) message:delete() - end - }; +end +}; + [prefix..'cowsay'] = { -- Parrots input to cowsay, then echos it to the same channel you are in. - exec = function (message) + exec = function (message) local prefixLength = string.len(prefix) local cowsay = string.sub(message.content, 7+prefixLength) local cowsaid = tools.cowsay(cowsay) local result = "```fix" .. "\n" .. cowsaid .. "```" message.channel:send(result) message:delete() - end - }; +end +}; + [prefix..'echo'] = { -- Echo's what you said back out, in a fix codeblock. Could be against TOS. - exec = function (message) + exec = function (message) local prefixLength = string.len(prefix) local echo = string.sub(message.content, 5+prefixLength) local echoed = tools.echo(echo) local result = "```fix" .. "\n" .. echoed .. "```" message.channel:send(result) message:delete() - end - }; +end +}; + } function complexCommands.initialize() -return commands + return commands end return complexCommands -- This project is libre, and licenced under the terms of the diff --git a/commands/simpleCommands.lua b/commands/simpleCommands.lua index 86a4300..3553b8b 100644 --- a/commands/simpleCommands.lua +++ b/commands/simpleCommands.lua @@ -1,45 +1,58 @@ local basicCommands = {} -local prefix = dofile("./docs/settings.lua") +local prefix = dofile("./docs/key.lua") local commands = { -- Define commands its a table that will contain our commands [prefix..'lenny'] = { -- Creates a lenny face - exec = function (message) - message.channel:send('( ͡° ͜ʖ ͡°)') - end - }; +exec = function (message) + message.channel:send('( ͡° ͜ʖ ͡°)') +end +}; + [prefix..'glomp'] = { -- Posts an image of glomping, may add RNG later. - exec = function (message) - message.channel:send('https://tenor.com/view/tv-shows-television-tackle-hug-hug-glomping-gif-14859564') - end - }; +exec = function (message) + message.channel:send('https://tenor.com/view/tv-shows-television-tackle-hug-hug-glomping-gif-14859564') +end +}; + [prefix..'ping'] = { -- Ping Pong function, generally just to see if its on or not without triggering a more complex function. Also tests if its really borked. - exec = function (message) - message.channel:send("Pong!") - end - }; +exec = function (message) + message.channel:send("Pong!") +end +}; + [prefix..'fire'] = { -- Places elmo on fire in chat. - exec = function (message) - message.channel:send("https://tenor.com/view/elmo-fire-burn-flame-gif-5042503") - end - }; +exec = function (message) + message.channel:send("https://tenor.com/view/elmo-fire-burn-flame-gif-5042503") +end +}; [prefix..'time'] = { -- Posts time to channel, stuck in military time, perhaps use a io.popen() to get actual system time in a more human readable format? - exec = function (message) - message.channel:send('The current time in military time is ' .. os.date() .. ' atleast in Chicago!') - end - }; +exec = function (message) + message.channel:send('The current time in military time is ' .. os.date() .. ' atleast in Chicago!') +end +}; + [prefix..'analyze'] = { -- Prints contents and attachments to console. - exec = function (message) - p(message.content) - p(message.attachments) - end - }; +exec = function (message) + p(message.content) + p(message.attachments) +end +}; + [prefix..'welsh'] = { -- Welsh. - exec = function (message) - message.channel:send("https://cdn.discordapp.com/attachments/748713417489252503/770289379586867231/image0.gif") - message:delete() - end - }; +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:delete() +end +}; + } diff --git a/docs/settings.lua b/docs/key.lua similarity index 75% rename from docs/settings.lua rename to docs/key.lua index 8c14a52..52fb600 100644 --- a/docs/settings.lua +++ b/docs/key.lua @@ -1,5 +1,5 @@ --Litterally just the prefix right now -return "!" +return "exp!" -- 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 diff --git a/docs/testmode.lua b/docs/testmode.lua new file mode 100644 index 0000000..1bae4d4 --- /dev/null +++ b/docs/testmode.lua @@ -0,0 +1 @@ +return false \ No newline at end of file diff --git a/startBot.sh b/startBot.sh old mode 100644 new mode 100755 -- 2.43.0 From e848c6680415a16b0895ae7d568f31dcbd4d7742 Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Sun, 8 Aug 2021 19:00:32 -0500 Subject: [PATCH 3/4] 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. +``` -- 2.43.0 From 1cef81445d75e4518417a7df35b95e474276ffb1 Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Tue, 10 Aug 2021 19:01:08 -0500 Subject: [PATCH 4/4] Reconfigured bot.lua, added in echoClean --- bot.lua | 26 +++++++++++++++++--------- commands/complexCommands.lua | 14 ++++++++++++++ commands/experimentalCommands.lua | 8 +++----- docs/help | 8 ++++---- docs/helpTestMode | 10 ++++------ 5 files changed, 42 insertions(+), 24 deletions(-) diff --git a/bot.lua b/bot.lua index ba6588b..5e5d328 100644 --- a/bot.lua +++ b/bot.lua @@ -18,28 +18,36 @@ 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 = "testMode" + shouldReinit = true elseif Tools.testModeDetection() == false and mode == "testMode" then mode = "normal" - selfReinitialize() + shouldReinit = false end if mode == "testMode" then - Commands = Tools.initialize() - Tools = dofile("./API/tools.lua") + shouldReinit = true + 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!") + p("Not reinitd at "..os.time()) 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) - elseif 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!") - p("Not reinitd at "..os.time()) end end) diff --git a/commands/complexCommands.lua b/commands/complexCommands.lua index 15b2f72..3f3da99 100644 --- a/commands/complexCommands.lua +++ b/commands/complexCommands.lua @@ -54,6 +54,20 @@ end local echo = string.sub(message.content, 5+prefixLength) local echoed = tools.echo(echo) local result = "```fix" .. "\n" .. echoed .. "```" + if result == "```fix\n```" then message:delete() return + else + message.channel:send(result) + message:delete() + end +end +}; + +[prefix..'echoclean'] = { -- Echo's what you said back out, in a fix codeblock. Could be against TOS. + exec = function (message) + local prefixLength = string.len(prefix) + local echo = string.sub(message.content, 10+prefixLength) + local echoed = tools.echo(echo) + local result = echoed message.channel:send(result) message:delete() end diff --git a/commands/experimentalCommands.lua b/commands/experimentalCommands.lua index e9bed00..f56c75f 100644 --- a/commands/experimentalCommands.lua +++ b/commands/experimentalCommands.lua @@ -9,14 +9,12 @@ local commands = { -- Define commands its a table that will contain our commands message.channel:send("Experimental mode works!") end }; - -[prefix..'test'] = { -- Test Command. +--[[ +[prefix..'fumo'] = { -- To be implemented later.. 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() diff --git a/docs/help b/docs/help index 7916da4..8304f54 100644 --- a/docs/help +++ b/docs/help @@ -2,15 +2,15 @@ Basic functions --------------- -figlet -Converts text to ASCII art +Converts text to ASCII art. Currently disabled due to security problems. -cowsay -Converts text to the speech of a cow +Converts text to the speech of a cow. Currently disabled due to security problems. -ping Pong! -roll [Argument] Rolls a dice, by default d20! -time -Displays the time in military time, as if you were in chicago +Displays the time in military time, as if you were in chicago. -helpme ^-^ Basic Information @@ -18,7 +18,7 @@ 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 +Mess with the code to your hearts content. ------------------ The source code is freely availible at https://github.com/AstoriaFloyd/thembot diff --git a/docs/helpTestMode b/docs/helpTestMode index 3480d5b..18c3ced 100644 --- a/docs/helpTestMode +++ b/docs/helpTestMode @@ -2,31 +2,29 @@ Basic functions --------------- -figlet -Converts text to ASCII art +Converts text to ASCII art. Currently disabled due to security problems. -cowsay -Converts text to the speech of a cow +Converts text to the speech of a cow. Currently disabled due to security problems. -ping Pong! -roll [Argument] Rolls a dice, by default d20! -time -Displays the time in military time, as if you were in chicago +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 +Mess with the code to your hearts content. ------------------ 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. -- 2.43.0