Skip to content
Permalink
dc02368709
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 100 lines (95 sloc) 4.26 KB
def environment():
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 change your current settings? (y/n) > ")
overwrite = overwrite.lower() #Makes the input string lowercase
if overwrite == "y" or overwrite == "yes":
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'''
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("Custom.py", "r")
oldCode = oldFile.read()
oldFile.close()
if not os.path.exists("oldCustom"):
os.makedirs("oldCustom")
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("Custom.py", "w")
customFile.write(template.read())
customFile.close()
template.close()
else:
template = open("templates/customTemplate.py", "r")
customFile = open("Custom.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={}\nPREFIX={}\nCUSTOM={}".format(token,serverIP,port,commandPrefix,custom) #Sets the format of the data
'''Write data to the .env file'''
creds = open(".env", "w")
creds.write(data)
creds.close()
'''Verify the data has been written'''
print("\nVerifying data..")
verify = open(".env")
readData = verify.read()
verify.close()
if data == readData:
print("Data written successfully")
return
else:
tryAgain = ("Error writing data. \n Try again? (y/n) > ")
tryAgain = tryAgain.lower() #Makes the input string lowercase
if tryAgain == "y" or tryAgain == "yes":
environment()
else:
return
environment()