Skip to content

Commit d5df022

Browse files
authored
Update main.py
1 parent 00175cb commit d5df022

File tree

1 file changed

+148
-31
lines changed

1 file changed

+148
-31
lines changed

Kitty/Flood/main.py

Lines changed: 148 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ def create_package_json():
9999
"description": "Kahoot game flooding utility",
100100
"main": "flood.js",
101101
"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"
102+
"readline-sync": "1.4.10",
103+
"kahoot.js-updated": "3.1.2",
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"
109109
},
110110
"engines": {
111111
"node": ">=12.0.0"
@@ -131,10 +131,39 @@ def install_node_packages():
131131
if not create_package_json():
132132
return False
133133

134+
# Clean install to fix corrupted packages
135+
print("Cleaning previous installations...")
136+
node_modules_path = os.path.join(script_dir, 'node_modules')
137+
package_lock_path = os.path.join(script_dir, 'package-lock.json')
138+
139+
# Remove node_modules and package-lock.json if they exist
140+
try:
141+
if os.path.exists(node_modules_path):
142+
import shutil
143+
shutil.rmtree(node_modules_path)
144+
print("Removed old node_modules directory")
145+
146+
if os.path.exists(package_lock_path):
147+
os.remove(package_lock_path)
148+
print("Removed old package-lock.json")
149+
except Exception as e:
150+
print(f"Warning: Could not clean old files: {e}")
151+
134152
try:
153+
# Clear npm cache
154+
print("Clearing npm cache...")
155+
subprocess.run(
156+
['npm', 'cache', 'clean', '--force'],
157+
cwd=script_dir,
158+
capture_output=True,
159+
text=True,
160+
check=False
161+
)
162+
135163
# Try installing from package.json
164+
print("Installing packages from package.json...")
136165
result = subprocess.run(
137-
['npm', 'install', '--no-fund', '--no-audit'],
166+
['npm', 'install', '--no-fund', '--no-audit', '--force'],
138167
cwd=script_dir,
139168
capture_output=True,
140169
text=True,
@@ -149,9 +178,57 @@ def install_node_packages():
149178
return False
150179

151180
except subprocess.CalledProcessError as e:
152-
print(f"Package installation failed: {e}")
153-
print("Error output:", e.stderr)
154-
return False
181+
print(f"Package installation failed, trying individual installation...")
182+
183+
# Try installing packages individually with specific versions
184+
packages_with_versions = [
185+
"readline-sync@1.4.10",
186+
"kahoot.js-updated@3.1.2",
187+
"an-array-of-english-words@2.0.0",
188+
"request@2.88.2",
189+
"random-name@0.1.2",
190+
"console-title@1.1.0",
191+
"beepbeep@1.3.0"
192+
]
193+
194+
success_count = 0
195+
for package in packages_with_versions:
196+
try:
197+
print(f"Installing {package}...")
198+
subprocess.run(
199+
['npm', 'install', package, '--no-fund', '--no-audit', '--force'],
200+
cwd=script_dir,
201+
capture_output=True,
202+
text=True,
203+
check=True
204+
)
205+
print(f"Successfully installed {package}")
206+
success_count += 1
207+
except subprocess.CalledProcessError:
208+
print(f"Failed to install {package}")
209+
210+
# Special handling for kahoot.js-updated
211+
if "kahoot.js-updated" in package:
212+
print("Trying alternative Kahoot package...")
213+
try:
214+
subprocess.run(
215+
['npm', 'install', 'kahoot.js@3.0.4', '--no-fund', '--no-audit', '--force'],
216+
cwd=script_dir,
217+
capture_output=True,
218+
text=True,
219+
check=True
220+
)
221+
print("Successfully installed alternative kahoot.js package")
222+
success_count += 1
223+
except subprocess.CalledProcessError:
224+
print("Failed to install alternative Kahoot package")
225+
226+
if success_count >= 6: # Allow one failure
227+
print("Most packages installed successfully")
228+
return True
229+
else:
230+
print("Too many packages failed to install")
231+
return False
155232
except Exception as e:
156233
print(f"Unexpected error during package installation: {e}")
157234
return False
@@ -161,19 +238,54 @@ def verify_installation():
161238
script_dir = os.path.dirname(os.path.abspath(__file__))
162239

163240
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);
241+
const modules = [
242+
'readline-sync',
243+
'an-array-of-english-words',
244+
'request',
245+
'random-name',
246+
'console-title',
247+
'beepbeep'
248+
];
249+
250+
// Special handling for Kahoot module with fallback
251+
const kahootModules = ['kahoot.js-updated', 'kahoot.js'];
252+
253+
let success = 0;
254+
let failed = 0;
255+
256+
// Test regular modules
257+
for (const moduleName of modules) {
258+
try {
259+
require(moduleName);
260+
console.log(`SUCCESS: ${moduleName}`);
261+
success++;
262+
} catch (error) {
263+
console.log(`FAILED: ${moduleName} - ${error.message}`);
264+
failed++;
265+
}
266+
}
267+
268+
// Test Kahoot module with fallback
269+
let kahootSuccess = false;
270+
for (const kahootModule of kahootModules) {
271+
try {
272+
require(kahootModule);
273+
console.log(`SUCCESS: ${kahootModule}`);
274+
kahootSuccess = true;
275+
success++;
276+
break;
277+
} catch (error) {
278+
console.log(`FAILED: ${kahootModule} - ${error.message}`);
279+
}
176280
}
281+
282+
if (!kahootSuccess) {
283+
console.log('FAILED: No working Kahoot module found');
284+
failed++;
285+
}
286+
287+
console.log(`SUMMARY: ${success} success, ${failed} failed`);
288+
process.exit(failed > 0 ? 1 : 0);
177289
'''
178290

179291
test_file = os.path.join(script_dir, 'test_modules.js')
@@ -184,14 +296,19 @@ def verify_installation():
184296

185297
result = subprocess.run(['node', test_file], capture_output=True, text=True, cwd=script_dir)
186298

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
299+
# Parse output
300+
for line in result.stdout.split('\n'):
301+
if line.startswith('SUCCESS:'):
302+
print(f"✓ Module verified: {line.split(': ')[1]}")
303+
elif line.startswith('FAILED:'):
304+
print(f"✗ Module failed: {line.split(': ')[1]}")
305+
elif line.startswith('SUMMARY:'):
306+
print(line)
307+
308+
# Clean up test file
309+
os.remove(test_file)
310+
311+
return result.returncode == 0
195312

196313
except Exception as e:
197314
print(f"Verification failed: {e}")

0 commit comments

Comments
 (0)