mbox

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackfillClient

type BackfillClient interface {
	GetChatHistory(ctx context.Context, channel string, payload map[string]any) error
	GetRawJSON(key string) []byte
}

BackfillClient is the minimal interface required to perform a channel backfill.

type BackfillOptions

type BackfillOptions struct {
	Channels      []string
	MaxPerChannel int
	// ResetCursor clears each channel's saved cursor before crawling so
	// the run starts from the most recent page (i.e. "from now") rather
	// than resuming from the oldest message previously ingested. Used to
	// re-pull current pages after a server-side schema change adds new
	// fields that older stored messages are missing.
	ResetCursor bool
}

BackfillOptions controls the behaviour of a Backfill run.

type BackfillReport

type BackfillReport struct {
	Channels map[string]ChannelReport
}

BackfillReport summarises the results of a Backfill run.

type Blocklist

type Blocklist struct {
	// contains filtered or unexported fields
}

Blocklist is a persisted set of spam senders for a single agent. Entries are stored verbatim (preserving display case) but matched case-insensitively against either a message's sender_id or sender display name. It is backed by a JSON array of strings on disk, e.g. data/agents/<agent>/spam_list.json.

func LoadBlocklist

func LoadBlocklist(path string) (*Blocklist, error)

LoadBlocklist reads the blocklist at path. A missing file yields an empty blocklist with no error so first-time callers don't have to special-case it.

func (*Blocklist) Add

func (b *Blocklist) Add(entry string) (bool, error)

Add inserts entry into the blocklist and persists it. It returns (true, nil) if the entry was newly added, or (false, nil) if it was already present (case-insensitive).

func (*Blocklist) IsBlocked

func (b *Blocklist) IsBlocked(senderID, sender string) bool

IsBlocked reports whether a message from senderID/sender should be treated as spam. A match on either field (case-insensitive) blocks the message.

func (*Blocklist) List

func (b *Blocklist) List() []string

List returns the blocked entries in their original case, sorted.

func (*Blocklist) Remove

func (b *Blocklist) Remove(entry string) (bool, error)

Remove deletes entry from the blocklist and persists the change. It returns (true, nil) if the entry was present and removed, or (false, nil) if it was not in the list (case-insensitive).

type ChannelReport

type ChannelReport struct {
	Fetched int
	Capped  bool
}

ChannelReport holds per-channel backfill statistics.

type Ingester

type Ingester struct {
	// contains filtered or unexported fields
}

Ingester converts incoming server push events into stored Messages.

func NewIngester

func NewIngester(store *Store) *Ingester

NewIngester creates an Ingester backed by the given Store.

func (*Ingester) Backfill

func (ing *Ingester) Backfill(ctx context.Context, client BackfillClient, opts BackfillOptions) (BackfillReport, error)

Backfill crawls history for each channel in opts.Channels, storing any messages that are not already present in the Store. It stops per channel when it encounters a message ID that already exists, when MaxPerChannel is reached, or when the server returns an empty page.

func (*Ingester) HandlePolled

func (ing *Ingester) HandlePolled(msg serverapi.ChatMessage)

HandlePolled ingests a message discovered via polling get_chat_history.

func (*Ingester) HandlePush

func (ing *Ingester) HandlePush(msg serverapi.ChatMessage)

HandlePush converts a server-pushed ChatMessage and stores it in the mbox. Duplicate messages (same ID) are silently ignored. HandlePush ingests a message received via server push event.

func (*Ingester) SetBlocklist

func (ing *Ingester) SetBlocklist(bl *Blocklist)

SetBlocklist attaches a spam blocklist. Incoming messages whose sender_id or sender display name is blocked are stored directly in the spam folder (SpamAt set) regardless of which path ingested them. Pass nil to disable.

func (*Ingester) SetSelfID

func (ing *Ingester) SetSelfID(id string)

SetSelfID registers the current player's internal ID so outbound echoes (messages where SenderID == selfID) can be tagged Source="sent" at ingest time. Pass an empty string to disable tagging.

type Message

type Message struct {
	ID           string
	Channel      string
	SenderID     string
	Sender       string
	Content      string
	TargetID     string
	TargetName   string
	TimestampUTC time.Time
	IngestedAt   time.Time
	ReadAt       *time.Time
	DeletedAt    *time.Time
	// SpamAt is set when the message is in the spam folder — either because it
	// was ingested from a blocked sender or flagged via MarkSpamBySender.
	// Spam messages are excluded from default queries (List, Search,
	// UnreadCounts), like soft-deleted ones.
	SpamAt *time.Time
	Source string
	// EmpireOfficial is true when the server delivered this message through
	// the verified empire-leadership pipeline or from an empire NPC. When
	// set, SenderID is the empire's own ID. Use it to detect player
	// impersonation of empire officials. (server v0.294.0+)
	EmpireOfficial bool
}

