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 Analytics
- type AnalyticsDay
- type Client
- func (c *Client) Analytics(ctx context.Context, days int) (*Analytics, error)
- 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) errordeprecated
- func (c *Client) ReportStats(ctx context.Context, 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 Analytics ¶ added in v1.0.1
type Analytics struct {
Listing *Listing `json:"listing"`
Window struct {
Days int `json:"days"`
From string `json:"from"`
To string `json:"to"`
} `json:"window"`
Totals struct {
Impressions int `json:"impressions"`
Clicks int `json:"clicks"`
Joins int `json:"joins"`
Votes int `json:"votes"`
ClickThroughRate float64 `json:"clickThroughRate"`
JoinRate float64 `json:"joinRate"`
} `json:"totals"`
Daily []AnalyticsDay `json:"daily"`
}
Analytics is the impressions, clicks, joins, and votes for your listing.
type AnalyticsDay ¶ added in v1.0.1
type AnalyticsDay struct {
Date string `json:"date"`
Impressions int `json:"impressions"`
Clicks int `json:"clicks"`
Joins int `json:"joins"`
Votes int `json:"votes"`
}
AnalyticsDay is one day of listing analytics.
type Client ¶
Client calls the developer API with your listing token.
func (*Client) Analytics ¶ added in v1.0.1
Analytics returns your listing's impressions, clicks, joins, and votes. Days must be between 1 and 90; anything outside that falls back to 7.
func (*Client) HasVotedByUserID ¶
HasVotedByUserID is the same check, keyed by Top Discord List user id.
func (*Client) ReportStats ¶ added in v1.0.1
ReportStats reports your bot's own server, user, and shard counts. The listing token says which listing this is, so no slug is needed.
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. |