v0.0.0-...-a2814e5 Latest Latest

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

Go to latest
Published: May 13, 2020 License: Apache-2.0 Imports: 20 Imported by: 0



Package swgohgg provides several wrappers to fetch and parse https://swgoh.gg/ website data.



This section is empty.


View Source
var (
	// ShapeNames is a list of all available mod shapes.
	ShapeNames = []string{"Transmitter", "Receiver", "Processor", "Holo-Array", "Data-Bus", "Multiplexer"}

	// StatNames is a list of all available mod stats.
	StatNames = []string{"Speed", "Critical Chance", "Critical Damage", "Critical Avoidance", "Accuracy", "Potency", "Tenacity", "Offense", "Defense", "Health", "Protection"}


func CharSlug

func CharSlug(src string) string

CharSlug converts the character verbose name into the URL component


type Ability

type Ability struct {
	Name            string
	Character       string
	CharacterBaseID string
	IsZeta          bool

Ability is a generic description of an ability for a given character.

func (Ability) String

func (a Ability) String() string

type Char

type Char struct {
	Name  string
	Stars int
	Level int
	Gear  int

Char is a single character unit holding the basic stats.

func (*Char) String

func (c *Char) String() string

type CharacterSkill

type CharacterSkill struct {
	Name  string
	Level int

CharacterSkill holds basic info about a character skill.

type CharacterStats

type CharacterStats struct {
	Name      string
	Level     int
	GearLevel int
	Stars     int

	// Current character gallactic power
	GalacticPower int

	// List of skils of this character
	Skills []CharacterSkill

	// Basic Stats
	STR                int
	AGI                int
	INT                int
	StrenghGrowth      float64
	AgilityGrowth      float64
	IntelligenceGrowth float64

	// General
	Health         int
	Protection     int
	Speed          int
	CriticalDamage float64
	Potency        float64
	Tenacity       float64
	HealthSteal    float64

	PhysicalDamage     int
	PhysicalCritChance float64
	SpecialDamage      int
	SpecialCritChance  float64

CharacterStats contains all detailed character stats, as displayed in the game.

type Client

type Client struct {
	// contains filtered or unexported fields

Client implements methods to interact with the https://swgoh.gg/ website.

func NewClient

func NewClient(profile string) *Client

NewClient initializes a new instance of the client, tied to the specified user profile.

func (*Client) AllyCode

func (c *Client) AllyCode() string

AllyCode returns the player ally code

func (*Client) Arena

func (c *Client) Arena() (team []*CharacterStats, lastUpdate time.Time, err error)

Arena returns basic information about the player Arena team. If authorized, attempts to fetch more information from character stats

func (*Client) CharacterStats

func (c *Client) CharacterStats(char string) (*CharacterStats, error)

CharacterStats fetches the character detail page and extracts all stats.

func (*Client) Collection

func (c *Client) Collection() (collection Collection, err error)

Collection parses a player home page and returns the entire collection list.

func (*Client) Get

func (c *Client) Get(url string) (*goquery.Document, error)

Get retrieves the provided URL and returns a parsed goquery.Document.

func (*Client) GuildName

func (c *Client) GuildName() string

GuildName returns the player guild name

func (*Client) Login

func (c *Client) Login(username, password string) (err error)

Login authorizes the bot client using the provided username and password.

func (*Client) Mods

func (c *Client) Mods(filter ModFilter) (mods ModCollection, err error)

Mods reutrns a mod collection of mods with the given filter.

func (*Client) PlayerName

func (c *Client) PlayerName() string

PlayerName returns the player nickname

func (*Client) Profile

func (c *Client) Profile(profile string) *Client

Profile sets the client profile to a new value. *DEPRECATED*: use SetAllyCode instead.

func (*Client) SetAllyCode

func (c *Client) SetAllyCode(allyCode string) *Client

SetAllyCode set's the Ally Code for the client.

func (*Client) Ships

func (c *Client) Ships() (ships Ships, err error)

Ships returns a collection of ships the player has and are active.

func (*Client) UseHTTPClient

func (c *Client) UseHTTPClient(hc *http.Client) *Client

UseHTTPClient allows one to overwrite the default HTTP Client. The Client.Jar is replaced before next use.

func (*Client) Zetas

func (c *Client) Zetas() (zetas []Ability, err error)

Zetas fetches the current character abilities available in the "/characters-zeta-abilities" website pages.

type Collection

type Collection []*Char

Collection is a list of characters. Usually loaded up by the call to client.Collection().

func (Collection) Contains

func (r Collection) Contains(char string) bool

Contains lookup a character by name and checks if it is present in the collection.

func (Collection) ContainsAll

func (r Collection) ContainsAll(chars ...string) bool

ContainsAll checks if the collection has all the provided items.

func (Collection) MinRarity

func (r Collection) MinRarity(stars int) (filtered Collection)

MinRarity returns a filtered collection containing the required min rarity.

type Mod

type Mod struct {
	ID       string
	Level    int
	Rarity   int
	Shape    string
	BonusSet string

	PrimStat ModStat
	SecStat  []ModStat

	UsingIn string

Mod represents a player mod with all mod information.

func (*Mod) BonusShortName

func (m *Mod) BonusShortName() string

BonusShortName returns the bonus set abreviated name.

func (*Mod) Format

func (m *Mod) Format(useEmoji bool) string

Format returns a string representation of the mod, either using Unicode emoji or not.

func (*Mod) GetStat

func (m *Mod) GetStat(stat string) ModStat

GetStat returns a stat from the mod. The return is never nil, but a Zero ModStat.

func (*Mod) HasStat

func (m *Mod) HasStat(stat string) bool

HasStat checks if the mod has a primary or secondary stat.

func (*Mod) ShapeEmoji

func (m *Mod) ShapeEmoji() string

ShapeEmoji returns an unicode emoji that better represents the mod shape.

func (*Mod) ShapeIcon

func (m *Mod) ShapeIcon() string

ShapeIcon returns an unicode emoji that is coloured and represents the mod shape.

func (*Mod) ShapeName

func (m *Mod) ShapeName() string

ShapeName returns the mod shape name.

func (Mod) String

func (m Mod) String() string

type ModCollection

type ModCollection []*Mod

ModCollection is a slice of mods with extra methods for manipulation.

func (ModCollection) ByShape

func (m ModCollection) ByShape(shape string) (filtered ModCollection)

ByShape filter the mod collection by a given shape.

func (ModCollection) Filter

func (m ModCollection) Filter(filter ModFilter) (filtered ModCollection)

Filter applies the provided mod filter and returns a filtered collection that matches it.

func (ModCollection) MinLevel

func (m ModCollection) MinLevel(level int) (filtered ModCollection)

MinLevel filters the mod collection to one that has only the given minimum level.

func (ModCollection) MinRarity

func (m ModCollection) MinRarity(rarity int) (filtered ModCollection)

MinRarity filters the mod collection to one that has the minium rarity.

func (ModCollection) Optimize

func (m ModCollection) Optimize(stat string, percentIsBetter bool) ModSet

Optimize searches over all your mods with level >= 12, rarity >= 4, and outputs a best-value for the given stat, considering bonus sets if the 'percentIsBetter' parameter is true. This is very experimental, CPU intensive and memory intensive!

func (ModCollection) SetWith

func (m ModCollection) SetWith(stat string) ModSet

SetWith suggests a set containing the max values of the provided stat.

func (ModCollection) WithStat

func (m ModCollection) WithStat(stat string) (filtered ModCollection)

WithStat filters a mod collection by a given stat.

type ModFilter

type ModFilter struct {
	Char string

ModFilter allows to filter mod queries. Currently available filter is by character name.

func (*ModFilter) Match

func (f *ModFilter) Match(mod *Mod) bool

Match checks if the provided mod matches the filter.

type ModSet

type ModSet map[string]Mod

ModSet is a mod with a set of mods with unique shapes.

func (ModSet) Add

func (set ModSet) Add(mod *Mod)

Add includes the provided mod in the set.

func (ModSet) AddAll

func (set ModSet) AddAll(mods []*Mod)

AddAll include all mods in the set.

func (ModSet) BonusForSet

func (set ModSet) BonusForSet(stat string) float64

BonusForSet calculates the bonus set for the given stat. Takes into account mod level.

func (ModSet) StatSummary

func (set ModSet) StatSummary() (result []string)

StatSummary returns a summary of all mods in the set.

func (ModSet) Sum

func (set ModSet) Sum(stat string, isPercent bool) (res float64)

Sum returns a sum of all stats in the given set. Only mods with the same stat name and ispercent flag will be included in the sum.

type ModStat

type ModStat struct {
	Stat      string
	Value     float64
	IsPercent bool

ModStat is a single mod stat value. If a percentage value additive, the IsPercentage attribute will be true.

func (ModStat) IsBetterThan

func (ms ModStat) IsBetterThan(other ModStat) bool

IsBetterThan attempts to compare two stats with each other.

func (ModStat) IsZero

func (ms ModStat) IsZero() bool

IsZero checks if the stat object has a value or name, indicating it is not zero value.

func (ModStat) StatShortName

func (ms ModStat) StatShortName() string

StatShortName returns an abbreviated stat name.

func (ModStat) String

func (ms ModStat) String() string

type Ship

type Ship struct {
	Name  string
	Stars int
	Level int

Ship is a ship unit with basic stats.

func (*Ship) String

func (c *Ship) String() string

type Ships

type Ships []*Ship

Ships is a slice of ships with methods for manipulation.

func (Ships) Contains

func (r Ships) Contains(ship string) bool

Contains checks if the ship collection contains the provided ship.

func (Ships) ContainsAll

func (r Ships) ContainsAll(ships ...string) bool

ContainsAll returns true if the ship collection contains all the provided ships.

type SortByShipStars

type SortByShipStars struct {
	// contains filtered or unexported fields

SortByShipStars is a sorting criteria to sort ship collection by stars.

func ByShipStars

func ByShipStars(ships []*Ship, ascending bool) SortByShipStars

ByShipStars returns a sorting criteria to sort ships by stars.

func (SortByShipStars) Len

func (bs SortByShipStars) Len() int

func (SortByShipStars) Less

func (bs SortByShipStars) Less(i, j int) bool

func (SortByShipStars) Swap

func (bs SortByShipStars) Swap(i, j int)

type SortByStars

type SortByStars struct {
	// contains filtered or unexported fields

SortByStars is a sorting criteria to sort a character collection by star level.

func ByStars

func ByStars(chars []*Char, ascending bool) SortByStars

ByStars returns a sorting criteria to sort characters by stars.

func (SortByStars) Len

func (bs SortByStars) Len() int

func (SortByStars) Less

func (bs SortByStars) Less(i, j int) bool

func (SortByStars) Swap

func (bs SortByStars) Swap(i, j int)


Path Synopsis

Jump to

Keyboard shortcuts

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