From 58af3ab21cde41f45c10a944d3c2b3be9d514cad Mon Sep 17 00:00:00 2001 From: Alastair Holland Date: Sun, 3 May 2020 12:34:36 +0100 Subject: [PATCH] Added Settings --- README.md | 2 +- lib/setup.py | 76 ++++++++++++++++++++++++++++++++----- templates/customTemplate.py | 1 + 3 files changed, 68 insertions(+), 11 deletions(-) create mode 100755 templates/customTemplate.py diff --git a/README.md b/README.md index b98665f..3a38dca 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Minecraft Discord Welcome to my GitHub -This is a Discord bot that you host yourself (tutorial below) that can tell you the status of your (or any public) Minecraft server and tlel you the players online. +This is a Discord bot that you host yourself (tutorial below) that can tell you the status of your (or any public) Minecraft server and lists the players online. More functions listed below. ## README in development \ No newline at end of file diff --git a/lib/setup.py b/lib/setup.py index 710379d..2ffc72f 100755 --- a/lib/setup.py +++ b/lib/setup.py @@ -1,24 +1,79 @@ def environment(): - import os.path + import os '''Prevents overwriting of the environment file''' + settingList = ["Token", "Server IP", "Port", "Command Prefix", "Custom File"] if os.path.isfile('.env'): #Checks to see if there is an environment file - overwrite = input("Would you like to overwrite your current credentials? (y/n)") + overwrite = input("Would you like to change your current settings? (y/n) > ") overwrite = overwrite.lower() #Makes the input string lowercase if overwrite == "y" or overwrite == "yes": - print("Creating new credientials... \n") + print("\nChoose settings to change") + for i in settingList: + print("{} - {}".format((settingList.index(i)+1), i)) + settingsChoice = input("\nInput the numbers of the settings you want to change\nYou can change multiple numbers by typing more than one (Example: 12345)\n > ") else: return #Exit function + else: + settingsChoice = "12345" '''Gets information''' - token = input("Input your bot token here > ") - serverIP = input("Input your server URL/IP here > ") - port = input("Input your bot port here (If you don't know it, leave blank) > ") - if port == "": - port = "25565" #Default Minecraft server port + if str(settingList.index("Token")+1) in settingsChoice: + token = input("Input your bot token here > ") + else: + token = os.environ['TOKEN'] + if str(settingList.index("Server IP")+1) in settingsChoice: + serverIP = input("Input your server URL/IP here > ") + else: + serverIP = os.environ['SERVER'] + if str(settingList.index("Port")+1) in settingsChoice: + port = input("Input your bot port here (If you don't know it, leave blank) > ") + if port == "": + port = "25565" #Default Minecraft server port + else: + port = os.environ['PORT'] + if str(settingList.index("Command Prefix")+1) in settingsChoice: + commandPrefix = input("If you want a custom command prefix, enter is here (Default is '?' - Leave bank for default)> ") + if commandPrefix == "": + commandPrefix = "?" + else: + commandPrefix = os.environ['PREFIX'] + if str(settingList.index("Custom File")+1) in settingsChoice: + customFile = input("Would you like a custom file to add your code to? (y/n) > ") + customFile = customFile.lower() + if customFile == "y" or customFile == "yes": + if os.path.isfile("Custom.py"): + newCustom = input("Do you want to overwrite the current custom file? (y/n) > ") + newCustom = newCustom.lower() + if newCustom == "y" or newCustom == "yes": + oldFile = open("customCode.py", "r") + oldCode = oldFile.read() + oldFile.close() + x = 0 + copied = False + while copied == False: + backupPath = "oldCustom/custom{}.py".format(x) + if not os.path.isfile(backupPath): + backupFile = open(backupPath, "w") + backupFile.write(oldCode) + copied = True + x = x + 1 + template = open("templates/customTemplate.py", "r") + customFile = open("customCode.py", "w") + customFile.write(template.read()) + customFile.close() + template.close() + else: + template = open("templates/customTemplate.py", "r") + customFile = open("customCode.py", "w") + customFile.write(template.read()) + customFile.close() + template.close() + custom = "TRUE" + else: + custom = os.environ['CUSTOM'] '''Concantinate into a string''' - data = "TOKEN={}\nSERVER={}\nPORT={}".format(token,serverIP,port) #Sets the format of the data + data = "TOKEN={}\nSERVER={}\nPORT={}\nPREFIX={}\nCUSTOM={}".format(token,serverIP,port,commandPrefix,custom) #Sets the format of the data '''Write data to the .env file''' creds = open(".env", "w") @@ -39,4 +94,5 @@ def environment(): if tryAgain == "y" or tryAgain == "yes": environment() else: - return \ No newline at end of file + return +environment() \ No newline at end of file diff --git a/templates/customTemplate.py b/templates/customTemplate.py new file mode 100755 index 0000000..018bd18 --- /dev/null +++ b/templates/customTemplate.py @@ -0,0 +1 @@ +#Test \ No newline at end of file