-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-docker.sh
More file actions
executable file
·214 lines (184 loc) · 7.86 KB
/
Copy pathsetup-docker.sh
File metadata and controls
executable file
·214 lines (184 loc) · 7.86 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
#!/usr/bin/env bash
# ==============================================================================
# 🤖 Advanced Discord Bot - Docker Auto Setup Script
# ==============================================================================
# Rich terminal colors & styling
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0;37m' # No Color
BOLD='\033[1m'
clear
echo -e "${PURPLE}${BOLD}"
echo " ╔═══════════════════════════════════════════════════════════════╗"
echo " ║ 🤖 ADVANCED DISCORD BOT SETUP 🤖 ║"
echo " ╠═══════════════════════════════════════════════════════════════╣"
echo " ║ Automated Docker Deployment & Configuration Script ║"
echo " ╚═══════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
# Check dependencies
echo -e "${BLUE}[1/4] Checking system prerequisites...${NC}"
dependencies=("git" "docker")
missing_deps=()
for dep in "${dependencies[@]}"; do
if ! command -v "$dep" &> /dev/null; then
missing_deps+=("$dep")
fi
done
# Check docker compose (could be 'docker-compose' or 'docker compose')
has_compose=false
if docker compose version &> /dev/null; then
has_compose=true
DOCKER_COMPOSE_CMD="docker compose"
elif command -v docker-compose &> /dev/null; then
has_compose=true
DOCKER_COMPOSE_CMD="docker-compose"
fi
if [ ${#missing_deps[@]} -ne 0 ] || [ "$has_compose" = false ]; then
echo -e "${RED}❌ Missing required dependencies:${NC}"
for dep in "${missing_deps[@]}"; do
echo -e " - ${YELLOW}$dep${NC}"
done
if [ "$has_compose" = false ]; then
echo -e " - ${YELLOW}docker-compose / docker compose${NC}"
fi
echo -e "\n${YELLOW}Please install the missing tools and run this script again.${NC}"
exit 1
fi
echo -e "${GREEN}✅ All prerequisites satisfied!${NC}\n"
# Repository navigation/cloning
echo -e "${BLUE}[2/4] Setting up working directory...${NC}"
if [ -f "docker-compose.yml" ] && [ -f "Dockerfile" ] && [ -f "package.json" ]; then
echo -e "${GREEN}✅ Running inside local repository directory.${NC}\n"
else
echo -e "${YELLOW}📂 No repository files detected. Cloning repo...${NC}"
git clone https://github.com/AdvancedDiscordBot/Advanced-Discord-Bot.git advanced-discord-bot
cd advanced-discord-bot || { echo -e "${RED}❌ Failed to enter directory 'advanced-discord-bot'${NC}"; exit 1; }
echo -e "${GREEN}✅ Successfully cloned and entered repository.${NC}\n"
fi
# Interactive Configuration
echo -e "${BLUE}[3/4] Configuring environment variables...${NC}"
echo -e "${CYAN}Please enter the required information below:${NC}\n"
# Discord Token
while true; do
read -rp "🔑 Enter your Discord Bot Token: " DISCORD_TOKEN
if [ -n "$DISCORD_TOKEN" ]; then
break
fi
echo -e "${RED}⚠️ Bot token is required!${NC}"
done
# Client ID
while true; do
read -rp "🆔 Enter your Discord Bot Client ID: " CLIENT_ID
if [[ "$CLIENT_ID" =~ ^[0-9]+$ ]]; then
break
fi
echo -e "${RED}⚠️ Client ID must be a numeric value!${NC}"
done
# Owner IDs
while true; do
read -rp "👑 Enter Owner Discord User ID(s) (comma-separated): " OWNER_IDS
if [ -n "$OWNER_IDS" ]; then
break
fi
echo -e "${RED}⚠️ At least one Owner ID is required!${NC}"
done
# Gemini API Key
read -rp "🤖 Enter Google Gemini API Key (press Enter to skip): " GEMINI_API_KEY
# Base URL / Domain
read -rp "🌐 Enter Bot Base URL [http://localhost:3210]: " BOT_API_BASE_URL
BOT_API_BASE_URL=${BOT_API_BASE_URL:-"http://localhost:3210"}
# Discord OAuth Secret
while true; do
read -rp "🔐 Enter Discord OAuth Client Secret: " DISCORD_OAUTH_CLIENT_SECRET
if [ -n "$DISCORD_OAUTH_CLIENT_SECRET" ]; then
break
fi
echo -e "${RED}⚠️ Client Secret is required for dashboard login!${NC}"
done
# Trial Mode
read -rp "⚖️ Enable Trial Mode? (Resets DB & exits servers every 5 hrs) (y/N): " TRIAL_CHOICE
if [[ "$TRIAL_CHOICE" =~ ^[Yy]$ ]]; then
TRIAL_MODE="true"
else
TRIAL_MODE="false"
fi
# Generate session secret
SESSION_SECRET=$(openssl rand -hex 32 2>/dev/null || tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 32 | head -n 1)
# Write .env file
echo -e "\n${BLUE}Generating .env file...${NC}"
cat <<EOT > .env
# 🤖 Advanced Discord Bot - Environment Configuration
# Automatically generated by setup-docker.sh on $(date)
# ==============================================
# 🔑 Discord Bot Configuration
# ==============================================
DISCORD_TOKEN=${DISCORD_TOKEN}
CLIENT_ID=${CLIENT_ID}
GUILD_ID=
# ==============================================
# 🗄️ Database Configuration (Configured for Docker Mongo)
# ==============================================
MONGODB_URI=mongodb://advance:bot@mongo:27017/discord-bot?authSource=admin
# ==============================================
# 🤖 AI Configuration
# ==============================================
GEMINI_API_KEY=${GEMINI_API_KEY}
# ==============================================
# 🔌 Internal API & OAuth Configuration
# ==============================================
BOT_API_ENABLED=true
BOT_API_PORT=3210
BOT_API_BASE_URL=${BOT_API_BASE_URL}
DISCORD_OAUTH_CLIENT_ID=${CLIENT_ID}
DISCORD_OAUTH_CLIENT_SECRET=${DISCORD_OAUTH_CLIENT_SECRET}
DISCORD_OAUTH_REDIRECT_URI=${BOT_API_BASE_URL}/auth/discord/callback
SESSION_SECRET=${SESSION_SECRET}
DASHBOARD_REDIRECT_URL=${BOT_API_BASE_URL}/dashboard
OWNER_IDS=${OWNER_IDS}
# ==============================================
# 🌐 Deployment Configuration
# ==============================================
NODE_ENV=production
TRIAL_MODE=${TRIAL_MODE}
# ==============================================
# 📊 Feature Toggles
# ==============================================
ENABLE_AI_ASSISTANT=true
ENABLE_POINTS_SYSTEM=true
ENABLE_XP_SYSTEM=true
ENABLE_TICKET_SYSTEM=true
ENABLE_MODERATION=true
# ==============================================
# 🔌 Plugin System Configuration
# ==============================================
PLUGIN_REGISTRY_URL=https://github.com/AdvancedDiscordBot/registry/blob/main/plugins.json
EOT
echo -e "${GREEN}✅ .env file successfully created!${NC}\n"
# Run Docker Compose
echo -e "${BLUE}[4/4] Starting docker containers...${NC}"
echo -e "${CYAN}Building bot image and launching database. Please wait...${NC}"
if $DOCKER_COMPOSE_CMD up --build -d; then
echo -e "\n${GREEN}🎉 Advanced Discord Bot is now running in Docker!${NC}"
echo -e "=========================================================="
echo -e "🌐 Dashboard is hosted at: ${BOLD}${BOT_API_BASE_URL}/dashboard${NC}"
echo -e "=========================================================="
echo -e "\n${YELLOW}${BOLD}⚠️ IMPORTANT NEXT STEP:${NC}"
echo -e "Go to the Discord Developer Portal (${UNDERLINE}https://discord.com/developers/applications${NC}) and:"
echo -e "1. Under ${BOLD}OAuth2 -> General${NC}, add this Redirect URI:"
echo -e " ${GREEN}${BOT_API_BASE_URL}/auth/discord/callback${NC}"
echo -e "2. Save Changes."
echo -e "3. Under ${BOLD}Bot${NC}, ensure the following ${BOLD}Privileged Gateway Intents${NC} are enabled:"
echo -e " - Presence Intent"
echo -e " - Server Members Intent"
echo -e " - Message Content Intent"
echo -e "4. Save Changes."
echo -e "\nEnjoy using Advanced Discord Bot! 🤖✨"
else
echo -e "\n${RED}❌ Docker Compose failed to start the containers.${NC}"
echo -e "Please check docker logs by running: ${YELLOW}docker logs adb-bot${NC}"
exit 1
fi