44import os
55import platform
66import subprocess
7+ import json
78from os import system
89from subprocess import call
910
@@ -21,6 +22,201 @@ def clear():
2122 else :
2223 print (f"Unsupported platform, please use Kitty-Tools LITE '{ system } '" )
2324 print (f"For more info go to https://github.com/CPScript/Kitty-Tools/extra.md" )
25+
26+ def check_node_installed ():
27+ """Check if Node.js is installed"""
28+ try :
29+ result = subprocess .run (['node' , '--version' ], capture_output = True , text = True , check = True )
30+ return True , result .stdout .strip ()
31+ except (subprocess .CalledProcessError , FileNotFoundError ):
32+ return False , None
33+
34+ def check_npm_installed ():
35+ """Check if npm is installed"""
36+ try :
37+ result = subprocess .run (['npm' , '--version' ], capture_output = True , text = True , check = True )
38+ return True , result .stdout .strip ()
39+ except (subprocess .CalledProcessError , FileNotFoundError ):
40+ return False , None
41+
42+ def install_nodejs_guide ():
43+ """Show Node.js installation guide"""
44+ system_name = platform .system ().lower ()
45+
46+ print ("\n Node.js is required but not found on your system." )
47+ print ("Please install Node.js using the following instructions:" )
48+ print ()
49+
50+ if system_name == "windows" :
51+ print ("Windows Installation:" )
52+ print ("1. Go to https://nodejs.org/" )
53+ print ("2. Download the Windows Installer (.msi)" )
54+ print ("3. Run the installer and follow the installation wizard" )
55+ print ("4. Make sure to check 'Add to PATH' during installation" )
56+ print ("5. Restart your computer after installation" )
57+ print ()
58+ print ("Alternative - Using Chocolatey:" )
59+ print ("choco install nodejs" )
60+
61+ elif system_name == "darwin" : # macOS
62+ print ("macOS Installation:" )
63+ print ("Option 1 - Using Homebrew (recommended):" )
64+ print (" brew install node" )
65+ print ()
66+ print ("Option 2 - Official installer:" )
67+ print (" 1. Go to https://nodejs.org/" )
68+ print (" 2. Download the macOS Installer (.pkg)" )
69+ print (" 3. Run the installer" )
70+
71+ elif system_name == "linux" :
72+ print ("Linux Installation:" )
73+ print ("Ubuntu/Debian:" )
74+ print (" sudo apt update && sudo apt install nodejs npm" )
75+ print ()
76+ print ("Fedora:" )
77+ print (" sudo dnf install nodejs npm" )
78+ print ()
79+ print ("Arch Linux:" )
80+ print (" sudo pacman -S nodejs npm" )
81+ print ()
82+ print ("CentOS/RHEL:" )
83+ print (" sudo yum install nodejs npm" )
84+
85+ else :
86+ print ("For other platforms, please visit: https://nodejs.org/" )
87+
88+ print ()
89+ print ("After installation, restart your terminal and run this script again." )
90+
91+ def create_package_json ():
92+ """Create package.json file for dependencies"""
93+ script_dir = os .path .dirname (os .path .abspath (__file__ ))
94+ package_json_path = os .path .join (script_dir , 'package.json' )
95+
96+ package_data = {
97+ "name" : "kitty-tools-kahoot-flooder" ,
98+ "version" : "1.4.0" ,
99+ "description" : "Kahoot game flooding utility" ,
100+ "main" : "flood.js" ,
101+ "dependencies" : {
102+ "readline-sync" : "^1.4.10" ,
103+ "kahoot.js-updated" : "^3.1.3" ,
104+ "an-array-of-english-words" : "^2.0.0" ,
105+ "request" : "^2.88.2" ,
106+ "random-name" : "^0.1.2" ,
107+ "console-title" : "^1.1.0" ,
108+ "beepbeep" : "^1.3.0"
109+ },
110+ "engines" : {
111+ "node" : ">=12.0.0"
112+ }
113+ }
114+
115+ try :
116+ with open (package_json_path , 'w' ) as f :
117+ json .dump (package_data , f , indent = 2 )
118+ print ("Created package.json file" )
119+ return True
120+ except Exception as e :
121+ print (f"Failed to create package.json: { e } " )
122+ return False
123+
124+ def install_node_packages ():
125+ """Install required Node.js packages"""
126+ script_dir = os .path .dirname (os .path .abspath (__file__ ))
127+
128+ print ("Installing Node.js dependencies..." )
129+
130+ # Create package.json first
131+ if not create_package_json ():
132+ return False
133+
134+ try :
135+ # Try installing from package.json
136+ result = subprocess .run (
137+ ['npm' , 'install' , '--no-fund' , '--no-audit' ],
138+ cwd = script_dir ,
139+ capture_output = True ,
140+ text = True ,
141+ check = True
142+ )
143+
144+ if result .returncode == 0 :
145+ print ("Successfully installed all Node.js packages" )
146+ return True
147+ else :
148+ print (f"npm install failed: { result .stderr } " )
149+ return False
150+
151+ except subprocess .CalledProcessError as e :
152+ print (f"Package installation failed: { e } " )
153+ print ("Error output:" , e .stderr )
154+ return False
155+ except Exception as e :
156+ print (f"Unexpected error during package installation: { e } " )
157+ return False
158+
159+ def verify_installation ():
160+ """Verify that Node.js modules are installed correctly"""
161+ script_dir = os .path .dirname (os .path .abspath (__file__ ))
162+
163+ test_script = '''
164+ try {
165+ require('readline-sync');
166+ require('kahoot.js-updated');
167+ require('an-array-of-english-words');
168+ require('request');
169+ require('random-name');
170+ require('console-title');
171+ require('beepbeep');
172+ console.log('VERIFICATION_SUCCESS');
173+ } catch (error) {
174+ console.log('VERIFICATION_FAILED:', error.message);
175+ process.exit(1);
176+ }
177+ '''
178+
179+ test_file = os .path .join (script_dir , 'test_modules.js' )
180+
181+ try :
182+ with open (test_file , 'w' ) as f :
183+ f .write (test_script )
184+
185+ result = subprocess .run (['node' , test_file ], capture_output = True , text = True , cwd = script_dir )
186+
187+ if 'VERIFICATION_SUCCESS' in result .stdout :
188+ print ("All modules verified successfully" )
189+ os .remove (test_file )
190+ return True
191+ else :
192+ print (f"Module verification failed: { result .stdout } " )
193+ os .remove (test_file )
194+ return False
195+
196+ except Exception as e :
197+ print (f"Verification failed: { e } " )
198+ return False
199+
200+ def run_flood_script ():
201+ """Run the flood.js script"""
202+ script_dir = os .path .dirname (os .path .abspath (__file__ ))
203+ flood_js_path = os .path .join (script_dir , 'flood.js' )
204+
205+ if not os .path .exists (flood_js_path ):
206+ print (f"Error: flood.js not found at { flood_js_path } " )
207+ return False
208+
209+ try :
210+ print ("Starting Kahoot flooder..." )
211+ subprocess .run (['node' , flood_js_path ], cwd = script_dir , check = False )
212+ return True
213+ except KeyboardInterrupt :
214+ print ("\n Flooder stopped by user" )
215+ return True
216+ except Exception as e :
217+ print (f"Error running flooder: { e } " )
218+ return False
219+
24220clear () # call check
25221
26222print ("Start???" )
@@ -30,23 +226,78 @@ def clear():
30226if choice == "yes" :
31227 time .sleep (1 )
32228 clear ()
33- print ("Checking if requirment exists: node" )
229+
230+ # Check if Node.js is installed
231+ node_installed , node_version = check_node_installed ()
232+ npm_installed , npm_version = check_npm_installed ()
233+
234+ if not node_installed :
235+ print ("Node.js is not installed!" )
236+ install_nodejs_guide ()
237+ input ("\n Press Enter to return to main menu..." )
238+ clear ()
239+ call (["python" , "../../main.py" ])
240+ exit ()
241+
242+ if not npm_installed :
243+ print ("npm is not installed!" )
244+ print ("npm is usually installed with Node.js. Please reinstall Node.js." )
245+ input ("\n Press Enter to return to main menu..." )
246+ clear ()
247+ call (["python" , "../../main.py" ])
248+ exit ()
249+
250+ print (f"Node.js found: { node_version } " )
251+ print (f"npm found: { npm_version } " )
252+
253+ # Check if node exists
254+ print ("Checking if Node.js is accessible..." )
34255 try :
35256 import node # does node exist
36257 except ModuleNotFoundError :
37- print ("Atempting to install node..." )
258+ print ("Attempting to install node Python package ..." )
38259 time .sleep (2 )
39260 os .system ("pip install node" ) # installation
40261 clear ()
262+
263+ # Install Node.js packages
264+ if not install_node_packages ():
265+ print ("Failed to install required Node.js packages!" )
266+ print ("\n Troubleshooting:" )
267+ print ("1. Check your internet connection" )
268+ print ("2. Try running as administrator/sudo" )
269+ print ("3. Clear npm cache: npm cache clean --force" )
270+ input ("\n Press Enter to return to main menu..." )
271+ clear ()
272+ call (["python" , "../../main.py" ])
273+ exit ()
274+
275+ # Verify installation
276+ if not verify_installation ():
277+ print ("Warning: Some modules failed verification" )
278+ print ("The flooder might still work, but some features may be limited" )
279+
280+ proceed = input ("Continue anyway? (y/n): " ).lower ()
281+ if proceed != 'y' :
282+ clear ()
283+ call (["python" , "../../main.py" ])
284+ exit ()
285+
41286 clear ()
42- print ("Exicuting !" )
287+ print ("Executing !" )
43288 time .sleep (2 )
44289 clear ()
45- subprocess .run (["node" , "Kitty/Flood/flood.js" ])
46290
291+ # Run the flooder
292+ if not run_flood_script ():
293+ print ("Flooder execution failed!" )
294+ input ("\n Press Enter to return to main menu..." )
295+
296+ clear ()
297+ call (["python" , "../../main.py" ])
47298
48299if choice == "no" :
49300 print ("\n Re-Running main menu file!" )
50301 time .sleep (3 )
51302 clear ()
52- call (["python" , "main.py" ])
303+ call (["python" , "../../ main.py" ])
0 commit comments