Skip to content

Commit

Permalink
fix(discord): properly escape string
Browse files Browse the repository at this point in the history
  • Loading branch information
yyewolf committed Nov 18, 2023
1 parent f5efb68 commit e46c60a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@

# Dependency directories (remove the comment below to include it)
# vendor/
.env
16 changes: 14 additions & 2 deletions internal/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ package discord

import (
"bytes"
"encoding/json"
"gocd/internal/config"
"net/http"
)

type RequestBody struct {
Content string `json:"content"`
}

func SendMessage(msg string) error {
var c = config.GetConfig()

Expand All @@ -15,9 +20,16 @@ func SendMessage(msg string) error {
return nil
}

data := []byte(`{"content":"` + msg + `"}`)
d := RequestBody{
Content: msg,
}

data, err := json.Marshal(d)
if err != nil {
return err
}
body := bytes.NewBuffer(data)

_, err := http.Post(webhook, "application/json", body)
_, err = http.Post(webhook, "application/json", body)
return err
}
3 changes: 1 addition & 2 deletions internal/docker/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@ func UpdateContainers(token string) error {
go func() {
mutex.Lock()
list := containers[token]
fmt.Println(list)
defer mutex.Unlock()
listCopy := make([]*Container, len(list))
copy(listCopy, list)

// Prepare discord's message
message := fmt.Sprintf("Updating %d containers\n", len(list))
for _, c := range list {
message += fmt.Sprintf("- %s\n", c.Inspect.Name)
message += fmt.Sprintf("- **%s**\n", c.Inspect.Name)
}

discord.SendMessage(message)
Expand Down

0 comments on commit e46c60a

Please sign in to comment.