remote

package
v2.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 12 Imported by: 0 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

Overview

Package remote holds what every phone surface shares: one-time pairing codes, the per-chat allowlist, and the throttle that keeps progress messages from flooding a phone. The surfaces themselves live in remote/telegram and remote/discord.

Index

Constants

View Source
const (

	// DefaultPairTTL is how long a minted code can be redeemed.
	DefaultPairTTL = 10 * time.Minute
)

Variables

View Source
var (
	ErrNoCode    = errors.New("no pairing code is active; run the pairing command on the host again")
	ErrWrongCode = errors.New("that code is not valid")
	ErrLockedOut = errors.New("too many wrong codes; wait a few minutes and try again")
)

Errors returned by Redeem. They are safe to show to the person in the chat.

View Source
var ErrStaticChat = errors.New("this chat is listed in the config, so it cannot be unpaired from here")

ErrStaticChat means a chat is listed in the config. Only the config can remove it, so /unpair from the phone cannot touch it.

Functions

func Chunk

func Chunk(text string, n int) []string

Chunk splits text into pieces of at most n bytes for platforms with a message size limit. It breaks at the last newline that fits, else at the last rune boundary, and never splits a UTF-8 sequence.

Types

type Allowlist

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

Allowlist is the set of chats allowed to talk to Scribe on one surface. Static ids come from config and are never written. Ids added by pairing are saved to a state file (mode 0600) so a pairing survives a restart. Surfaces default-deny: an empty allowlist admits no chat.

func NewAllowlist

func NewAllowlist(path string, static []string) (*Allowlist, error)

NewAllowlist loads the paired ids from path (a missing file is empty) and merges static. An empty path keeps pairings in memory only.

func (*Allowlist) Add

func (a *Allowlist) Add(chat string) error

Add pairs chat and saves the pairing. Adding a chat twice is fine.

func (*Allowlist) Allowed

func (a *Allowlist) Allowed(chat string) bool

Allowed reports whether chat may use the surface.

func (*Allowlist) IsStatic

func (a *Allowlist) IsStatic(chat string) bool

IsStatic reports whether chat is listed in the config (and so cannot be removed from a phone or the TUI).

func (*Allowlist) Members

func (a *Allowlist) Members() []string

Members returns every allowed chat id, sorted.

func (*Allowlist) Remove

func (a *Allowlist) Remove(chat string) (bool, error)

Remove unpairs chat and saves the change. It reports whether the chat was paired. A static chat returns ErrStaticChat and is left alone.

func (*Allowlist) RemoveAll

func (a *Allowlist) RemoveAll() (int, error)

RemoveAll unpairs every paired chat (static chats stay) and saves the change. It returns how many chats were unpaired.

type Pairing

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

Pairing mints one-time codes and redeems them from chats. A code is shown on the host and typed into the chat that should be paired. Five wrong attempts from one chat lock that chat out for ten minutes. The lockout is per chat, so one chat cannot exhaust another's attempts.

func NewPairing

func NewPairing(ttl time.Duration) *Pairing

NewPairing returns a Pairing whose codes last ttl (DefaultPairTTL if zero).

func (*Pairing) Mint

func (p *Pairing) Mint() (string, time.Time, error)

Mint replaces any active code with a new one and returns it with its expiry.

func (*Pairing) Redeem

func (p *Pairing) Redeem(chat, input string) error

Redeem checks input from chat against the active code. A correct code is spent: it cannot pair a second chat. Matching ignores case and surrounding space.

type Throttle

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

Throttle lets an event through at most once per interval for each key. Progress lines use it so a chatty tool cannot flood a phone.

func NewThrottle

func NewThrottle(d time.Duration) *Throttle

NewThrottle returns a Throttle that allows one event per key every d.

func (*Throttle) Allow

func (t *Throttle) Allow(key string) bool

Allow reports whether an event for key may go out now, and records it if so.

Directories

Path Synopsis
Package discord is Scribe's Discord surface, and it is notify-only.
Package discord is Scribe's Discord surface, and it is notify-only.
Package telegram is Scribe's Telegram surface.
Package telegram is Scribe's Telegram surface.

Jump to

Keyboard shortcuts

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