Message represents a single chat message stored in the mbox.

type Query

type Query struct {
	Channel        string
	SenderID       string
	UnreadOnly     bool
	IncludeDeleted bool
	// IncludeSpam includes spam-flagged messages in results (they are
	// excluded by default). SpamOnly restricts results to spam-flagged
	// messages — the "spam folder" view. SpamOnly takes precedence.
	IncludeSpam bool
	SpamOnly    bool
	Before      time.Time
	After       time.Time
	Limit       int
	Offset      int
}

Query holds filter parameters for retrieving messages. By default, soft-deleted messages are excluded; set IncludeDeleted to see them.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is a SQLite-backed message store for a single agent's inbox.

func Open

func Open(dbPath string) (*Store, error)

Open opens (or creates) the SQLite database at dbPath, enables WAL mode, and runs any pending schema migrations.

func (*Store) ClearCursor

func (s *Store) ClearCursor(channel string) error

ClearCursor removes the backfill cursor for a channel so the next Backfill starts from the most recent page (i.e. "from now") instead of resuming from the oldest previously-seen message.

func (*Store) Close

func (s *Store) Close() error

Close releases the database connection.

func (*Store) Cursor

func (s *Store) Cursor(channel string) (time.Time, bool, error)

Cursor returns the oldest-seen timestamp for a channel's backfill cursor. Returns (time.Time{}, false, nil) if no cursor exists for the channel.

func (*Store) Get

func (s *Store) Get(id string) (*Message, error)

Get retrieves a single message by ID. Returns nil, nil if not found. Returns soft-deleted messages as well; callers that want to exclude them should check the returned Message.DeletedAt field.

func (*Store) GetByPrefix

func (s *Store) GetByPrefix(prefix string) (*Message, error)

GetByPrefix retrieves a single message whose ID starts with prefix. Returns nil, nil if no match. Returns an error if the prefix matches more than one message (caller must disambiguate by using a longer prefix or the full ID).

func (*Store) Ingest

func (s *Store) Ingest(msg Message) (bool, error)

Ingest stores a message in the database. It returns (true, nil) if the message was newly inserted, or (false, nil) if the ID already existed.

func (*Store) List

func (s *Store) List(q Query) ([]Message, error)

List returns messages matching the query, ordered newest-first. If q.Limit is 0 it defaults to 20.

func (*Store) MarkChannelRead

func (s *Store) MarkChannelRead(channel string) error

MarkChannelRead marks all unread messages in a channel as read.

func (*Store) MarkRead

func (s *Store) MarkRead(ids ...string) error

MarkRead marks the given message IDs as read if they are currently unread.

func (*Store) MarkSpamBySender

func (s *Store) MarkSpamBySender(idOrName string) (int, error)

MarkSpamBySender flags every non-spam message whose sender_id or sender display name matches idOrName (case-insensitive) as spam, moving it into the spam folder. It returns the number of messages newly flagged.

func (*Store) Restore

func (s *Store) Restore(id string) error

Restore clears the soft-delete flag on a message, making it visible to default queries again. No-op if not deleted.

func (*Store) Search

func (s *Store) Search(text string, q Query) ([]Message, error)

Search performs a full-text search over messages, with optional Query filters. Default limit is 20 if q.Limit is 0.

func (*Store) SearchCount

func (s *Store) SearchCount(text string, q Query) (int, error)

SearchCount returns the total number of messages matching the FTS query, applying the same filters (Channel, SenderID, UnreadOnly, IncludeDeleted) as Search but ignoring Limit/Offset.

func (*Store) SetCursor

func (s *Store) SetCursor(channel string, oldest time.Time, capped bool) error

SetCursor upserts the backfill cursor for a channel.

func (*Store) SoftDelete

func (s *Store) SoftDelete(id string) error

SoftDelete marks a message as deleted. It is hidden from default queries (List, Search) but remains in the store and can be undone with Restore. No-op if the message is already deleted.

func (*Store) SourceCounts

func (s *Store) SourceCounts() (map[string]int, error)

SourceCounts returns a map of source → message count.

func (*Store) UnmarkSpamBySender

func (s *Store) UnmarkSpamBySender(idOrName string) (int, error)

UnmarkSpamBySender clears the spam flag on every spam message whose sender_id or sender display name matches idOrName (case-insensitive), restoring it to its original folder. It returns the number of messages restored.

func (*Store) UnreadCounts

func (s *Store) UnreadCounts() (map[string]int, error)

UnreadCounts returns a map of channel → unread message count.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL