roomservice

package
v0.0.0-...-b6406c2 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgParser

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

ArgParser parses elements of an arg list as different types

func NewArgParser

func NewArgParser(args []string) *ArgParser

NewArgParser takes an arg list like a string split at every space.

func (*ArgParser) AsFloat

func (a *ArgParser) AsFloat(index int) (float64, error)

AsFloat parses the arg as float64

func (*ArgParser) AsInt

func (a *ArgParser) AsInt(index int) (int, error)

AsInt parses the arg as an int

func (*ArgParser) AsIntArray

func (a *ArgParser) AsIntArray(index int) (arr []int, err error)

AsIntArray returns the single value or comma separated values as an array

func (*ArgParser) AsLocation

func (a *ArgParser) AsLocation(latIdx, lonIdx int) (l pogo.Location, err error)

AsLocation returns a pogo.Location from the given indices

func (*ArgParser) AsLocationRadius

func (a *ArgParser) AsLocationRadius(latIdx, lonIdx, radiusIdx int) (lr pogo.LocationRadius, err error)

AsLocationRadius returns a pogo.LocationRadius from the given indices

func (*ArgParser) AsString

func (a *ArgParser) AsString(index int) (string, error)

AsString returns the arg as is, but with index bounds check

func (*ArgParser) Count

func (a *ArgParser) Count() int

Count returns the number of args

type Chatter

type Chatter interface {
	SendText(roomID, text string)
	SendFormattedText(roomID, text, formattedText string)
}

Chatter posts messages into a chatroom

type Command

type Command struct {
	// Command without / or ! prefix
	Command  string
	Callback CommandCallback
	// accessible by everyone? false=admin only
	Public bool
}

Command is triggered by a line starting with the keyword

type CommandCallback

type CommandCallback func(args []string, context Context) (handled bool, err error)

CommandCallback contains the line triggering it and room context

type Context

type Context struct {
	Cli     *gomatrix.Client // Client pointer
	Chatter Chatter
	Poster  *Poster

	Sender    string `json:"sender"`           // The user ID of the sender of the event
	Type      string `json:"type"`             // The event type
	Timestamp int64  `json:"origin_server_ts"` // The unix timestamp when this message was sent by the origin server
	ID        string `json:"event_id"`         // The unique ID of this event
	RoomID    string `json:"room_id"`          // The room the event was sent to. May be nil (e.g. for presence)
}

Context is the room state description

type FilterChange

type FilterChange int

FilterChange is used to describe what should be done with the existing Filter

const (
	// FilterChangeAddPokemon adds pokemon to list
	FilterChangeAddPokemon FilterChange = iota
	// FilterChangeRemovePokemon removes pokemon from list
	FilterChangeRemovePokemon
	// FilterChangeArea replaces the area
	FilterChangeArea
)

type MainController

type MainController interface {
	Stop()
}

MainController stops main when Stop is called

type Persister

type Persister interface {
	SaveRoomConfig(roomID string, roomConfig *RoomConfig)
	SaveRoomConfigs(roomConfigs map[string]*RoomConfig)
	ReadRoomConfigs(roomConfigs map[string]*RoomConfig)

	SaveRoomState(roomID string, roomState *RoomState)
	SaveRoomStates(roomStates map[string]*RoomState)
	ReadRoomStates(roomStates map[string]*RoomState)
}

Persister persists states and configs between runs

type PokemonFilter

type PokemonFilter struct {
	Area       pogo.LocationRadius // area to include
	ListRaids  bool                // true if this filter only matches raids, false for only spawns
	ListWanted bool                // true if only wanted pokemon ids are in the list, false for unwanted pokemon
	PokemonIDs []int               // pokedex numbers
}

PokemonFilter specifies which pokemon in an area should be posted

type Poster

type Poster struct {
	// data input channels
	GymUpdates   chan pogo.Gym
	SpawnUpdates chan pogo.Spawn
	RaidUpdates  chan pogo.Raid

	// control channels
	Quit        chan bool
	MainControl MainController

	// pokedex
	Pokedex *pogo.Pokedex

	// geodex
	GeoDex *geodex.GeoDex

	// read RoomConfigs and States from disk before starting the main loop in Run()
	ResumeStateOnStartup bool

	// remove expired spawns and raids from memory
	ExpiryCheckPeriod time.Duration
	// contains filtered or unexported fields
}

Poster is an agent that posts info from various datasources without user interaction

func NewPoster

func NewPoster(chatter Chatter, persister Persister) *Poster

NewPoster creates some objects

func (*Poster) ChangeRoomConfig

func (p *Poster) ChangeRoomConfig(roomID string, rcChange *RoomConfigChange, newValues *RoomConfig) (err error)

ChangeRoomConfig edits an existing RoomConfig with the given changeset

func (*Poster) DeleteFilters

func (p *Poster) DeleteFilters(roomID string) (deleted bool)

DeleteFilters deletes all pokemon filters for a room if a RoomConfig exists

func (*Poster) GetRoomConfig

func (p *Poster) GetRoomConfig(roomID string) (*RoomConfig, bool)

GetRoomConfig returns a copy of the room configuration if there is one

func (*Poster) ParseMessage

func (p *Poster) ParseMessage(msg string, context Context) (handled bool, err error)

ParseMessage processes a single line and calls the callback if it contains a command

func (*Poster) Run

func (p *Poster) Run()

Run runs the poster main loop blockingly

func (*Poster) UpdateRoomConfig

func (p *Poster) UpdateRoomConfig(rcUpdate *RoomConfig) (created bool)

UpdateRoomConfig overwrites or adds the RoomConfig and appends the Filter

type RaidState

type RaidState struct {
	EndTime int64
	Posted  bool
}

RaidState tracks if a raid was already posted as long as it has not elapsed

type RoomConfig

type RoomConfig struct {
	RoomID         string
	AcceptCommands bool // parse commands from users in this room (admin privileges are checked seperately)
	FormatText     bool
	Filter         []PokemonFilter
}

RoomConfig contains settings for a room with one or more people

func (RoomConfig) ToString

func (r RoomConfig) ToString() string

ToString converts RoomConfig into a human-readable string

type RoomConfigChange

type RoomConfigChange struct {
	ChangeAcceptCommands bool // update RC with value from given RoomConfig
	ChangeFormatText     bool // same as above
	Operation            RoomConfigOperation
	FilterIndex          int          // only when UpdateFilter=true
	FilterChange         FilterChange // only when UpdateFilter=true
}

RoomConfigChange describes an update operation for an existing RoomConfig

type RoomConfigOperation

type RoomConfigOperation int

RoomConfigOperation describes what should be done in a RoomConfigChange

const (
	RoomConfigOperationNone RoomConfigOperation = iota
	RoomConfigOperationAppendFilter
	RoomConfigOperationUpdateFilter
	RoomConfigOperationRemoveFilter
)

this flag says what you want to do with the roomconfig

type RoomState

type RoomState struct {
	// EncounterID -> SpawnState
	Spawns map[string]*SpawnState
	// Raid hash -> RaidState
	Raids map[string]*RaidState
}

RoomState keeps track of posted mons

func NewRoomState

func NewRoomState() *RoomState

NewRoomState creates a RoomState object

type SpawnState

type SpawnState struct {
	EndTime int64
	Posted  bool
}

SpawnState tracks if a spawn was already posted as long as it has not elapsed

Jump to

Keyboard shortcuts

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