added logout

This commit is contained in:
2026-01-24 15:23:28 +11:00
parent 73a5c9726b
commit 4dec97def8
14 changed files with 327 additions and 191 deletions

View File

@@ -1,6 +1,11 @@
package discord
import (
"net/http"
"sync"
"time"
"git.haelnorr.com/h/golib/hlog"
"github.com/bwmarrin/discordgo"
"github.com/pkg/errors"
)
@@ -24,3 +29,33 @@ func (s *OAuthSession) GetUser() (*discordgo.User, error) {
}
return user, nil
}
// APIClient is an HTTP client wrapper that handles Discord API rate limits
type APIClient struct {
cfg *Config
client *http.Client
logger *hlog.Logger
mu sync.RWMutex
buckets map[string]*RateLimitState
trustedHost string
}
// NewAPIClient creates a new Discord API client with rate limit handling
func NewAPIClient(cfg *Config, logger *hlog.Logger, trustedhost string) (*APIClient, error) {
if cfg == nil {
return nil, errors.New("config cannot be nil")
}
if logger == nil {
return nil, errors.New("logger cannot be nil")
}
if trustedhost == "" {
return nil, errors.New("trustedhost cannot be empty")
}
return &APIClient{
client: &http.Client{Timeout: 30 * time.Second},
logger: logger,
buckets: make(map[string]*RateLimitState),
cfg: cfg,
trustedHost: trustedhost,
}, nil
}