-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathconfigure.py
71 lines (58 loc) · 1.94 KB
/
configure.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import json
import os.path
import sys
from shutil import copyfile
import discord
import mysql.connector
client = discord.Client()
if not os.path.isfile("config.json"):
copyfile("default-config.json", "config.json")
with open("config.json") as f:
config = json.load(f)
config_mysql = config["mysql"]
config_discord = config["discord"]
@client.event
async def on_ready():
print("discord: Connection is working")
while True:
print("\n[1] Quick installation")
print(
"[2] Test the configuration (Save the configuration before using this option.)"
)
print("[3] save/exit")
option = input("Please enter the desired option:")
if option == "1":
config_mysql["host"] = input("Please enter your mysql host:")
config_mysql["port"] = input("Pleasen enter your mysql port:")
config_mysql["user"] = input("Please enter your mysql username:")
config_mysql["password"] = input("Please enter your mysql password:")
config_mysql["database"] = input(
"Please enter your mysql database name:")
config_discord["bot_token"] = input(
"Please enter your discord bot token:")
elif option == "2":
try:
test_mysql = mysql.connector.connect(
user=config_mysql["user"],
password=config_mysql["password"],
host=config_mysql["host"],
port=config_mysql["port"],
database=config_mysql["database"])
test_mysql.close()
print("mysql: Connection is working")
except mysql.connector.Error as err:
print(f"mysql: Something went wrong: {err}")
client.run(config_discord["bot_token"])
elif option == "3":
print(("Do you want to save before exiting? [y/n]"))
option = input()
if option == "y" or "yes":
break
if option == "n" or "no":
sys.exit()
else:
print("You entered a invalid option.")
else:
print("Please enter a valid option number!")
with open("config.json", "w") as f:
json.dump(config, f, indent=4, sort_keys=False)