#!/usr/bin/env python3 """ RedFlag Discord Setup Assistant Helps configure Discord bot for server management """ import os import sys from dotenv import load_dotenv def setup_discord(): """Interactive Discord setup""" print("šŸš€ RedFlag Discord Bot Setup Assistant") print("=" * 50) # Check if .env exists env_file = ".env" if not os.path.exists(env_file): print(f"šŸ“ Creating {env_file} from template...") if os.path.exists(".env.example"): import shutil shutil.copy(".env.example", env_file) print(f"āœ… Created {env_file} from .env.example") else: # Create basic .env file with open(env_file, 'w') as f: f.write("# Discord Bot Configuration\n") f.write("DISCORD_BOT_TOKEN=your_bot_token_here\n") f.write("DISCORD_SERVER_ID=your_server_id_here\n") f.write("DISCORD_APPLICATION_ID=your_app_id_here\n") f.write("DISCORD_PUBLIC_KEY=your_public_key_here\n") f.write("\n# Server Settings\n") f.write("SERVER_NAME=RedFlag Security\n") f.write("ADMIN_ROLE_ID=\n") print(f"āœ… Created basic {env_file}") # Load environment load_dotenv(env_file) print("\nšŸ“‹ Discord Configuration Checklist:") print("1. āœ… Discord Developer Portal: https://discord.com/developers/applications") print("2. āœ… Create Application: Click 'New Application'") print("3. āœ… Create Bot: Go to 'Bot' → 'Add Bot'") print("4. āœ… Enable Privileged Intents:") print(" - āœ… Server Members Intent") print(" - āœ… Server Management Intent") print(" - āœ… Message Content Intent") print("5. āœ… OAuth2 URL Generator:") print(" - āœ… Scope: bot") print(" - āœ… Scope: applications.commands") print(" - āœ… Permissions: Administrator (or specific)") print("6. āœ… Invite Bot to Server") print("7. āœ… Copy Values Below:") print("\nšŸ”‘ Required Discord Information:") print("From your Discord Developer Portal, copy these values:") print("-" * 50) # Get user input (with masking) def get_sensitive_input(prompt, key): value = input(f"{prompt}: ").strip() if value: # Update .env file update_env_file(key, value) # Show masked version masked_value = value[:8] + "..." + value[-4:] if len(value) > 12 else value print(f"āœ… {key}: {masked_value}") return value def update_env_file(key, value): """Update .env file with value""" env_path = os.path.join(os.path.dirname(__file__), env_file) # Read current file with open(env_path, 'r') as f: lines = f.readlines() # Update or add the line updated = False for i, line in enumerate(lines): if line.startswith(f"{key}="): lines[i] = f"{key}={value}\n" updated = True break if not updated: lines.append(f"{key}={value}\n") # Write back to file with open(env_path, 'w') as f: f.writelines(lines) # Get required values bot_token = get_sensitive_input("Discord Bot Token", "DISCORD_BOT_TOKEN") server_id = get_sensitive_input("Discord Server ID", "DISCORD_SERVER_ID") app_id = get_sensitive_input("Discord Application ID", "DISCORD_APPLICATION_ID") public_key = get_sensitive_input("Discord Public Key", "DISCORD_PUBLIC_KEY") print("-" * 50) print("šŸŽ‰ Configuration Complete!") print("\nšŸ“ Next Steps:") print("1. Run the Discord bot:") print(" cd /home/memory/Desktop/Projects/RedFlag/discord") print(" python discord_manager.py") print("\n2. Available Commands (slash commands):") print(" • /status - Show server status") print(" • /create-channels - Create standard channels") print(" • /list-channels - List all channels") print(" • /send-message - Send message to channel") print(" • /create-category - Create new category") print(" • /help - Show all commands") print("\nšŸ”’ Security Note:") print("• Your bot token is stored locally in .env") print("• Never share the .env file") print("• The bot only has Administrator permissions you grant it") print("• All actions are logged locally") def main(): """Main setup function""" setup_discord() if __name__ == "__main__": main()