add Embed payload

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2017-06-14 11:03:44 +08:00
parent 100ff18145
commit e4a13b26fb
3 changed files with 41 additions and 18 deletions
+1 -1
View File
@@ -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"),
+37 -14
View File
@@ -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 {
+3 -3
View File
@@ -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)
}