diff --git a/main.go b/main.go index d959fdc..13fb183 100644 --- a/main.go +++ b/main.go @@ -171,7 +171,7 @@ func run(c *cli.Context) error { WebhookToken: c.String("webhook-token"), Message: c.StringSlice("message"), }, - Form: Form{ + Payload: Payload{ Wait: c.Bool("wait"), Username: c.String("username"), AvatarURL: c.String("avatar-url"), diff --git a/plugin.go b/plugin.go index 19fe1e8..906870c 100644 --- a/plugin.go +++ b/plugin.go @@ -41,21 +41,45 @@ type ( Message []string } - // Form for the plugin. - Form struct { - Wait bool `json:"wait"` - Content string `json:"content"` - Username string `json:"username"` - AvatarURL string `json:"avatar_url"` - TTS bool `json:"tts"` + EmbedFooterObject struct { + Text string `json:"text"` + } + + EmbedAuthorObject struct { + Name string `json:"name"` + URL string `json:"url"` + IconURL string `json:"icon_url"` + } + + EmbedFieldObject struct { + Name string `json:"name"` + Value string `json:"value"` + } + + EmbedObject struct { + Title string `json:"title"` + Description string `json:"description"` + URL string `json:"url"` + Footer *EmbedFooterObject `json:"footer"` + Author *EmbedAuthorObject `json:"author"` + Fields []*EmbedFieldObject `json:"fields"` + } + + Payload struct { + Wait bool `json:"wait"` + Content string `json:"content"` + Username string `json:"username"` + AvatarURL string `json:"avatar_url"` + TTS bool `json:"tts"` + Embeds []*DiscordEmbedObject `json:"embeds"` } // Plugin values. Plugin struct { - Repo Repo - Build Build - Config Config - Form Form + Repo Repo + Build Build + Config Config + Payload Payload } ) @@ -83,10 +107,9 @@ func (p Plugin) Exec() error { } // update content - p.Form.Content = txt - fmt.Println(p.Form) + p.Payload.Content = txt b := new(bytes.Buffer) - json.NewEncoder(b).Encode(p.Form) + json.NewEncoder(b).Encode(p.Payload) _, err = http.Post(webhookURL, "application/json; charset=utf-8", b) if err != nil { diff --git a/plugin_test.go b/plugin_test.go index e87228c..85e9350 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -59,7 +59,7 @@ func TestSendMessage(t *testing.T) { Message: []string{"test one message from drone testing", "test two message from drone testing"}, }, - Form: Form{ + Payload: Payload{ Username: "drone-ci", TTS: false, Wait: false, @@ -74,8 +74,8 @@ func TestSendMessage(t *testing.T) { assert.Nil(t, err) plugin.Config.Message = []string{"I am appleboy"} - plugin.Form.TTS = true - plugin.Form.Wait = true + plugin.Payload.TTS = true + plugin.Payload.Wait = true err = plugin.Exec() assert.Nil(t, err) }