33# Tous droits réservés.
44
55try :
6- import colorama , json , subprocess , os , sys , datetime , requests , webbrowser
6+ import colorama , json , subprocess , os , sys , datetime , requests , webbrowser , platform
77 from config .info import *
8+ from colorama import Fore , Style
89except Exception as error :
910 import os
1011 print (f'Error in Module : { error } ' )
1112 os .system ("pause" )
1213
14+ data = {}
1315colorama .init ()
1416color = colorama .Fore
15- reset = color . RESET
17+ reset = Style . RESET_ALL
1618purple = '\033 [38;2;131;0;255m'
19+ lightPurple = '\033 [38;2;178;102;255m'
20+ pink = '\033 [38;2;255;105;180m'
21+ lightBlue = '\033 [38;2;173;216;230m'
22+ lightLilac = '\033 [38;2;200;162;200m'
1723white = color .WHITE
1824yellow = color .YELLOW
1925blue = color .BLUE
2026red = color .RED
2127green = color .GREEN
22-
23- parametreFichier = 'config/parametre.json'
28+ bold = Style .BRIGHT
29+ dim = Style .DIM
30+ normal = Style .NORMAL
2431
2532def githubVersion ():
2633 response = requests .get (linkUpdate )
@@ -54,55 +61,24 @@ def checkUpdate():
5461# else:
5562# pass
5663
57- def Sauvegarde () :
58- try :
59- with open (parametreFichier , 'w' ) as fichier :
60- json .dump (data , fichier , indent = 4 )
61- except FileNotFoundError :
62- print (f'{ red } [{ white } x{ red } ] The file { parametreFichier } is not found. { reset } ' )
63- os .system ('pause' )
64- except Exception as error :
65- print (f'{ red } [{ white } x{ red } ] An error occurred while saving the settings: { yellow } { error } { reset } ' )
66- os .system ('pause' )
67-
68- try :
69- with open (parametreFichier , 'r' ) as fichier :
70- data = json .load (fichier )
71- except FileNotFoundError :
72- print (f'{ red } [{ white } x{ red } ] The file { parametreFichier } is not found. { reset } ' )
73- os .system ('pause' )
74- except json .JSONDecodeError :
75- print (f'{ red } [{ white } x{ red } ] JSON decoding error in the file { parametreFichier } . { reset } ' )
76- os .system ('pause' )
77- except Exception as error :
78- print (f'{ red } [{ white } x{ red } ] An error occurred while loading the settings: { yellow } { error } { reset } ' )
79- os .system ('pause' )
80-
81- def setPromptColor (setting ):
64+ def setPromptColor ():
8265 global promptColor
83- if setting ['promptColor' ] == 'white' :
66+ if data ['promptColor' ] == 'white' :
8467 promptColor = white
85- elif setting ['promptColor' ] == 'yellow' :
68+ elif data ['promptColor' ] == 'yellow' :
8669 promptColor = yellow
87- elif setting ['promptColor' ] == 'blue' :
70+ elif data ['promptColor' ] == 'blue' :
8871 promptColor = blue
89- elif setting ['promptColor' ] == 'red' :
72+ elif data ['promptColor' ] == 'red' :
9073 promptColor = red
91- elif setting ['promptColor' ] == 'green' :
74+ elif data ['promptColor' ] == 'green' :
9275 promptColor = green
93- elif setting ['promptColor' ] == 'purple' :
76+ elif data ['promptColor' ] == 'purple' :
9477 promptColor = purple
9578 else :
9679 promptColor = white
9780 print (f'{ ERROR } Unknown prompt color: { data ['promptColor' ]} . Using default white.' )
98- os .system ('pause' )
99-
100- setPromptColor (data )
101-
102- try :
103- username = os .getlogin ()
104- except :
105- username = 'user'
81+ Pause ()
10682
10783def TIME_H ():
10884 return datetime .datetime .now ().strftime ('%H:%M:%S' )
@@ -144,9 +120,26 @@ def startMenu(program):
144120 elif sys .platform .startswith ("linux" ):
145121 file = f'python3 menu/{ program } '
146122 subprocess .run (file , shell = True )
123+
124+ def errorModule (error ):
125+ print (f'{ TIME_RED ()} { ERROR } Error Module (Restart install.bat) or contact support on the discord server : { yellow } { error } { reset } ' )
126+ webbrowser .open (linkDiscord )
127+ Pause ()
128+ mainMenu ()
129+
130+ def error (error ):
131+ print (f"\n { TIME_RED ()} { ERROR } Error : { yellow } { error } { reset } " )
132+ Pause ()
133+ mainMenu ()
134+
135+ def errorUrl ():
136+ print (f"\n { TIME_RED ()} { ERROR } Invalid URL ! { reset } " )
137+ Pause ()
138+ mainMenu ()
147139
148140def Pause ():
149141 input (f"{ TIME ()} { WAIT } Press to continue >>> { reset } " )
142+
150143def Soon ():
151144 print (f'{ TIME_YELLOW ()} { INFO_YELLOW } The chosen option will arrive soon. { reset } ' )
152145 Pause ()
@@ -194,10 +187,112 @@ def TIME_YELLOW():
194187 {"num" : 3 , "titre" : "NukeBot Discord" },
195188 {"num" : 8 , "titre" : "Soon" },
196189 {"num" : 13 , "titre" : "Soon" },
197- {"num" : 4 , "titre" : "Soon " },
190+ {"num" : 4 , "titre" : "Discord Invitation Info " },
198191 {"num" : 9 , "titre" : "Soon" },
199192 {"num" : 14 , "titre" : "Soon" },
200193 {"num" : 5 , "titre" : "Soon" },
201194 {"num" : 10 , "titre" : "Soon" },
202195 {"num" : 15 , "titre" : "Soon" },
203- ]
196+ ]
197+ def Sauvegarde () :
198+ try :
199+ save_dir = setDirectory ()
200+ filePath = os .path .join (save_dir , 'Save.json' )
201+ with open (filePath , 'w' ) as fichier :
202+ json .dump (data , fichier , indent = 4 )
203+ except FileNotFoundError :
204+ print (f'{ TIME_RED ()} { ERROR } The file { filePath } is not found. { reset } ' )
205+ Pause ()
206+ except Exception as error :
207+ print (f'{ TIME_RED ()} { ERROR } An error occurred while saving the settings: { yellow } { error } { reset } ' )
208+ Pause ()
209+
210+ def setDirectory ():
211+ if platform .system () == 'Windows' :
212+ documents_folder = os .path .join (os .path .expanduser ('~' ), 'Documents' )
213+ return os .path .join (documents_folder , 'CodeBreak' )
214+ elif platform .system () == 'Linux' :
215+ return os .path .join (os .path .expanduser ('~' ), '.local' , 'share' , 'CodeBreak' )
216+ elif platform .system () == 'Darwin' :
217+ library_folder = os .path .join (os .path .expanduser ('~' ), 'Library' , 'Application Support' )
218+ return os .path .join (library_folder , 'CodeBreak' )
219+ else :
220+ raise OSError (f"{ TIME_RED ()} { ERROR } Système d'exploitation non supporté{ reset } " )
221+
222+ def saveDirectory (path ):
223+ try :
224+ os .makedirs (path , exist_ok = True )
225+ except Exception as e :
226+ print (f'{ TIME_RED ()} { ERROR } Erreur lors de la création du dossier { path } : { e } { reset } ' )
227+ Pause ()
228+
229+ def loadData (saveFile ):
230+ if os .path .exists (saveFile ):
231+ try :
232+ with open (saveFile , 'r' ) as fichier :
233+ data = json .load (fichier )
234+ if not isinstance (data , dict ):
235+ return {}
236+ return data
237+ except FileNotFoundError :
238+ print (f'{ TIME_RED ()} { ERROR } The file { saveFile } is not found. { reset } ' )
239+ except json .JSONDecodeError :
240+ print (f'{ TIME_RED ()} { ERROR } JSON decoding error in the file { saveFile } . { reset } ' )
241+ except Exception as error :
242+ print (f'{ TIME_RED ()} { ERROR } An error occurred while loading the settings: { yellow } { error } { reset } ' )
243+ return defaultData
244+ else :
245+ return defaultData
246+
247+ def FirstSauvegarde (file_path , data ):
248+ try :
249+ with open (file_path , 'w' ) as fichier :
250+ json .dump (data , fichier , indent = 4 )
251+ except Exception as error :
252+ print (f'{ TIME_RED ()} { ERROR } Une erreur est survenue lors de la sauvegarde des paramètres : { yellow } { error } { reset } ' )
253+ Pause ()
254+
255+ def upData (existing_data , newData ):
256+ if isinstance (existing_data , dict ) and isinstance (newData , dict ):
257+ for key , value in newData .items ():
258+ if key not in existing_data :
259+ existing_data [key ] = value
260+ else :
261+ print (f'{ TIME_RED ()} { ERROR } Les données existantes ou nouvelles ne sont pas des dictionnaires.{ reset } ' )
262+ return existing_data
263+
264+
265+ try :
266+ username = os .getlogin ()
267+ except :
268+ username = 'user'
269+
270+ defaultData = {
271+ "promptColor" : "purple" ,
272+ "token" : "null" ,
273+ "excludeIds" : [
274+ "726772485252710503"
275+ ],
276+ "censureToken" : "False"
277+ }
278+
279+ def main ():
280+ global data
281+
282+ try :
283+ save_dir = setDirectory ()
284+ save_file_path = os .path .join (save_dir , 'Save.json' )
285+ saveDirectory (save_dir )
286+ existing_data = loadData (save_file_path )
287+ data = upData (existing_data , defaultData )
288+ FirstSauvegarde (save_file_path , data )
289+ except Exception as error :
290+ print (f'{ TIME_RED ()} { ERROR } error loading/writing backup : { error } { reset } ' )
291+ Pause ()
292+
293+ try :
294+ setPromptColor ()
295+ except Exception as error :
296+ print (f'{ TIME_RED ()} { ERROR } error setPromptColor : { error } { reset } ' )
297+ Pause ()
298+ main ()
0 commit comments