Permalink
Cannot retrieve contributors at this time
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?
MinecraftDiscord/setup.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
42 lines (37 sloc)
1.48 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def environment(): | |
import os.path | |
'''Prevents overwriting of the environment 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 = overwrite.lower() #Makes the input string lowercase | |
if overwrite == "y" or overwrite == "yes": | |
print("Creating new credientials... \n") | |
else: | |
return #Exit function | |
'''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 | |
'''Concantinate into a string''' | |
data = "TOKEN={}\nSERVER={}\nPORT={}".format(token,serverIP,port) #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 |