cards

package
v0.0.0-...-f1aec25 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, priority int, fn NewCardFunc)

Register adds a new card to the library

Types

type CalcCard

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

CalcCard represents a calculation card

func (*CalcCard) Content

func (cc *CalcCard) Content() template.HTML

Content returns the solveRenderScript with the given input

func (*CalcCard) Footer

func (cc *CalcCard) Footer() template.HTML

Footer returns empty string because CalcCard has no footer

func (*CalcCard) Head

func (cc *CalcCard) Head() template.HTML

Head returns the extra head tags required for CalcCard

func (*CalcCard) Matches

func (cc *CalcCard) Matches() bool

Matches determines whether a query matches the requirements fot CalcCard and determines which function to run with what arguments

func (*CalcCard) Returned

func (cc *CalcCard) Returned() bool

Returned always returns true since CalcCard is a frontend card and it is thus impossible to determine whether the query gets an answer

func (*CalcCard) RunQuery

func (cc *CalcCard) RunQuery() error

RunQuery returns nil as CalcCard is a frontend card

func (*CalcCard) StripKey

func (cc *CalcCard) StripKey() string

StripKey removes all key words related to CalcCard

func (*CalcCard) Title

func (cc *CalcCard) Title() string

Title for CalcCard is "Calculation"

type Card

type Card interface {
	// RunQuery runs any HTTP or other requests
	RunQuery() error

	// Returned returns whether the query
	// returned any information
	Returned() bool

	// Matches returns whether the query matches
	// for the card
	Matches() bool

	// StripKey removes the key words and returns
	// the updated query
	StripKey() string

	// Title returns the card title
	Title() string

	// Content returns the contents of the card
	Content() template.HTML

	// Footer returns the contents of the card footer
	Footer() template.HTML

	// Head returns any extras to include in <head>
	Head() template.HTML
}

Card represents a search result card

func GetCard

func GetCard(query, userAgent string) Card

GetCard returns a matching registered card

func NewCalcCard

func NewCalcCard(query, _ string) Card

NewCalcCard is a NewCardFunc that creates a new CalcCard

func NewDDGCard

func NewDDGCard(query, userAgent string) Card

NewDDGCard is a NewCardFunc that creates a new DDGCard

func NewMetaweatherCard

func NewMetaweatherCard(query, userAgent string) Card

NewMetaweatherCard is a NewCardFunc that creates a new MetaweatherCard

func NewPlotCard

func NewPlotCard(query, _ string) Card

NewPlotCard is a NewCardFunc that creates a new PlotCard

type DDGCard

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

DDGCard represents a DuckDuckGo Instant Answer API card

func (*DDGCard) Content

func (ddg *DDGCard) Content() template.HTML

Content returns the instant answer abstract with DuckDuckGo attibution

func (*DDGCard) Footer

func (ddg *DDGCard) Footer() template.HTML

Footer returns a footer containing URL and name of source gotten from instant answer API

func (*DDGCard) Head

func (ddg *DDGCard) Head() template.HTML

Head returns an empty string as no extra tags are reuired for DDGCard

func (*DDGCard) Matches

func (ddg *DDGCard) Matches() bool

Matches always returns true as there are no keys

func (*DDGCard) Returned

func (ddg *DDGCard) Returned() bool

Returned checks if abstract is empty. If it is, query returned no result.

func (*DDGCard) RunQuery

func (ddg *DDGCard) RunQuery() error

RunQuery requests the query from the instant answer API

func (*DDGCard) StripKey

func (ddg *DDGCard) StripKey() string

StripKey returns the query as there are no keys

func (*DDGCard) Title

func (ddg *DDGCard) Title() string

Title returns the instant answer heading

type DDGInstAns

type DDGInstAns struct {
	Abstract       string
	AbstractText   string
	AbstractSource string
	AbstractURL    string
	Image          string
	Heading        string
	Answer         string
	AnswerType     string
}

DDGInstAns represents a DuckDuckGo Instant Answer API response

type MetaweatherCard

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

MetaweatherCard represents a metaweather card

func (*MetaweatherCard) Content

func (mc *MetaweatherCard) Content() template.HTML

Content returns metaweatherContent with all information added

func (*MetaweatherCard) Footer

func (mc *MetaweatherCard) Footer() template.HTML

Footer returns a footer with a link to metaweather

func (*MetaweatherCard) Head

func (mc *MetaweatherCard) Head() template.HTML

Head returns an empty string as no extra head tags are required for MetaweatherCard

func (*MetaweatherCard) Matches

func (mc *MetaweatherCard) Matches() bool

Matches determines whether the query matches the keys for MetaweatherCard

func (*MetaweatherCard) Returned

func (mc *MetaweatherCard) Returned() bool

Returned checks whether no location was found or response said not found.

func (*MetaweatherCard) RunQuery

func (mc *MetaweatherCard) RunQuery() error

RunQuery searches for the location and then runs an API query using the returned WOEID

func (*MetaweatherCard) StripKey

func (mc *MetaweatherCard) StripKey() string

StripKey removes keys related to MetaweatherCard

func (*MetaweatherCard) Title

func (mc *MetaweatherCard) Title() string

Title of MetaweatherCard is "Weather"

type MetaweatherLocation

type MetaweatherLocation struct {
	Title string `json:"title"`
	WOEID int    `json:"woeid"`
}

MetaweatherLocation represents a location

type MetaweatherResponse

type MetaweatherResponse struct {
	Detail       string `json:"detail"`
	Title        string `json:"title"`
	Timezone     string `json:"timezone"`
	Consolidated []struct {
		ID             int     `json:"id"`
		State          string  `json:"weather_state_name"`
		StateAbbr      string  `json:"weather_state_abbr"`
		WindCompass    string  `json:"wind_direction_compass"`
		MinTemp        float64 `json:"min_temp"`
		MaxTemp        float64 `json:"max_temp"`
		CurrentTemp    float64 `json:"the_temp"`
		WindSpeed      float64 `json:"wind_speed"`
		WindDirection  float64 `json:"wind_direction"`
		AirPressure    float64 `json:"air_pressure"`
		Visibility     float64 `json:"visibility"`
		Humidity       int     `json:"humidity"`
		Predictability int     `json:"predictability"`
	} `json:"consolidated_weather"`
}

MetaweatherResponse represents a response from the metaweather API

type NewCardFunc

type NewCardFunc func(query, userAgent string) Card

NewCardFunc creates and returns a new card. This should not be an expensive operation

type PlotCard

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

PlotCard represents a card with an equation plot

func (*PlotCard) Content

func (pc *PlotCard) Content() template.HTML

Content returns plot script with given input

func (*PlotCard) Footer

func (pc *PlotCard) Footer() template.HTML

Footer returns an empty string as PlotCard has no footer

func (*PlotCard) Head

func (pc *PlotCard) Head() template.HTML

Head returns extra head tags for PlotCard

func (*PlotCard) Matches

func (pc *PlotCard) Matches() bool

Matches checks if the query matches the rules for PlotCard

func (*PlotCard) Returned

func (pc *PlotCard) Returned() bool

Returned will alwats return true because this card is frontend, and this cannot be checked.

func (*PlotCard) RunQuery

func (pc *PlotCard) RunQuery() error

RunQuery returns nil as PlotCard is a frontend card

func (*PlotCard) StripKey

func (pc *PlotCard) StripKey() string

StripKey removes all keys related to PlotCard

func (*PlotCard) Title

func (pc *PlotCard) Title() string

Title generates a title formatted as "Plot (<eqation>)"

Jump to

Keyboard shortcuts

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