raid

package
v0.0.0-...-11da6b2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2023 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const MapHeight = 670
View Source
const MapWidth = 1000
View Source
const URLPattern = "https://t.me/s/%s"

Variables

View Source
var AuthorSel = cascadia.MustCompile(".tgme_widget_message_author span")
View Source
var DateSel = cascadia.MustCompile(".tgme_widget_message_footer time[datetime]")
View Source
var MessagesSel = cascadia.MustCompile(".tgme_widget_message")
View Source
var TextSel = cascadia.MustCompile(".tgme_widget_message_text")

Functions

func CreateRateLimiter

func CreateRateLimiter(perSec int, burst int) throttled.RateLimiter

func FilterAll

func FilterAll[T interface{}](T) bool

Types

type APIServer

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

func NewAPIServer

func NewAPIServer(
	port uint16, apiKeys []string, updaterState *UpdaterState, updates *Topic[Update], mapData *MapData,
	listRecordsFunc func() ([]Record, error),
) *APIServer

func (*APIServer) CreateRouter

func (a *APIServer) CreateRouter(ctx context.Context) *mux.Router

func (*APIServer) Run

func (a *APIServer) Run(ctx context.Context, wg *sync.WaitGroup, errch chan error)

type ChannelClient

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

func NewChannelClient

func NewChannelClient(channel string) *ChannelClient

func (*ChannelClient) FetchLast

func (c *ChannelClient) FetchLast(ctx context.Context, count int) ([]Message, error)

func (*ChannelClient) FetchMessages

func (c *ChannelClient) FetchMessages(ctx context.Context, before int64) ([]Message, error)

func (*ChannelClient) FetchNewer

func (c *ChannelClient) FetchNewer(ctx context.Context, after int64) ([]Message, error)

type Delorean

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

func NewDelorean

func NewDelorean(dbname string, updates *Topic[Update]) *Delorean

func (*Delorean) ListRecords

func (d *Delorean) ListRecords() ([]Record, error)

func (*Delorean) Run

func (d *Delorean) Run(ctx context.Context, wg *sync.WaitGroup, errch chan error)

type FilterFunc

type FilterFunc[T interface{}] func(T) bool

type MapData

type MapData struct {
	ContentType string
	Bytes       []byte
}

type MapGenerator

type MapGenerator struct {
	MapData *MapData
	// contains filtered or unexported fields
}

func NewMapGenerator

func NewMapGenerator(updaterState *UpdaterState, updates *Topic[Update]) *MapGenerator

func (*MapGenerator) GenerateMap

func (g *MapGenerator) GenerateMap(updaterState *UpdaterState, title string, transparent bool) error

func (*MapGenerator) Run

func (g *MapGenerator) Run(ctx context.Context, wg *sync.WaitGroup, errch chan error)

type Message

type Message struct {
	ID     int64
	Author string
	Text   []string
	Date   time.Time
}

func (Message) String

func (m Message) String() string

type Persistence

type Persistence[T interface{}] struct {
	Data T
	// contains filtered or unexported fields
}

func NewPersistence

func NewPersistence[T interface{}](data T, path string) (*Persistence[T], error)

func (*Persistence[T]) Load

func (p *Persistence[T]) Load() error

func (*Persistence[T]) Save

func (p *Persistence[T]) Save() error

type PollResponse

type PollResponse struct {
	State          State     `json:"state"`
	NotificationID uuid.UUID `json:"notification_id"`
}

type Record

type Record struct {
	ID      int       `json:"id"`
	Date    time.Time `json:"date"`
	StateID int       `json:"state_id"`
	Alert   bool      `json:"alert"`
}

type SSEEncoder

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

func NewSSEEncoder

func NewSSEEncoder(w http.ResponseWriter) *SSEEncoder

func (*SSEEncoder) Write

func (e *SSEEncoder) Write(event string, data interface{}) error

type Settings

type Settings struct {
	TelegramChannel string         `env:"TELEGRAM_CHANNEL" envDefault:"air_alert_ua" yaml:"telegram_channel"`
	TimezoneName    string         `env:"TZ" envDefault:"Europe/Kiev" yaml:"timezone_name"`
	Timezone        *time.Location ``
	APIKeys         []string       `env:"API_KEYS" envSeparator:"," envDefault:"" yaml:"api_keys"`
	Debug           bool           `env:"DEBUG" envDefault:"false" yaml:"debug"`
	Trace           bool           `env:"TRACE" envDefault:"false" yaml:"trace"`
	BacklogSize     int            `env:"BACKLOG_SIZE" envDefault:"200" yaml:"backlog_size"`
}

func MustLoadSettings

func MustLoadSettings() (settings Settings)

type ShortState

type ShortState struct {
	ID    int  `json:"id"`
	Alert bool `json:"alert"`
}

type State

type State struct {
	ID      int        `json:"id"`
	Name    string     `json:"name"`
	NameEn  string     `json:"name_en"`
	Alert   bool       `json:"alert"`
	Changed *time.Time `json:"changed"`
}

type StateResponse

type StateResponse struct {
	*State     `json:"state"`
	LastUpdate time.Time `json:"last_update"`
}

type StatesResponse

type StatesResponse struct {
	States     []State   `json:"states"`
	LastUpdate time.Time `json:"last_update"`
}

type StatesShortResponse

type StatesShortResponse struct {
	States     []ShortState `json:"states"`
	LastUpdate time.Time    `json:"last_update"`
}

type TCPServer

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

func NewTCPServer

func NewTCPServer(port uint16, apiKeys []string, updaterState *UpdaterState, updates *Topic[Update]) *TCPServer

func (*TCPServer) HandleConn

func (t *TCPServer) HandleConn(ctx context.Context, conn net.Conn)

func (*TCPServer) Run

func (t *TCPServer) Run(ctx context.Context, wg *sync.WaitGroup, errch chan error)

type Topic

type Topic[T interface{}] struct {
	// contains filtered or unexported fields
}

func NewTopic

func NewTopic[T interface{}]() *Topic[T]

func (*Topic[T]) Broadcast

func (t *Topic[T]) Broadcast(payload T)

func (*Topic[T]) Subscribe

func (t *Topic[T]) Subscribe(name string, filter func(T) bool) chan T

func (*Topic[T]) Unsubscribe

func (t *Topic[T]) Unsubscribe(ch chan T)

type Update

type Update struct {
	IsFresh bool
	IsLast  bool
	State   State
}

type Updater

type Updater struct {
	Updates *Topic[Update]
	// contains filtered or unexported fields
}

func NewUpdater

func NewUpdater(telegramChannel string, timezone *time.Location, backlogSize int, updaterState *UpdaterState) *Updater

func (*Updater) ProcessMessages

func (u *Updater) ProcessMessages(ctx context.Context, messages []Message, isFresh bool)

func (*Updater) Run

func (u *Updater) Run(ctx context.Context, wg *sync.WaitGroup, errch chan error)

type UpdaterState

type UpdaterState struct {
	States        []State   `json:"states"`
	LastUpdate    time.Time `json:"last_update"`
	LastMessageID int64     `json:"last_message_id"`
}

func (*UpdaterState) FindState

func (s *UpdaterState) FindState(id int) *State

Jump to

Keyboard shortcuts

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