Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
added test mdoule & fixed stoopid stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Apr 23, 2021
1 parent 8c40ba0 commit 065c5f7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/endpoints/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
UpdateWebhok = NewAPIRoute(PATCH, "/webhooks/{webhook.id}/{token}")
DeleteWebhook = NewAPIRoute(DELETE, "/webhooks/{webhook.id}/{token}")

CreateWebhookMessage = NewAPIRoute(POST, "/webhooks/{webhook.id}/{webhook.token}")
CreateWebhookMessage = NewAPIRoute(POST, "/webhooks/{webhook.id}/{webhook.token}?wait=true")
UpdateWebhookMessage = NewAPIRoute(POST, "/webhooks/{webhook.id}/{webhook.token}/messages/{message.id}")
DeleteWebhookMessage = NewAPIRoute(POST, "/webhooks/{webhook.id}/{webhook.token}/messages/{message.id}")
)
Expand Down
8 changes: 4 additions & 4 deletions disgohook.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"github.com/DisgoOrg/log"
)

func NewWebhookByToken(webhookToken string, logger log.Logger) (api.Webhook, error) {
func NewWebhookByToken(logger log.Logger, webhookToken string) (api.Webhook, error) {
webhookTokenSplit := strings.SplitN(webhookToken, "/", 2)
if len(webhookTokenSplit) != 2 {
return nil, api.ErrMalformedWebhookToken
}
return internal.NewWebhookImpl(nil, logger, webhookTokenSplit[0], webhookTokenSplit[1]), nil
return internal.NewWebhookImpl(nil, logger, webhookTokenSplit[1], webhookTokenSplit[0]), nil
}

func NewWebhookByID(id string, token string) (api.Webhook, error) {
return nil, nil
func NewWebhookByIDToken(logger log.Logger, webhookID string, webhookToken string) (api.Webhook, error) {
return internal.NewWebhookImpl(nil, logger, webhookID, webhookToken), nil
}
1 change: 0 additions & 1 deletion internal/rest_client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (r *RestClientImpl) Request(route endpoints.CompiledAPIRoute, rqBody interf
}

rq.Header.Set("User-Agent", r.UserAgent())
rq.Header.Set("Authorization", "Bot "+r.webhook.Token())
rq.Header.Set("Content-Type", "application/json")

rs, err := r.client.Do(rq)
Expand Down
12 changes: 12 additions & 0 deletions test/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/DisgoOrg/disgo/disgohook

go 1.16

replace (
github.com/DisgoOrg/disgohook => ../
)

require (
github.com/DisgoOrg/disgohook v1.0.1
github.com/sirupsen/logrus v1.8.1
)
9 changes: 9 additions & 0 deletions test/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
github.com/DisgoOrg/log v1.0.3 h1:IjmZQQu/kuBIui22EdXmxzQGYwcPCJEkXa0Fe6W9fJk=
github.com/DisgoOrg/log v1.0.3/go.mod h1:KFGKhBQr37d6rxZ7p2bmc8BEmDH8DZbtgdlJDSCsE7I=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
24 changes: 24 additions & 0 deletions test/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"os"

"github.com/DisgoOrg/disgohook"
"github.com/sirupsen/logrus"
)

func main() {
logger := logrus.New()
logger.SetLevel(logrus.InfoLevel)
logger.Info("starting test...")
webhook, err := disgohook.NewWebhookByToken(os.Getenv("webhook_token"), logger)
if err != nil {
logger.Errorf("failed to create webhook: %s", err)
return
}
_, err = webhook.SendContent("test")
if err != nil {
logger.Errorf("failed to send webhook message: %s", err)
return
}
}

0 comments on commit 065c5f7

Please sign in to comment.