summaryrefslogtreecommitdiffstats
path: root/bridge/discord/helpers.go
diff options
context:
space:
mode:
Diffstat (limited to 'bridge/discord/helpers.go')
-rw-r--r--bridge/discord/helpers.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/bridge/discord/helpers.go b/bridge/discord/helpers.go
index 7b060817..e150d192 100644
--- a/bridge/discord/helpers.go
+++ b/bridge/discord/helpers.go
@@ -1,6 +1,7 @@
package bdiscord
import (
+ "encoding/json"
"errors"
"regexp"
"strings"
@@ -187,3 +188,26 @@ 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
+}