-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsetupfile.py
205 lines (189 loc) · 6.89 KB
/
setupfile.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import subprocess
import os
import configparser
import string
import random
config = configparser.ConfigParser()
config.read('database.ini')
def cls():
os.system('cls' if os.name == 'nt' else 'clear')
def mainmenu():
cls()
print("")
print("Welcome to the main menu.")
print("")
print("For proper installation be sure to run the setup file in the same folder as the downloaded files!")
print("")
print("Please select an option.")
print("""
1. Fully automated setup
2. Manual setup
2. Exit
""")
choice = input("Enter your choice: ")
if choice == "1":
autosetup()
if choice == "2":
setup()
elif choice == "2":
exit()
def passwordgenerator():
chars = string.ascii_letters + string.digits
return ''.join(random.choice(chars) for i in range(18))
def fetchurlcorectly(domaintogo):
domainwithoutslash = domaintogo[:-1]
if domaintogo.endswith('/'):
return domainwithoutslash
else:
return domaintogo
def autosetup():
checkfile1 = os.path.exists('application.py')
checkfile2 = os.path.exists('database.ini')
checkfile3 = os.path.exists('requirements.txt')
if checkfile1 == True:
pass
else:
print("The application.py file is missing.")
print("Please download the file and place it in the same folder as this file.")
type = input('Press enter to continue')
exit()
if checkfile2 == True:
pass
else:
print("The database.ini file is missing.")
print("Please download the file and place it in the same folder as this file.")
type = input('Press enter to continue')
exit()
if checkfile3 == True:
pass
else:
print("The requirements.txt file is missing.")
print("Please download the file and place it in the same folder as this file.")
type = input('Press enter to continue')
exit()
cls()
domain = input("Enter your FLASK domain/ip: ")
memberrole = input("Enter the member role name: ")
welcomechannel = input("Enter the welcome channel id: ")
therestorekey = input("Enter the restore key used to restore backups: ")
guildid = input("Enter the guild ID: ")
config['apiinfo']['DOMAIN'] = fetchurlcorectly(domain)
config['botinfo']['memberrole'] = memberrole
config['botinfo']['welcome_channel'] = welcomechannel
config['botinfo']['therestorekey'] = therestorekey
config['apiinfo']['exchangepass'] = passwordgenerator()
config['apiinfo']['tempkey'] = passwordgenerator()
config['botinfo']['guildid'] = guildid
with open('database.ini', 'w') as configfile:
config.write(configfile)
print("")
print("Changes were saved now starting installing do you want to continue? (y/n)")
print("")
choice = input("Enter your choice: ")
if choice == "y":
install()
elif choice == "n":
exit()
def setup():
checkfile1 = os.path.exists('application.py')
checkfile2 = os.path.exists('database.ini')
checkfile3 = os.path.exists('requirements.txt')
if checkfile1 == True:
pass
else:
print("The application.py file is missing.")
print("Please download the file and place it in the same folder as this file.")
type = input('Press enter to continue')
exit()
if checkfile2 == True:
pass
else:
print("The database.ini file is missing.")
print("Please download the file and place it in the same folder as this file.")
type = input('Press enter to continue')
exit()
if checkfile3 == True:
pass
else:
print("The requirements.txt file is missing.")
print("Please download the file and place it in the same folder as this file.")
type = input('Press enter to continue')
exit()
cls()
cls()
print("")
print("Welcome to the setup.")
print("")
print("Please enter the following information.")
print("")
print("")
clientid = input("Enter Client ID from the discord developer dashboard: ")
clientsecret = input("Enter Client Secret from the discord developer dashboard: ")
bottoken = input("Enter your Bot token: ")
domain = input("Enter your FLASK domain/ip: ")
welcomechannel = input("Enter the welcome channel id: ")
memberrole = input("Enter the member role name: ")
therestorekey = input("Enter the restore key used to restore backups: ")
guildid = input("Enter the guild ID: ")
print("")
print("")
cls()
print("Please wait while we save all of the changes!")
print("")
config['apiinfo']['CLIENT_ID'] = clientid
config['apiinfo']['CLIENT_SECRET'] = clientsecret
config['apiinfo']['DOMAIN'] = fetchurlcorectly(domain)
config['botinfo']['bottoken'] = bottoken
config['botinfo']['memberrole'] = memberrole
config['botinfo']['welcome_channel'] = welcomechannel
config['botinfo']['therestorekey'] = therestorekey
config['apiinfo']['exchangepass'] = passwordgenerator()
config['apiinfo']['tempkey'] = passwordgenerator()
config['botinfo']['guildid'] = guildid
with open('database.ini', 'w') as configfile:
config.write(configfile)
print("")
print("Changes were saved now starting installing do you want to continue? (y/n)")
print("")
choice = input("Enter your choice: ")
if choice == "y":
install()
elif choice == "n":
exit()
def install():
try:
subprocess.call('pip install -r requirements.txt', shell=True)
except:
try:
subprocess.call('pip3 install -r requirements.txt', shell=True)
except:
try:
subprocess.call('python pip install -r requirements.txt', shell=True)
except:
try:
subprocess.call('python3 pip install -r requirements.txt', shell=True)
except:
try:
subprocess.call('py pip install -r requirements.txt', shell=True)
except:
print("Could not install requirements.txt")
print("Error installing requirements please try manually.")
exit()
print("Requirements installed")
print("")
print("Do you want to start the API?")
print("")
print("(y/n)")
print("")
choice = input("Enter your choice: ")
if choice == "y":
try:
subprocess.call('python application.py', shell=True)
except:
print("Failed to execute please start manually.")
typetocon = input("Please Press enter to continue")
exit()
elif choice == "n":
exit()
if __name__ == '__main__':
mainmenu()