primebot

package module
v1.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2023 License: MIT Imports: 14 Imported by: 1

README

primebot

primebot is a bot for posting prime numbers to places like Mastodon or Twitter. It's meant to replace primes while being both tested and maintainable.

You can follow the magic at:

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCanceled is returned from a generator when its context is cancelled
	ErrCanceled = errors.New("cancelled")
	// ErrOverflow is returned from a generator when the generator number type's
	// max is overflowed
	ErrOverflow = errors.New("overflow")
)
View Source
var (
	MastodonStatusRex = regexp.MustCompile(`^<p>([0-9]+)</p>$`)
)

Functions

This section is empty.

Types

type Bot

type Bot interface {
	Start(context.Context) error
}

type BotOpts

type BotOpts struct {
	Logger         *log.Logger
	ServiceTimeout time.Duration
}

type CompositeGenerator

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

func NewCompositeGenerator

func NewCompositeGenerator(start *big.Int) *CompositeGenerator

func (*CompositeGenerator) Generate

func (c *CompositeGenerator) Generate(ctx context.Context) (*big.Int, error)

func (*CompositeGenerator) SetStart

func (c *CompositeGenerator) SetStart(start *big.Int)

type Fetcher

type Fetcher interface {
	Fetch(context.Context) (*Status, error)
}

type Generator

type Generator interface {
	SetStart(*big.Int)
	Generate(context.Context) (*big.Int, error)
}

type IntervalTicker

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

func NewIntervalTicker

func NewIntervalTicker(d time.Duration) *IntervalTicker

func (IntervalTicker) Interval

func (i IntervalTicker) Interval() time.Duration

func (*IntervalTicker) Start

func (i *IntervalTicker) Start(ctx context.Context, first time.Duration) (c chan time.Time)

type MastodonClient

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

func NewMastodonClient

func NewMastodonClient(ctx context.Context, config *MastodonConfig) (*MastodonClient, error)

func (*MastodonClient) Fetch

func (m *MastodonClient) Fetch(ctx context.Context) (*Status, error)

func (*MastodonClient) Post

func (m *MastodonClient) Post(ctx context.Context, status *big.Int) error

type MastodonConfig

type MastodonConfig struct {
	Server       string
	ClientID     string
	ClientSecret string
	AccessToken  string
	AccountID    string
}

type MastodonPrimesClient

type MastodonPrimesClient interface {
	GetAccountStatuses(context.Context, mastodon.ID, *mastodon.Pagination) ([]*mastodon.Status, error)
	PostStatus(context.Context, *mastodon.Toot) (*mastodon.Status, error)
}

type Poster

type Poster interface {
	Post(context.Context, *big.Int) error
}

type PrimeBot

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

func NewPrimeBot

func NewPrimeBot(f Fetcher, t Ticker, g Generator, p Poster, opts *BotOpts) *PrimeBot

func (*PrimeBot) Start

func (p *PrimeBot) Start(ctx context.Context) error

type ProbablyPrimeGenerator

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

ProbablyPrimeGenerator is a prime number generator that uses the math/big package's ProbablyPrime; it is 100% accurate up to the max value of a uint, at which point it overflows; this cannot be used to generate any prime number larger than 2**64

func NewProbablyPrimeGenerator

func NewProbablyPrimeGenerator(start *big.Int) *ProbablyPrimeGenerator

NewProbablyPrimeGenerator creates a new ProbablyPrimeGenerator, starting at the given number

func (*ProbablyPrimeGenerator) Generate

func (p *ProbablyPrimeGenerator) Generate(ctx context.Context) (*big.Int, error)

Generate generates the next prime number from the ProbablyPrime generator

func (*ProbablyPrimeGenerator) SetStart

func (p *ProbablyPrimeGenerator) SetStart(start *big.Int)

type RandFetcher

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

func NewRandFetcher

func NewRandFetcher() *RandFetcher

func (*RandFetcher) Fetch

func (r *RandFetcher) Fetch(ctx context.Context) (*Status, error)

type Status

type Status struct {
	LastStatus *big.Int
	Posted     time.Time
}

type Ticker

type Ticker interface {
	Start(context.Context, time.Duration) chan time.Time
	Interval() time.Duration
}

type TrialDivisionGenerator

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

func NewTrialDivisionGenerator

func NewTrialDivisionGenerator(start *big.Int) *TrialDivisionGenerator

func (*TrialDivisionGenerator) Generate

func (t *TrialDivisionGenerator) Generate(ctx context.Context) (*big.Int, error)

func (*TrialDivisionGenerator) SetStart

func (t *TrialDivisionGenerator) SetStart(start *big.Int)

type TwitterClient

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

func NewTwitterClient

func NewTwitterClient(c *http.Client) (*TwitterClient, error)

func (*TwitterClient) Fetch

func (t *TwitterClient) Fetch(_ context.Context) (*Status, error)

func (*TwitterClient) Post

func (t *TwitterClient) Post(_ context.Context, status *big.Int) error

type TwitterPrimesStatusService

type TwitterPrimesStatusService interface {
	Update(string, *twitter.StatusUpdateParams) (*twitter.Tweet, *http.Response, error)
}

type TwitterPrimesTimelineService

type TwitterPrimesTimelineService interface {
	UserTimeline(*twitter.UserTimelineParams) ([]twitter.Tweet, *http.Response, error)
}

type WritePoster

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

func NewStdoutPoster

func NewStdoutPoster() *WritePoster

func NewWriterPoster

func NewWriterPoster(w io.Writer) *WritePoster

func (*WritePoster) Post

func (w *WritePoster) Post(ctx context.Context, status *big.Int) error

Directories

Path Synopsis
cmd
primebot-stdout command

Jump to

Keyboard shortcuts

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