mirror of
https://github.com/appleboy/drone-discord.git
synced 2026-06-04 10:23:47 +08:00
@@ -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"),
|
||||
|
||||
@@ -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
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user