Documentation
¶
Overview ¶
Package topdiscordlist talks to the Top Discord List developer API and verifies the vote webhooks it sends you.
Index ¶
- Constants
- func Sign(secret string, timestamp int64, body string) string
- func VerifySignature(secret, header, body string, tolerance time.Duration) bool
- func VerifySignatureAt(secret, header, body string, tolerance time.Duration, now time.Time) bool
- func WebhookHandler(secret string, fn func(Payload)) http.HandlerFunc
- type APIError
- type Client
- func (c *Client) HasVoted(ctx context.Context, discordID string) (*VoteCheck, error)
- func (c *Client) HasVotedByUserID(ctx context.Context, userID string) (*VoteCheck, error)
- func (c *Client) Listing(ctx context.Context) (*Listing, error)
- func (c *Client) PostStats(ctx context.Context, slug string, stats Stats) error
- func (c *Client) Votes(ctx context.Context, limit, page int) ([]Voter, error)
- type Listener
- type Listing
- type Payload
- type Stats
- type VoteCheck
- type VoteEvent
- type Voter
Constants ¶
const ( DefaultBaseURL = "https://topdiscordlist.com/api" SignatureHeader = "X-TDL-Signature" EventHeader = "X-TDL-Event" DeliveryHeader = "X-TDL-Delivery" DefaultTolerance = 5 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func VerifySignature ¶
VerifySignature checks an X-TDL-Signature header against the raw request body. Pass a tolerance of 0 to skip the freshness check.
func VerifySignatureAt ¶
VerifySignatureAt is VerifySignature with the current time supplied by the caller, which makes replaying a stored delivery in tests straightforward.
func WebhookHandler ¶
func WebhookHandler(secret string, fn func(Payload)) http.HandlerFunc
WebhookHandler verifies each delivery and hands the payload to fn. It replies before fn runs, so a slow reward never causes a retry.
Types ¶
type Client ¶
Client calls the developer API with your listing token.
func (*Client) HasVotedByUserID ¶
HasVotedByUserID is the same check, keyed by Top Discord List user id.
type Listener ¶
Listener streams votes over a WebSocket. Your bot connects out to us, so it works fine without a public URL.
func NewListener ¶
NewListener returns a listener for the given listing token.
type Listing ¶
type Listing struct {
Type string `json:"type"`
ID string `json:"id"`
Slug string `json:"slug"`
Name string `json:"name"`
VoteCount int `json:"voteCount"`
}
Listing describes your server or bot listing.
type Payload ¶
type Payload struct {
Event string `json:"event"`
DeliveryID string `json:"deliveryId"`
SentAt string `json:"sentAt"`
Vote struct {
ID string `json:"id"`
VotedAt string `json:"votedAt"`
IsTest bool `json:"isTest"`
} `json:"vote"`
User struct {
ID string `json:"id"`
Username string `json:"username"`
DiscordID string `json:"discordId"`
} `json:"user"`
Listing struct {
Type string `json:"type"`
ID string `json:"id"`
Slug string `json:"slug"`
Name string `json:"name"`
VoteCount int `json:"voteCount"`
} `json:"listing"`
Streak struct {
Listing int `json:"listing"`
Global int `json:"global"`
} `json:"streak"`
}
Payload is the body of a vote webhook.
type Stats ¶
type Stats struct {
ServerCount int `json:"serverCount"`
UserCount *int `json:"userCount,omitempty"`
ShardCount *int `json:"shardCount,omitempty"`
}
Stats are the counts a bot reports about itself.
type VoteCheck ¶
type VoteCheck struct {
Voted bool `json:"voted"`
VotedAt string `json:"votedAt"`
ExpiresAt string `json:"expiresAt"`
}
VoteCheck reports whether a user's vote is still inside the cooldown window.
type VoteEvent ¶
type VoteEvent struct {
Type string `json:"type"`
VoteID string `json:"voteId"`
UserID string `json:"userId"`
Username string `json:"username"`
TargetType string `json:"targetType"`
TargetID string `json:"targetId"`
Slug string `json:"slug"`
Name string `json:"name"`
VoteCount int `json:"voteCount"`
VotedAt string `json:"votedAt"`
}
VoteEvent is a single vote pushed over the vote stream.
Directories
¶
| Path | Synopsis |
|---|---|
|
Command conformance checks this package against the shared signature test vectors.
|
Command conformance checks this package against the shared signature test vectors. |