Documentation
¶
Overview ¶
Package groups owns group admission, management and voluntary entertainment.
Index ¶
- Constants
- Variables
- func OpenAPI() []byte
- type Action
- type Actor
- type Analyzer
- type Authorizer
- type Blacklist
- type BlacklistInput
- type Bot
- type BotIdentity
- type BotScope
- type Bulk
- type BulkItem
- type BulkResult
- type CardField
- type Command
- type Delivery
- type EligibilityChange
- type Event
- type Facts
- type FactsProvider
- type GroupConfig
- type GroupConfigInput
- type GroupCounts
- type GroupSettings
- type GroupSummary
- type Hit
- type IdentityResolver
- type ManagedGroup
- type Member
- type Message
- type MyGroup
- type OutboxReader
- type Outcome
- type OwnerGroupRecord
- type Page
- type Report
- type Repository
- type Result
- type Row
- type Service
- func (s *Service) Actions(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Action], error)
- func (s *Service) Batch(ctx context.Context, p account.Principal, g, key string, in Bulk) (BulkResult, error)
- func (s *Service) Blacklist(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Blacklist], error)
- func (s *Service) Blacklists(ctx context.Context, p account.Principal, key string, in BlacklistInput) (Result, error)
- func (s *Service) Cleanup(ctx context.Context, g, cursor string) (string, error)
- func (s *Service) Command(ctx context.Context, p account.Principal, g, key string, cmd Command) (Result, error)
- func (s *Service) Configuration(ctx context.Context, p account.Principal, g string) (GroupConfig, error)
- func (s *Service) Configure(ctx context.Context, p account.Principal, key string, in GroupConfigInput) (GroupConfig, error)
- func (s *Service) Consume(ctx context.Context, event UpstreamEvent) error
- func (s *Service) Deliveries(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Delivery], error)
- func (s *Service) Execute(ctx context.Context, g, id string) (Action, error)
- func (s *Service) Fanout(ctx context.Context, e Event) error
- func (s *Service) Groups(ctx context.Context, p account.Principal, cursor string, limit int) (Page[GroupSummary], error)
- func (s *Service) GroupsForOwner(ctx context.Context, owner account.Principal, cursor string, limit int) (Page[ManagedGroup], error)
- func (s *Service) Hits(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Hit], error)
- func (s *Service) Ingest(ctx context.Context, g string, event Event, m Message) error
- func (s *Service) MemberEvent(ctx context.Context, g string, event Event, owner string) error
- func (s *Service) Members(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Member], error)
- func (s *Service) Messages(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Message], error)
- func (s *Service) MyGroups(ctx context.Context, p account.Principal, cursor string, limit int) (Page[MyGroup], error)
- func (s *Service) Progress(ctx context.Context, p account.Principal, g string) (Member, error)
- func (s *Service) Recover(ctx context.Context, g, cursor string) (string, error)
- func (s *Service) Reports(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Report], error)
- func (s *Service) Subscriptions(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Subscription], error)
- func (s *Service) Sweep(ctx context.Context, g, cursor string) (string, error)
- func (s *Service) Warnings(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Warnings], error)
- func (s *Service) Watch(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Watch], error)
- type Subscription
- type Tx
- type UpstreamEvent
- type Warnings
- type Watch
Constants ¶
const MaxEventGroups = 1000
A bounded transaction provides all-or-nothing fanout. Overflow is a failure, not a partial acknowledgement; Sweep remains available for periodic recovery.
const OutboxChannel = "groups_outbox"
Variables ¶
var ( ErrUnprocessable = errors.New("groups_unprocessable") ErrInvalid = errors.New("groups_invalid_request") ErrUnauthenticated = errors.New("groups_unauthenticated") ErrForbidden = errors.New("groups_forbidden") ErrNotFound = errors.New("groups_not_found") ErrConflict = errors.New("groups_conflict") ErrDisabled = errors.New("groups_disabled") ErrCooldown = errors.New("groups_cooldown") )
Functions ¶
Types ¶
type Action ¶
type Action struct {
LeaseUntil *time.Time `json:"lease_until,omitempty"`
ID string `json:"id"`
Group string `json:"group"`
Actor Actor `json:"actor"`
Capability string `json:"capability"`
Command Command `json:"command"`
State string `json:"state"`
Result string `json:"result"`
Created time.Time `json:"created"`
}
type Authorizer ¶
type BlacklistInput ¶
type BotIdentity ¶
type BotScope ¶
BotScope identifies a registered adapter instance. Platform is onebot or official; connect is never a bot transport or evidence of a shared QQ identity.
type BulkResult ¶
type BulkResult struct {
Items []BulkItem `json:"items"`
}
type CardField ¶
CardField separates disclosure permission from source availability. Only allowed and available fields may enter a group card; absence is not a violation.
type EligibilityChange ¶
type Facts ¶
type Facts struct {
StudentKnown bool
StageKnown bool
Bound bool
Student bool
Alumni bool
Temporary bool
Fields map[string]CardField
}
Facts contains current eligibility and card disclosure decisions supplied by backend. Bound is true only when all three independent QQ bindings are currently complete.
type FactsProvider ¶
type FactsProvider interface {
GroupFacts(ctx context.Context, principal account.Principal, owner, school string) (Facts, error)
}
FactsProvider is owned by groups; backend implements all provider mappings. Unknown stages and provider failures must not be turned into valid eligibility.
type GroupConfig ¶
type GroupConfig struct {
GroupSettings
Number string `json:"number"`
Revision int64 `json:"revision"`
PasswordSet bool `json:"password_set"`
}
type GroupConfigInput ¶
type GroupConfigInput struct {
GroupSettings
Number *string `json:"number,omitempty"`
ExpectedRevision int64 `json:"expected_revision"`
Password *string `json:"password,omitempty"`
}
type GroupCounts ¶
type GroupCounts struct{ Members, Pending int64 }
type GroupSettings ¶
type GroupSettings struct {
Name string `json:"name"`
BotEnabled bool `json:"bot_enabled"`
Welcome string `json:"welcome"`
RulesTemplate string `json:"rules_template"`
CheckCard bool `json:"check_card"`
RemindCard bool `json:"remind_card"`
BlockLinks bool `json:"block_links"`
FrequencySeconds int64 `json:"frequency_seconds"`
FrequencyLimit int64 `json:"frequency_limit"`
WarningLimit int64 `json:"warning_limit"`
ID string `json:"id"`
School string `json:"school"`
Mode string `json:"mode"`
RequireStudent bool `json:"require_student"`
AcceptAlumni bool `json:"accept_alumni"`
AcceptTemporary bool `json:"accept_temporary"`
GraceSeconds int64 `json:"grace_seconds"`
ReminderSeconds int64 `json:"reminder_seconds"`
RetentionSeconds int64 `json:"retention_seconds"`
CardTemplate string `json:"card_template"`
AutoCard bool `json:"auto_card"`
DiceSides int64 `json:"dice_sides"`
MuteProbability int64 `json:"mute_probability"`
MuteSeconds int64 `json:"mute_seconds"`
CooldownSeconds int64 `json:"cooldown_seconds"`
Pity int64 `json:"pity"`
Keywords []string `json:"keywords"`
RepeatThreshold int64 `json:"repeat_threshold"`
AutoActions []string `json:"auto_actions"`
}
type GroupSummary ¶
type GroupSummary struct {
ID string `json:"id"`
School string `json:"school"`
Name string `json:"name"`
Number string `json:"number"`
MemberCount int64 `json:"member_count"`
BotEnabled bool `json:"bot_enabled"`
RequireStudent bool `json:"require_student"`
PendingCount int64 `json:"pending_count"`
Revision int64 `json:"revision"`
}
type IdentityResolver ¶
type IdentityResolver interface {
ResolveOwner(ctx context.Context, principal account.Principal, identity BotIdentity) (string, error)
ResolveBotIdentity(ctx context.Context, principal account.Principal, owner string, bot BotScope) (BotIdentity, error)
}
IdentityResolver is the backend bot bridge's consumer-owned port. The provider must check the current service identity, bot scope and binding on every call. Errors use groups sentinels (errors.Is); unavailable is never a missing binding.
type ManagedGroup ¶
ManagedGroup identifies a configured group; it deliberately omits card fields, messages, raw QQ identifiers and other membership data.
type Member ¶
type Member struct {
ID string `json:"id"`
Joined bool `json:"joined"`
Owner string `json:"owner"`
State string `json:"state"`
Deadline time.Time `json:"deadline"`
Reminder time.Time `json:"reminder"`
Password bool `json:"password"`
Exempt bool `json:"exempt"`
Extended bool `json:"extended"`
Failures int64 `json:"failures"`
LastPlay time.Time `json:"last_play"`
MutedUntil time.Time `json:"muted_until"`
}
type MyGroup ¶
type MyGroup struct {
ID string `json:"id"`
Name string `json:"name"`
School string `json:"school"`
Number string `json:"number"`
Joined bool `json:"joined"`
State string `json:"state"`
Deadline *time.Time `json:"deadline"`
RequiresPassword bool `json:"requires_password"`
Eligibility string `json:"eligibility"`
MissingConditions []string `json:"missing_conditions"`
UnknownConditions []string `json:"unknown_conditions"`
NextActions []string `json:"next_actions"`
}
type OutboxReader ¶
type OutboxReader interface {
PendingOutbox(ctx context.Context, limit int, excludeSubjects []string) ([]Event, error)
ConfirmOutbox(ctx context.Context, id string) error
}
OutboxReader is a trusted backend relay port. Exclusions are applied in SQL before ordering and limiting. Confirm only after all consumers commit durably.
type Outcome ¶
Bot must deduplicate by Action.ID and query actual outcomes after timeouts. Lookup returns found=false only when no execution took place. Never guess success.
type OwnerGroupRecord ¶
type OwnerGroupRecord struct {
Config GroupConfig
Member Member
}
OwnerGroupRecord is internal repository data. Public owner queries still return only ManagedGroup; MyGroups explicitly projects a separate user-safe shape.
type Report ¶
type Report struct {
ID string `json:"id"`
Reporter string `json:"reporter"`
Message string `json:"message"`
Reason string `json:"reason"`
State string `json:"state"`
Analysis string `json:"analysis,omitempty"`
Suggestions []string `json:"suggestions,omitempty"`
Feedback string `json:"feedback,omitempty"`
}
type Row ¶
type Row struct {
ID string
Data json.RawMessage
}
type Service ¶
type Service struct {
PlatformIdentity admin.Identity
Repo Repository
Auth Authorizer
Facts FactsProvider
FactsPrincipal account.Principal
Bot Bot
AI Analyzer
Now func() time.Time
Random func(int64) (int64, error)
}
func (*Service) Blacklists ¶
func (*Service) Configuration ¶
func (*Service) Configure ¶
func (s *Service) Configure(ctx context.Context, p account.Principal, key string, in GroupConfigInput) (GroupConfig, error)
func (*Service) Consume ¶
func (s *Service) Consume(ctx context.Context, event UpstreamEvent) error
Consume atomically records inbox/revision and reevaluates all affected groups. Source data only identifies the owner: current facts always come from Facts.
func (*Service) Deliveries ¶
func (*Service) Execute ¶
Execute serializes claims before an external call. Interrupted calls remain unknown and are resolved via Lookup on the next invocation with the same ID.
func (*Service) Fanout ¶
Fanout consumes committed disposition events, independently queuing each enabled recipient. Delivery state is the recipient action's actual state.
func (*Service) GroupsForOwner ¶
func (s *Service) GroupsForOwner(ctx context.Context, owner account.Principal, cursor string, limit int) (Page[ManagedGroup], error)
GroupsForOwner is a trusted backend query, not an HTTP authorization bypass. It returns joined, non-removed memberships whose group configuration exists.
func (*Service) Ingest ¶
Ingest is a trusted backend boundary, never mounted as a public route. Only authenticated bot adapters may provide the actual group and sender.
func (*Service) MemberEvent ¶
MemberEvent receives verified group membership from the host bot adapter. A web application alone cannot claim that a QQ user has already joined.
func (*Service) MyGroups ¶
func (s *Service) MyGroups(ctx context.Context, p account.Principal, cursor string, limit int) (Page[MyGroup], error)
MyGroups shares the indexed reverse lookup behind GroupsForOwner, including active applications. The only owner is the authenticated principal; no caller supplied owner, admin scope, or content fields enter the response.
func (*Service) Recover ¶
Recover is called by the host for expired execution leases, with bounded pages.
func (*Service) Subscriptions ¶
func (*Service) Sweep ¶
Sweep is a bounded host job for qualification deadlines and reminders. Host persists its cursor and periodically starts at the beginning for new deadlines.
type Subscription ¶
type Tx ¶
type Tx interface {
Get(string, string, any) error
Put(string, string, any) error
Delete(string, string) error
List(string, string, int) ([]Row, error)
PendingActions(string) (int, error)
GroupCounts([]string) (map[string]GroupCounts, error)
OwnerGroups(owner, cursor string, limit int, includeApplicants bool) (Page[ManagedGroup], error)
OwnerGroupRecords(owner, cursor string, limit int, includeApplicants bool) (Page[OwnerGroupRecord], error)
Emit(Event) error
Accept(Event) (bool, error)
}
type UpstreamEvent ¶
type UpstreamEvent struct {
SpecVersion string `json:"specversion"`
ID string `json:"id"`
Source string `json:"source"`
Type string `json:"type"`
Subject string `json:"subject"`
Time time.Time `json:"time"`
DataContentType string `json:"datacontenttype"`
SchoolID string `json:"schoolid,omitempty"`
Data EligibilityChange `json:"data"`
}
UpstreamEvent uses the providers' public CloudEvents shape. Preserve source and subject: verification uses object streams; qq-binding uses an owner stream.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package accountquery provides the module-owned account investigation port.
|
Package accountquery provides the module-owned account investigation port. |
|
Package httpapi accepts principals only from the host authentication middleware.
|
Package httpapi accepts principals only from the host authentication middleware. |
|
Package postgres owns all groups SQL.
|
Package postgres owns all groups SQL. |
|
Package sdk provides primitives to interact with the openapi HTTP API.
|
Package sdk provides primitives to interact with the openapi HTTP API. |