From 8b13c4724f588bc4ed816031065ded71a8896af0 Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Fri, 13 Aug 2021 16:53:03 -0500 Subject: [PATCH] Added first time setup. The way this is implemented is stupid, but it works. --- API/tools.lua | 5 +++++ bot.lua | 32 +++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/API/tools.lua b/API/tools.lua index 52c9916..aaf4271 100644 --- a/API/tools.lua +++ b/API/tools.lua @@ -149,6 +149,11 @@ function tools.fumoList() return(fumoList) end +--Checks if file exists +function tools.file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end + end --Message detection logic. If string.find detects both the desired string, and the key, starting at position 1, do the thing. --Now deprecated diff --git a/bot.lua b/bot.lua index e92f6b9..4eab445 100644 --- a/bot.lua +++ b/bot.lua @@ -3,6 +3,34 @@ local client = discordia.Client() Tools = dofile("./API/tools.lua") discordia.extensions() +if Tools.file_exists("./docs/firstTimeSetupComplete") == false then + print("First time setup started") + os.execute("touch docs/firstTimeSetupComplete") + print("Please enter bot token.") + process.stdin:once("data", function(input) + tokenInput = input:gsub("[\n\r]", "") + os.execute("touch docs/token.lua") + local file = io.open("./docs/token.lua", "w") + file:write('return "'..tokenInput..'"') + file:close() + print("Please enter symbol for command detection(eg, the ! in !helpme)") + process.stdin:once("data", function(input) + keyInput = input:gsub("[\n\r]", "") + os.execute("touch docs/key.lua") + local file = io.open("./docs/key.lua", "w") + file:write('return "'..keyInput..'"') + file:close() + print("First time setup complete!") + local token = dofile("./docs/token.lua") + client:run('Bot '..token) + end) + end) +else + print("If this errors because of bad token, delete docs/firstTimeSetupComplete") + local token = dofile("./docs/token.lua") + client:run('Bot '..token) +end + --Setup bot here, initializes bot client:once("ready", function() client:setGame("Astoria's bot, very sad!") @@ -59,6 +87,4 @@ client:on('userBan', function(user, guild) end end) ---Insert Token in a .lua file with simply returns it as a string. -local token = require("./docs/token.lua") -client:run('Bot '..token) \ No newline at end of file +--Insert Token in a .lua file with simply returns it as a string. \ No newline at end of file