-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_experiences.py
More file actions
116 lines (95 loc) · 3.62 KB
/
Copy pathsetup_experiences.py
File metadata and controls
116 lines (95 loc) · 3.62 KB
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
#!/usr/bin/env python3
"""
Experience Configuration Setup Script
This script runs before the Node.js application to configure allowed chat experiences.
"""
import json
import os
import sys
from pathlib import Path
def clear_screen():
"""Clear the terminal screen"""
os.system('cls' if os.name == 'nt' else 'clear')
def get_input(prompt):
"""Get user input with proper handling"""
try:
return input(prompt).strip()
except KeyboardInterrupt:
print("\n\n❌ Setup cancelled by user.")
sys.exit(1)
def validate_experience_id(experience_id):
"""Basic validation for experience ID format"""
if not experience_id:
return False
# Basic check - experience IDs usually start with 'exp_' or similar
if len(experience_id) < 5:
return False
return True
def main():
"""Main setup function"""
clear_screen()
print("=" * 60)
print("🔧 EXPERIENCE CONFIGURATION SETUP")
print("=" * 60)
print("This bot will only process image messages from the channels you configure here.")
print("You can find experience IDs in your Whop dashboard under Chat experiences.")
print("The Node.js application will NOT start until you complete this setup.\n")
# Get number of experiences
while True:
try:
num_str = get_input("How many chat experiences do you want to allow? (1-10): ")
num_experiences = int(num_str)
if 1 <= num_experiences <= 10:
break
else:
print("❌ Please enter a number between 1 and 10.")
except ValueError:
print("❌ Please enter a valid number.")
print(f"\nYou will now enter {num_experiences} experience ID(s).")
print("Example: exp_abc123def456\n")
allowed_experiences = []
# Get experience IDs
for i in range(1, num_experiences + 1):
while True:
experience_id = get_input(f"Enter experience ID {i}/{num_experiences}: ")
if validate_experience_id(experience_id):
allowed_experiences.append(experience_id)
print(f"✅ Added: {experience_id}")
break
else:
print("❌ Invalid experience ID format. Please try again.")
# Save configuration
config = {
"allowedExperiences": allowed_experiences
}
# Determine config file path
script_dir = Path(__file__).parent
config_file = script_dir / "src" / "config" / "experiences.json"
try:
# Ensure directory exists
config_file.parent.mkdir(parents=True, exist_ok=True)
# Save config
with open(config_file, 'w', encoding='utf-8') as f:
json.dump(config, f, indent=2, ensure_ascii=False)
print("\n" + "=" * 60)
print("✅ CONFIGURATION SAVED SUCCESSFULLY!")
print("=" * 60)
print("Valid experiences configured:")
for i, exp_id in enumerate(allowed_experiences, 1):
print(f" {i}. {exp_id}")
print(f"\nConfiguration saved to: {config_file}")
print("The Node.js application will now start...")
print("=" * 60 + "\n")
return True
except Exception as e:
print(f"\n❌ Error saving configuration: {e}")
print(f"Config file path: {config_file}")
return False
if __name__ == "__main__":
success = main()
if success:
print("✅ Setup completed successfully!")
print("The Node.js application will start automatically...")
else:
print("❌ Setup failed. Please try again.")
sys.exit(1)