-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
268 lines (206 loc) · 7.41 KB
/
setup.py
File metadata and controls
268 lines (206 loc) · 7.41 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#!/usr/bin/env python3
"""
============================================================================
TENBOT SETUP SCRIPT
============================================================================
Quick setup wizard for TENBOT.
This script will:
1. Check Python version
2. Install dependencies
3. Create .env file
4. Initialize database
5. Verify everything is ready
Usage:
python setup.py
"""
import sys
import os
import subprocess
from pathlib import Path
def print_header(text):
"""Print a nice header."""
print("\n" + "=" * 60)
print(text)
print("=" * 60)
def check_python_version():
"""Check if Python version is 3.8+."""
print_header("1. Checking Python Version")
version = sys.version_info
print(f"Python {version.major}.{version.minor}.{version.micro}")
if version.major < 3 or (version.major == 3 and version.minor < 8):
print("❌ Python 3.8 or higher is required!")
print(" Please upgrade Python and try again.")
return False
print("✅ Python version is compatible!")
return True
def install_dependencies():
"""Install required packages."""
print_header("2. Installing Dependencies")
if not Path("requirements.txt").exists():
print("❌ requirements.txt not found!")
return False
print("📦 Installing packages...")
try:
subprocess.check_call([
sys.executable, "-m", "pip", "install", "-r", "requirements.txt", "--quiet"
])
print("✅ All dependencies installed!")
return True
except subprocess.CalledProcessError:
print("❌ Failed to install dependencies!")
print(" Try manually: pip install -r requirements.txt")
return False
def create_env_file():
"""Create .env file from template."""
print_header("3. Setting Up Environment")
if Path(".env").exists():
print("⚠️ .env file already exists!")
response = input("Overwrite? (yes/no): ").lower().strip()
if response != 'yes':
print("Skipping .env creation")
return True
# Get bot token from user
print("\n📝 You'll need your Discord bot token.")
print(" Get it from: https://discord.com/developers/applications")
print()
token = input("Enter your bot token (or press Enter to skip): ").strip()
env_content = f"""# TENBOT Environment Variables
# Generated by setup script
# Discord Bot Token (REQUIRED)
BOT_TOKEN={token if token else 'your_bot_token_here'}
# Future: AI API Keys (optional)
# ANTHROPIC_API_KEY=your_key_here
# OPENAI_API_KEY=your_key_here
"""
with open(".env", "w") as f:
f.write(env_content)
if token:
print("✅ .env file created with your token!")
else:
print("⚠️ .env file created, but you need to add your token!")
print(" Edit .env and add: BOT_TOKEN=your_token_here")
return True
def initialize_database():
"""Initialize the database."""
print_header("4. Initializing Database")
# Check if database already exists
db_path = Path("data/tenbot.db")
if db_path.exists():
print("⚠️ Database already exists!")
response = input("Recreate database? This will DELETE all data! (yes/no): ").lower().strip()
if response != 'yes':
print("Skipping database initialization")
return True
# Delete old database
db_path.unlink()
print("🗑️ Old database deleted")
print("📊 Creating new database...")
try:
import asyncio
from database import Database
async def init_db():
db = Database()
await db.initialize()
await db.close()
asyncio.run(init_db())
print("✅ Database initialized successfully!")
return True
except Exception as e:
print(f"❌ Failed to initialize database: {e}")
return False
def verify_setup():
"""Verify everything is ready."""
print_header("5. Verifying Setup")
checks = []
# Check .env
if Path(".env").exists():
with open(".env", "r") as f:
content = f.read()
if "your_bot_token_here" not in content and "BOT_TOKEN=" in content:
checks.append(("✅", ".env file configured"))
else:
checks.append(("⚠️ ", ".env file exists but needs token"))
else:
checks.append(("❌", ".env file missing"))
# Check database
if Path("data/tenbot.db").exists():
checks.append(("✅", "Database initialized"))
else:
checks.append(("⚠️ ", "Database not found"))
# Check modules
try:
import discord
checks.append(("✅", "discord.py installed"))
except ImportError:
checks.append(("❌", "discord.py not installed"))
try:
import aiosqlite
checks.append(("✅", "aiosqlite installed"))
except ImportError:
checks.append(("❌", "aiosqlite not installed"))
try:
from PIL import Image
import imagehash
checks.append(("✅", "Image libraries installed"))
except ImportError:
checks.append(("❌", "Image libraries not installed"))
# Print results
print()
for status, message in checks:
print(f"{status} {message}")
all_ok = all(status == "✅" for status, _ in checks)
return all_ok
def main():
"""Main setup function."""
print("""
╔══════════════════════════════════════════════════════════╗
║ ║
║ TENBOT SETUP WIZARD ║
║ Ultra Discord Bot for Business Communities ║
║ ║
╚══════════════════════════════════════════════════════════╝
""")
print("This wizard will help you set up TENBOT.")
print()
# Run setup steps
steps = [
("Python version check", check_python_version),
("Installing dependencies", install_dependencies),
("Creating environment file", create_env_file),
("Initializing database", initialize_database),
("Verifying setup", verify_setup)
]
for step_name, step_func in steps:
if not step_func():
print(f"\n❌ Setup failed at: {step_name}")
print(" Please fix the error and run setup again.")
return False
# Success!
print_header("✅ SETUP COMPLETE!")
print("""
🎉 TENBOT is ready to run!
Next steps:
1. Make sure your bot token is in .env file
2. Invite the bot to your server with these permissions:
- Read Messages/View Channels
- Send Messages
- Manage Messages
- Moderate Members
- Manage Roles
- Read Message History
3. Run the bot:
python bot.py
4. Customize settings in config.py
Need help? Check README.md for full documentation!
""")
return True
if __name__ == "__main__":
try:
success = main()
sys.exit(0 if success else 1)
except KeyboardInterrupt:
print("\n\n❌ Setup cancelled by user")
sys.exit(1)
except Exception as e:
print(f"\n❌ Unexpected error: {e}")
sys.exit(1)