Documentation
¶
Overview ¶
Package state provides persistent state management for the bot.
Index ¶
- type DMInfo
- type DailyReportInfo
- type FidoStore
- func (s *FidoStore) ClaimDM(ctx context.Context, userID, prURL string, ttl time.Duration) bool
- func (s *FidoStore) ClaimThread(ctx context.Context, owner, repo string, number int, channelID string, ...) bool
- func (s *FidoStore) Cleanup(ctx context.Context) error
- func (s *FidoStore) Close() error
- func (s *FidoStore) DMInfo(ctx context.Context, userID, prURL string) (DMInfo, bool)
- func (s *FidoStore) DailyReportInfo(ctx context.Context, userID string) (DailyReportInfo, bool)
- func (s *FidoStore) ListDMUsers(ctx context.Context, prURL string) []string
- func (*FidoStore) ListUserMappings(_ context.Context, guildID string) []UserMappingInfo
- func (s *FidoStore) MarkProcessed(ctx context.Context, eventKey string, ttl time.Duration) error
- func (s *FidoStore) PendingDMs(ctx context.Context, before time.Time) ([]*PendingDM, error)
- func (s *FidoStore) QueuePendingDM(ctx context.Context, dm *PendingDM) error
- func (s *FidoStore) RemovePendingDM(ctx context.Context, id string) error
- func (s *FidoStore) SaveDMInfo(ctx context.Context, userID, prURL string, info DMInfo) error
- func (s *FidoStore) SaveDailyReportInfo(ctx context.Context, userID string, info DailyReportInfo) error
- func (s *FidoStore) SaveThread(ctx context.Context, owner, repo string, number int, channelID string, ...) error
- func (s *FidoStore) SaveUserMapping(ctx context.Context, guildID string, info UserMappingInfo) error
- func (s *FidoStore) Thread(ctx context.Context, owner, repo string, number int, channelID string) (ThreadInfo, bool)
- func (s *FidoStore) UserMapping(ctx context.Context, guildID, gitHubUsername string) (UserMappingInfo, bool)
- func (s *FidoStore) WasProcessed(ctx context.Context, eventKey string) bool
- type FidoStoreOption
- func WithClaimStore(s fido.Store[string, time.Time]) FidoStoreOption
- func WithDMStore(s fido.Store[string, DMInfo]) FidoStoreOption
- func WithDMUserStore(s fido.Store[string, dmUserList]) FidoStoreOption
- func WithEventStore(s fido.Store[string, time.Time]) FidoStoreOption
- func WithPendingStore(s fido.Store[string, pendingDMQueue]) FidoStoreOption
- func WithReportStore(s fido.Store[string, DailyReportInfo]) FidoStoreOption
- func WithThreadStore(s fido.Store[string, ThreadInfo]) FidoStoreOption
- func WithUserMappingStore(s fido.Store[string, UserMappingInfo]) FidoStoreOption
- type MemoryStore
- func (s *MemoryStore) ClaimDM(ctx context.Context, userID, prURL string, ttl time.Duration) bool
- func (s *MemoryStore) ClaimThread(ctx context.Context, owner, repo string, number int, channelID string, ...) bool
- func (s *MemoryStore) Cleanup(ctx context.Context) error
- func (*MemoryStore) Close() error
- func (s *MemoryStore) DMInfo(ctx context.Context, userID, prURL string) (DMInfo, bool)
- func (s *MemoryStore) DailyReportInfo(_ context.Context, userID string) (DailyReportInfo, bool)
- func (s *MemoryStore) ListDMUsers(_ context.Context, prURL string) []string
- func (s *MemoryStore) ListUserMappings(ctx context.Context, guildID string) []UserMappingInfo
- func (s *MemoryStore) MarkProcessed(_ context.Context, eventKey string, _ time.Duration) error
- func (s *MemoryStore) PendingDMs(ctx context.Context, before time.Time) ([]*PendingDM, error)
- func (s *MemoryStore) QueuePendingDM(ctx context.Context, dm *PendingDM) error
- func (s *MemoryStore) RemovePendingDM(_ context.Context, id string) error
- func (s *MemoryStore) SaveDMInfo(_ context.Context, userID, prURL string, info DMInfo) error
- func (s *MemoryStore) SaveDailyReportInfo(_ context.Context, userID string, info DailyReportInfo) error
- func (s *MemoryStore) SaveThread(ctx context.Context, owner, repo string, number int, channelID string, ...) error
- func (s *MemoryStore) SaveUserMapping(ctx context.Context, guildID string, info UserMappingInfo) error
- func (s *MemoryStore) Stats() StoreStats
- func (s *MemoryStore) Thread(ctx context.Context, owner, repo string, number int, channelID string) (ThreadInfo, bool)
- func (s *MemoryStore) UserMapping(ctx context.Context, guildID, gitHubUsername string) (UserMappingInfo, bool)
- func (s *MemoryStore) WasProcessed(ctx context.Context, eventKey string) bool
- type PendingDM
- type Store
- type StoreStats
- type ThreadInfo
- type UserMappingInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DMInfo ¶
type DMInfo struct {
SentAt time.Time `json:"sent_at"`
ChannelID string `json:"channel_id"`
MessageID string `json:"message_id"`
MessageText string `json:"message_text"`
LastState string `json:"last_state"` // PR state when DM was sent/updated
}
DMInfo stores DM message info for updating.
type DailyReportInfo ¶
type DailyReportInfo struct {
LastSentAt time.Time `json:"last_sent_at"`
GuildID string `json:"guild_id"`
}
DailyReportInfo tracks daily report state for a user.
type FidoStore ¶
type FidoStore struct {
// contains filtered or unexported fields
}
FidoStore implements Store using fido with CloudRun backend.
Requires these Datastore databases (must be created before use):
- discordian-threads: PR to Discord thread/message mapping
- discordian-dms: DM message tracking
- discordian-dmusers: DM user lists (prURL -> list of user IDs)
- discordian-reports: Daily report tracking
- discordian-pending: Pending DM queue
- discordian-events: Event deduplication (persisted for cross-instance safety)
- discordian-claims: Distributed claims (persisted for cross-instance coordination)
- discordian-usermappings: GitHub username to Discord user ID mappings
func NewFidoStore ¶
func NewFidoStore(ctx context.Context, opts ...FidoStoreOption) (*FidoStore, error)
NewFidoStore creates a new fido-backed store. Uses CloudRun backend which auto-detects environment. Use WithThreadStore, WithDMStore, etc. to inject custom stores for testing.
func (*FidoStore) ClaimDM ¶
ClaimDM attempts to claim a DM for sending. Returns true if the claim was successful, false if another instance already claimed it.
func (*FidoStore) ClaimThread ¶
func (s *FidoStore) ClaimThread(ctx context.Context, owner, repo string, number int, channelID string, ttl time.Duration) bool
ClaimThread attempts to claim a thread for creation. Returns true if the claim was successful, false if another instance already claimed it.
func (*FidoStore) DailyReportInfo ¶
DailyReportInfo retrieves daily report info for a user.
func (*FidoStore) ListDMUsers ¶
ListDMUsers returns all user IDs who received DMs for a PR.
func (*FidoStore) ListUserMappings ¶
func (*FidoStore) ListUserMappings(_ context.Context, guildID string) []UserMappingInfo
ListUserMappings returns all user mappings for a guild.
func (*FidoStore) MarkProcessed ¶
MarkProcessed marks an event as processed.
func (*FidoStore) PendingDMs ¶
PendingDMs returns all pending DMs that should be sent before the given time.
func (*FidoStore) QueuePendingDM ¶
QueuePendingDM adds a pending DM to the queue.
func (*FidoStore) RemovePendingDM ¶
RemovePendingDM removes a pending DM from the queue.
func (*FidoStore) SaveDMInfo ¶
SaveDMInfo stores DM info for a user/PR.
func (*FidoStore) SaveDailyReportInfo ¶
func (s *FidoStore) SaveDailyReportInfo(ctx context.Context, userID string, info DailyReportInfo) error
SaveDailyReportInfo stores daily report info for a user.
func (*FidoStore) SaveThread ¶
func (s *FidoStore) SaveThread(ctx context.Context, owner, repo string, number int, channelID string, info ThreadInfo) error
SaveThread stores thread info for a PR.
func (*FidoStore) SaveUserMapping ¶
func (s *FidoStore) SaveUserMapping(ctx context.Context, guildID string, info UserMappingInfo) error
SaveUserMapping stores user mapping info for a GitHub username.
func (*FidoStore) Thread ¶
func (s *FidoStore) Thread(ctx context.Context, owner, repo string, number int, channelID string) (ThreadInfo, bool)
Thread retrieves thread info for a PR.
func (*FidoStore) UserMapping ¶
func (s *FidoStore) UserMapping(ctx context.Context, guildID, gitHubUsername string) (UserMappingInfo, bool)
UserMapping retrieves user mapping info for a GitHub username in a guild.
type FidoStoreOption ¶
type FidoStoreOption func(*fidoStoreOptions)
FidoStoreOption configures a FidoStore.
func WithClaimStore ¶
WithClaimStore sets a custom store for claim data.
func WithDMStore ¶
func WithDMStore(s fido.Store[string, DMInfo]) FidoStoreOption
WithDMStore sets a custom store for DM data.
func WithDMUserStore ¶
func WithDMUserStore(s fido.Store[string, dmUserList]) FidoStoreOption
WithDMUserStore sets a custom store for DM user list data.
func WithEventStore ¶
WithEventStore sets a custom store for event deduplication data.
func WithPendingStore ¶
func WithPendingStore(s fido.Store[string, pendingDMQueue]) FidoStoreOption
WithPendingStore sets a custom store for pending DM data.
func WithReportStore ¶
func WithReportStore(s fido.Store[string, DailyReportInfo]) FidoStoreOption
WithReportStore sets a custom store for daily report data.
func WithThreadStore ¶
func WithThreadStore(s fido.Store[string, ThreadInfo]) FidoStoreOption
WithThreadStore sets a custom store for thread data.
func WithUserMappingStore ¶
func WithUserMappingStore(s fido.Store[string, UserMappingInfo]) FidoStoreOption
WithUserMappingStore sets a custom store for user mapping data.
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore provides an in-memory implementation of Store.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
NewMemoryStore creates a new in-memory store.
func (*MemoryStore) ClaimDM ¶
ClaimDM attempts to claim a DM for sending. Returns true if the claim was successful, false if another goroutine already claimed it.
func (*MemoryStore) ClaimThread ¶
func (s *MemoryStore) ClaimThread(ctx context.Context, owner, repo string, number int, channelID string, ttl time.Duration) bool
ClaimThread attempts to claim a thread for creation. Returns true if the claim was successful, false if another goroutine already claimed it.
func (*MemoryStore) Cleanup ¶
func (s *MemoryStore) Cleanup(ctx context.Context) error
Cleanup removes old entries from the store.
func (*MemoryStore) Close ¶
func (*MemoryStore) Close() error
Close closes the store (no-op for memory store).
func (*MemoryStore) DailyReportInfo ¶
func (s *MemoryStore) DailyReportInfo(_ context.Context, userID string) (DailyReportInfo, bool)
DailyReportInfo returns daily report info for a user.
func (*MemoryStore) ListDMUsers ¶
func (s *MemoryStore) ListDMUsers(_ context.Context, prURL string) []string
ListDMUsers returns all user IDs who received DMs for a PR.
func (*MemoryStore) ListUserMappings ¶
func (s *MemoryStore) ListUserMappings(ctx context.Context, guildID string) []UserMappingInfo
ListUserMappings returns all user mappings for a guild.
func (*MemoryStore) MarkProcessed ¶
MarkProcessed marks an event as processed.
func (*MemoryStore) PendingDMs ¶
PendingDMs returns DMs scheduled before the given time.
func (*MemoryStore) QueuePendingDM ¶
func (s *MemoryStore) QueuePendingDM(ctx context.Context, dm *PendingDM) error
QueuePendingDM adds a DM to the pending queue.
func (*MemoryStore) RemovePendingDM ¶
func (s *MemoryStore) RemovePendingDM(_ context.Context, id string) error
RemovePendingDM removes a DM from the queue.
func (*MemoryStore) SaveDMInfo ¶
SaveDMInfo saves DM info.
func (*MemoryStore) SaveDailyReportInfo ¶
func (s *MemoryStore) SaveDailyReportInfo(_ context.Context, userID string, info DailyReportInfo) error
SaveDailyReportInfo saves daily report info for a user.
func (*MemoryStore) SaveThread ¶
func (s *MemoryStore) SaveThread(ctx context.Context, owner, repo string, number int, channelID string, info ThreadInfo) error
SaveThread saves thread info for a PR.
func (*MemoryStore) SaveUserMapping ¶
func (s *MemoryStore) SaveUserMapping(ctx context.Context, guildID string, info UserMappingInfo) error
SaveUserMapping saves user mapping info for a GitHub username.
func (*MemoryStore) Stats ¶
func (s *MemoryStore) Stats() StoreStats
Stats returns current store statistics.
func (*MemoryStore) Thread ¶
func (s *MemoryStore) Thread(ctx context.Context, owner, repo string, number int, channelID string) (ThreadInfo, bool)
Thread returns thread info for a PR in a channel.
func (*MemoryStore) UserMapping ¶
func (s *MemoryStore) UserMapping(ctx context.Context, guildID, gitHubUsername string) (UserMappingInfo, bool)
UserMapping returns user mapping info for a GitHub username in a guild.
func (*MemoryStore) WasProcessed ¶
func (s *MemoryStore) WasProcessed(ctx context.Context, eventKey string) bool
WasProcessed checks if an event was already processed.
type PendingDM ¶
type PendingDM struct {
SendAt time.Time `json:"send_at"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
ID string `json:"id"`
UserID string `json:"user_id"`
PRURL string `json:"pr_url"`
MessageText string `json:"message_text"`
GuildID string `json:"guild_id"`
Org string `json:"org"`
RetryCount int `json:"retry_count"`
}
PendingDM represents a scheduled DM notification.
type Store ¶
type Store interface {
// Thread/post tracking - maps PR to Discord thread/message
Thread(ctx context.Context, owner, repo string, number int, channelID string) (ThreadInfo, bool)
SaveThread(ctx context.Context, owner, repo string, number int, channelID string, info ThreadInfo) error
// Distributed claim mechanism to prevent duplicate thread/message creation across instances
// Returns true if claim was successful, false if another instance already claimed it
ClaimThread(ctx context.Context, owner, repo string, number int, channelID string, ttl time.Duration) bool
// DM tracking
DMInfo(ctx context.Context, userID, prURL string) (DMInfo, bool)
SaveDMInfo(ctx context.Context, userID, prURL string, info DMInfo) error
ListDMUsers(ctx context.Context, prURL string) []string // Returns all user IDs who received DMs for this PR
// Distributed claim mechanism for DMs
ClaimDM(ctx context.Context, userID, prURL string, ttl time.Duration) bool
// Event deduplication
WasProcessed(ctx context.Context, eventKey string) bool
MarkProcessed(ctx context.Context, eventKey string, ttl time.Duration) error
// Pending DM queue
QueuePendingDM(ctx context.Context, dm *PendingDM) error
PendingDMs(ctx context.Context, before time.Time) ([]*PendingDM, error)
RemovePendingDM(ctx context.Context, id string) error
// Daily report tracking
DailyReportInfo(ctx context.Context, userID string) (DailyReportInfo, bool)
SaveDailyReportInfo(ctx context.Context, userID string, info DailyReportInfo) error
// User mapping tracking (GitHub username <-> Discord user ID)
UserMapping(ctx context.Context, guildID, gitHubUsername string) (UserMappingInfo, bool)
SaveUserMapping(ctx context.Context, guildID string, info UserMappingInfo) error
ListUserMappings(ctx context.Context, guildID string) []UserMappingInfo
// Lifecycle
Cleanup(ctx context.Context) error
Close() error
}
Store provides persistent state operations.
type StoreStats ¶
StoreStats contains store statistics.
type ThreadInfo ¶
type ThreadInfo struct {
UpdatedAt time.Time `json:"updated_at"`
ThreadID string `json:"thread_id"`
MessageID string `json:"message_id"`
ChannelID string `json:"channel_id"`
ChannelType string `json:"channel_type"` // "forum" or "text"
LastState string `json:"last_state"`
MessageText string `json:"message_text"`
}
ThreadInfo stores Discord thread/message info for a PR.