4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-07-03 09:37:44 +00:00

Add support for sending files via webhook (discord) (#872)

This commit is contained in:
MOZGIII
2019-08-29 01:13:10 +03:00
committed by Wim
parent 942d8f1ced
commit cec086994e
3 changed files with 69 additions and 36 deletions

View File

@ -1,7 +1,6 @@
package bdiscord
import (
"encoding/json"
"errors"
"regexp"
"strings"
@ -236,26 +235,3 @@ func enumerateUsernames(s string) []string {
}
return usernames
}
// webhookExecute executes a webhook.
// webhookID: The ID of a webhook.
// token : The auth token for the webhook
// wait : Waits for server confirmation of message send and ensures that the return struct is populated (it is nil otherwise)
func (b *Bdiscord) webhookExecute(webhookID, token string, wait bool, data *discordgo.WebhookParams) (st *discordgo.Message, err error) {
uri := discordgo.EndpointWebhookToken(webhookID, token)
if wait {
uri += "?wait=true"
}
response, err := b.c.RequestWithBucketID("POST", uri, data, discordgo.EndpointWebhookToken("", ""))
if !wait || err != nil {
return nil, err
}
err = json.Unmarshal(response, &st)
if err != nil {
return nil, discordgo.ErrJSONUnmarshal
}
return st, nil
}