1+ # © 2024 CIPIX
2+ # All rights reserved.
3+ # Tous droits réservés.
4+
5+ try :
6+ import colorama , json , subprocess , os , sys , datetime , requests , webbrowser
7+ from config .info import *
8+ except Exception as error :
9+ import os
10+ print (f'Error in Module : { error } ' )
11+ os .system ("pause" )
12+
13+ colorama .init ()
14+ color = colorama .Fore
15+ reset = color .RESET
16+ purple = '\033 [38;2;131;0;255m'
17+ white = color .WHITE
18+ yellow = color .YELLOW
19+ blue = color .BLUE
20+ red = color .RED
21+ green = color .GREEN
22+
23+ parametreFichier = 'config/parametre.json'
24+
25+ def githubVersion ():
26+ response = requests .get (linkUpdate )
27+ if response .status_code == 200 :
28+ github_vars = {}
29+ exec (response .text , github_vars )
30+ return github_vars .get ('versionCode' )
31+ else :
32+ print (f"{ TIME_RED ()} { ERROR } Unable to retrieve the info.py file from the GitHub repository." )
33+ Pause ()
34+
35+ def checkUpdate ():
36+ github_version = githubVersion ()
37+
38+ if versionCode != github_version :
39+ print (f"""
40+ { TIME_RED ()} { ERROR } Update available !
41+
42+ Current version :{ yellow } { versionCode } { red }
43+ New version :{ green } { github_version } { red }
44+ Please update CodeBreak to get the latest improvements and fixes.
45+ Opening the update link in your browser... { reset }
46+ """ )
47+ webbrowser .open (linkGithub )
48+ # if sys.platform.startswith("win"):
49+ # file = f'python update.py'
50+ # subprocess.run(file, shell=True)
51+ # elif sys.platform.startswith("linux"): Soon !
52+ # file = f'python3 update.py'
53+ # subprocess.run(file, shell=True)
54+ # else:
55+ # pass
56+
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 ):
82+ global promptColor
83+ if setting ['promptColor' ] == 'white' :
84+ promptColor = white
85+ elif setting ['promptColor' ] == 'yellow' :
86+ promptColor = yellow
87+ elif setting ['promptColor' ] == 'blue' :
88+ promptColor = blue
89+ elif setting ['promptColor' ] == 'red' :
90+ promptColor = red
91+ elif setting ['promptColor' ] == 'green' :
92+ promptColor = green
93+ elif setting ['promptColor' ] == 'purple' :
94+ promptColor = purple
95+ else :
96+ promptColor = white
97+ 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'
106+
107+ def TIME_H ():
108+ return datetime .datetime .now ().strftime ('%H:%M:%S' )
109+
110+ def CLEAR ():
111+ if sys .platform .startswith ("win" ):
112+ os .system ("cls" )
113+ else :
114+ os .system ("clear" )
115+
116+ def terminalTitle (title ):
117+ if sys .platform .startswith ("win" ):
118+ os .system (f'title CodeBreak - { title } ' )
119+ else :
120+ sys .stdout .write (f"\033 ]0;CodeBreak - { title } \007 " )
121+ sys .stdout .flush ()
122+
123+ def mainMenu ():
124+ print (f'{ TIME_YELLOW ()} { WAIT_YELLOW } Loading main menu...' )
125+ if sys .platform .startswith ("win" ):
126+ file = 'python ./CodeBreak.py'
127+ subprocess .run (file , shell = True )
128+ elif sys .platform .startswith ("linux" ):
129+ file = 'python3 ./CodeBreak.py'
130+ subprocess .run (file , shell = True )
131+
132+ def startProgram (program ):
133+ if sys .platform .startswith ("win" ):
134+ file = f'python Program/{ program } '
135+ subprocess .run (file , shell = True )
136+ elif sys .platform .startswith ("linux" ):
137+ file = f'python3 Program/{ program } '
138+ subprocess .run (file , shell = True )
139+
140+ def startMenu (program ):
141+ if sys .platform .startswith ("win" ):
142+ file = f'python menu/{ program } '
143+ subprocess .run (file , shell = True )
144+ elif sys .platform .startswith ("linux" ):
145+ file = f'python3 menu/{ program } '
146+ subprocess .run (file , shell = True )
147+
148+ def Pause ():
149+ input (f"{ TIME ()} { WAIT } Press to continue >>> { reset } " )
150+ def Soon ():
151+ print (f'{ TIME_YELLOW ()} { INFO_YELLOW } The chosen option will arrive soon. { reset } ' )
152+ Pause ()
153+
154+ ERROR = f'{ red } [{ white } x{ red } ]'
155+
156+ ADD = f'{ purple } [{ white } +{ purple } ]'
157+ INFO = f'{ purple } [{ white } !{ purple } ]'
158+ INPUT = f'{ purple } [{ white } >{ purple } ]'
159+ WAIT = f'{ purple } [{ white } ~{ purple } ]'
160+ def TIME ():
161+ return f'{ purple } [{ white } { TIME_H ()} { purple } ]'
162+
163+
164+ ADD_RED = f'{ red } [{ white } +{ red } ]'
165+ INFO_RED = f'{ red } [{ white } !{ red } ]'
166+ INPUT_RED = f'{ red } [{ white } >{ red } ]'
167+ WAIT_RED = f'{ red } [{ white } ~{ red } ]'
168+ def TIME_RED ():
169+ return f'{ red } [{ white } { TIME_H ()} { red } ]'
170+
171+ ADD_GREEN = f'{ green } [{ white } +{ green } ]'
172+ INFO_GREEN = f'{ green } [{ white } !{ green } ]'
173+ INPUT_GREEN = f'{ green } [{ white } >{ green } ]'
174+ WAIT_GREEN = f'{ green } [{ white } ~{ green } ]'
175+ def TIME_GREEN ():
176+ return f'{ green } [{ white } { TIME_H ()} { green } ]'
177+
178+ ADD_YELLOW = f'{ yellow } [{ white } +{ yellow } ]'
179+ INFO_YELLOW = f'{ yellow } [{ white } !{ yellow } ]'
180+ INPUT_YELLOW = f'{ yellow } [{ white } >{ yellow } ]'
181+ WAIT_YELLOW = f'{ yellow } [{ white } ~{ yellow } ]'
182+ def TIME_YELLOW ():
183+ return f'{ yellow } [{ white } { TIME_H ()} { yellow } ]'
184+
185+ CHOICELANG = f'{ purple } [{ white } 1{ purple } ] English | [{ white } 2{ purple } ] French'
186+
187+ MainOption = [
188+ {"num" : 1 , "titre" : "Info" },
189+ {"num" : 6 , "titre" : "Soon" },
190+ {"num" : 11 , "titre" : "Soon" },
191+ {"num" : 2 , "titre" : "Setting" },
192+ {"num" : 7 , "titre" : "Soon" },
193+ {"num" : 12 , "titre" : "Soon" },
194+ {"num" : 3 , "titre" : "NukeBot Discord" },
195+ {"num" : 8 , "titre" : "Soon" },
196+ {"num" : 13 , "titre" : "Soon" },
197+ {"num" : 4 , "titre" : "Soon" },
198+ {"num" : 9 , "titre" : "Soon" },
199+ {"num" : 14 , "titre" : "Soon" },
200+ {"num" : 5 , "titre" : "Soon" },
201+ {"num" : 10 , "titre" : "Soon" },
202+ {"num" : 15 , "titre" : "Soon" },
203+ ]
0 commit comments