summaryrefslogtreecommitdiff
path: root/app/cmd/main.go
diff options
context:
space:
mode:
authorsoler_j <soler_j@etna-alternance.net>2025-04-29 10:50:45 +0200
committersoler_j <soler_j@etna-alternance.net>2025-04-29 10:50:45 +0200
commit3d143c271394a942dff5d979ffc8d2c55f1644dc (patch)
tree7191a49baacebe7a8bbb46b82c8d8f1f96bf5f0e /app/cmd/main.go
parent22dc3abd0c866e4ee292a4648c3dac5cda2583cb (diff)
Refactor Dockerfile and bot code: remove ZeroMQ dependencies, enhance bot initialization with HTTP webhook server, and improve error handling for bot startup.
Diffstat (limited to 'app/cmd/main.go')
-rw-r--r--app/cmd/main.go32
1 files changed, 31 insertions, 1 deletions
diff --git a/app/cmd/main.go b/app/cmd/main.go
index 49e645f..2232c8e 100644
--- a/app/cmd/main.go
+++ b/app/cmd/main.go
@@ -40,7 +40,37 @@ func main() {
ProcessID: fmt.Sprint(len(botList) + 5555), // or any unique identifier
}
- bot, err := internal.Start(bot)
+ // Let's check if this discord bot exists
+ if _, ok := botList[botToken]; ok {
+ log.Printf("[SERVER] Bot already running: %s", botToken)
+ http.Error(w, "Bot already running", http.StatusConflict)
+ return
+ }
+
+ // let's check if it exist on Discord
+ httpClient := &http.Client{}
+ req, err := http.NewRequest("GET", "https://discord.com/api/v10/users/@me", nil)
+ if err != nil {
+ log.Printf("[SERVER] Error creating request: %v", err)
+ http.Error(w, "Error creating request", http.StatusInternalServerError)
+ return
+ }
+ req.Header.Set("Authorization", "Bot "+botToken)
+ resp, err := httpClient.Do(req)
+ if err != nil {
+ log.Printf("[SERVER] Error sending request: %v", err)
+ http.Error(w, "Error sending request", http.StatusInternalServerError)
+ return
+ }
+ defer resp.Body.Close()
+ if resp.StatusCode != http.StatusOK {
+ log.Printf("[SERVER] Bot not found: %s", botToken)
+ http.Error(w, "Bot not found", http.StatusNotFound)
+ return
+ }
+ // let's check if the bot is already running
+
+ bot, err = internal.Start(bot)
if err != nil {
log.Printf("[SERVER] Error starting bot: %v", err)
http.Error(w, "Error starting bot", http.StatusInternalServerError)