Skip to content

Commit

Permalink
Merge branch 'release/51.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Oct 1, 2022
2 parents 1235a73 + 5a0ec39 commit 67b9fb3
Show file tree
Hide file tree
Showing 34 changed files with 623 additions and 182 deletions.
2 changes: 1 addition & 1 deletion cmd/c/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func BuildShips(planetID, shipID, nbr C.int) (errorMsg *C.char) {
// TODO: GetProduction(PlanetID) ([]Quantifiable, error)

//export ConstructionsBeingBuilt
func ConstructionsBeingBuilt(planetID C.int) (buildingID, buildingCountdown, researchID, researchCountdown, lfBuildingID, lfBuildingCountdown, lfTechID, lfTechCountdown C.int) {
func ConstructionsBeingBuilt(planetID C.int) (buildingID, buildingCountdown, researchID, researchCountdown, lfBuildingID, lfBuildingCountdown, lfResearchID, lfResearchCountdown C.int) {
a, b, c, d, e, f, g, h := bot.ConstructionsBeingBuilt(ogame2.CelestialID(planetID))
return C.int(a), C.int(b), C.int(c), C.int(d), C.int(e), C.int(f), C.int(g), C.int(h)
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/ogamed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ func start(c *cli.Context) error {
// CAPTCHA Handler
e.GET("/bot/captcha", wrapper.GetCaptchaHandler)
e.POST("/bot/captcha/solve", wrapper.GetCaptchaSolverHandler)
e.GET("/bot/captcha/challenge", wrapper.GetCaptchaChallengeHandler)

e.GET("/bot/ip", wrapper.GetPublicIPHandler)
e.GET("/bot/server", wrapper.GetServerHandler)
e.GET("/bot/server-data", wrapper.GetServerDataHandler)
e.POST("/bot/set-user-agent", wrapper.SetUserAgentHandler)
Expand Down Expand Up @@ -302,7 +304,7 @@ func start(c *cli.Context) error {
e.POST("/bot/planets/:planetID/resource-settings", wrapper.SetResourceSettingsHandler)
e.GET("/bot/planets/:planetID/resources-buildings", wrapper.GetResourcesBuildingsHandler)
e.GET("/bot/planets/:planetID/lifeform-buildings", wrapper.GetLfBuildingsHandler)
e.GET("/bot/planets/:planetID/lifeform-techs", wrapper.GetLfTechsHandler)
e.GET("/bot/planets/:planetID/lifeform-techs", wrapper.GetLfResearchHandler)
e.GET("/bot/planets/:planetID/defence", wrapper.GetDefenseHandler)
e.GET("/bot/planets/:planetID/ships", wrapper.GetShipsHandler)
e.GET("/bot/planets/:planetID/facilities", wrapper.GetFacilitiesHandler)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible
github.com/google/gxui v0.0.0-20151028112939-f85e0a97b3a4
github.com/hashicorp/go-version v1.2.0
github.com/labstack/echo/v4 v4.8.0
github.com/labstack/echo/v4 v4.9.0
github.com/magiconair/properties v1.8.1
github.com/olekukonko/tablewriter v0.0.4
github.com/orirawlings/persistent-cookiejar v0.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/labstack/echo/v4 v4.8.0 h1:wdc6yKVaHxkNOEdz4cRZs1pQkwSXPiRjq69yWP4QQS8=
github.com/labstack/echo/v4 v4.8.0/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
github.com/labstack/echo/v4 v4.9.0 h1:wPOF1CE6gvt/kmbMR4dGzWvHMPT+sAEUJOwOTtvITVY=
github.com/labstack/echo/v4 v4.9.0/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o=
github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
Expand Down
20 changes: 11 additions & 9 deletions pkg/extractor/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type OverviewExtractorBytes interface {
ExtractCancelLfBuildingInfos(pageHTML []byte) (token string, id, listID int64, err error)
ExtractCancelResearchInfos(pageHTML []byte) (token string, techID, listID int64, err error)
ExtractCharacterClass(pageHTML []byte) (ogame.CharacterClass, error)
ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfTechID ogame.ID, lfTechCountdown int64)
ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfResearchID ogame.ID, lfResearchCountdown int64)
ExtractDMCosts(pageHTML []byte) (ogame.DMCosts, error)
ExtractFleetDeutSaveFactor(pageHTML []byte) float64
ExtractOverviewProduction(pageHTML []byte) ([]ogame.Quantifiable, int64, error)
Expand Down Expand Up @@ -423,18 +423,18 @@ type LfBuildingsExtractorBytesDoc interface {
LfBuildingsExtractorDoc
}

type LfTechsExtractorBytes interface {
type LfResearchExtractorBytes interface {
ExtractUpgradeToken(pageHTML []byte) (string, error)
ExtractLfTechs(pageHTML []byte) (ogame.LfTechs, error)
ExtractLfResearch(pageHTML []byte) (ogame.LfResearches, error)
}

type LfTechsExtractorDoc interface {
ExtractLfTechsFromDoc(doc *goquery.Document) (ogame.LfTechs, error)
type LfResearchExtractorDoc interface {
ExtractLfResearchFromDoc(doc *goquery.Document) (ogame.LfResearches, error)
}

type LfTechsExtractorBytesDoc interface {
LfTechsExtractorBytes
LfTechsExtractorDoc
type LfResearchExtractorBytesDoc interface {
LfResearchExtractorBytes
LfResearchExtractorDoc
}

// ResourcesBuildingsExtractorBytes supplies page
Expand Down Expand Up @@ -463,11 +463,13 @@ type PlanetLayerExtractorDoc interface {
}

type TechnologyDetailsExtractorBytes interface {
ExtractTechnologyDetails(pageHTML []byte) (ogame.TechnologyDetails, error)
ExtractTearDownButtonEnabled(pageHTML []byte) bool
}

type TechnologyDetailsExtractorDoc interface {
ExtractTearDownButtonEnabledFromDoc(doc *goquery.Document) bool
ExtractTechnologyDetailsFromDoc(doc *goquery.Document) (ogame.TechnologyDetails, error)
}

type TechnologyDetailsExtractorBytesDoc interface {
Expand All @@ -492,7 +494,7 @@ type Extractor interface {
FullPageExtractorBytesDoc
HighscoreExtractorBytesDoc
LfBuildingsExtractorBytesDoc
LfTechsExtractorBytesDoc
LfResearchExtractorBytesDoc
MessagesCombatReportExtractorBytesDoc
MessagesEspionageReportExtractorBytesDoc
MessagesExpeditionExtractorBytesDoc
Expand Down
20 changes: 15 additions & 5 deletions pkg/extractor/v6/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ func (e *Extractor) GetLanguage() string {
return e.lang
}

// ExtractTechnologyDetails ...
func (e *Extractor) ExtractTechnologyDetails(pageHTML []byte) (out ogame.TechnologyDetails, err error) {
panic("implement me")
}

// ExtractTechnologyDetailsFromDoc ...
func (e *Extractor) ExtractTechnologyDetailsFromDoc(doc *goquery.Document) (ogame.TechnologyDetails, error) {
panic("implement me")
}

func (e *Extractor) ExtractCancelLfBuildingInfos(pageHTML []byte) (token string, id, listID int64, err error) {
panic("implement me")
}
Expand Down Expand Up @@ -809,7 +819,7 @@ func (e *Extractor) ExtractFederation(pageHTML []byte) url.Values {
}

// ExtractConstructions ...
func (e *Extractor) ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfTechID ogame.ID, lfTechCountdown int64) {
func (e *Extractor) ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfResearchID ogame.ID, lfResearchCountdown int64) {
return extractConstructions(pageHTML)
}

Expand Down Expand Up @@ -894,12 +904,12 @@ func (e *Extractor) ExtractLfBuildingsFromDoc(doc *goquery.Document) (ogame.LfBu
panic("not implemented")
}

// ExtractLfTechs ...
func (e *Extractor) ExtractLfTechs(pageHTML []byte) (ogame.LfTechs, error) {
// ExtractLfResearch ...
func (e *Extractor) ExtractLfResearch(pageHTML []byte) (ogame.LfResearches, error) {
panic("not implemented")
}

// ExtractLfTechsFromDoc ...
func (e *Extractor) ExtractLfTechsFromDoc(doc *goquery.Document) (ogame.LfTechs, error) {
// ExtractLfResearchFromDoc ...
func (e *Extractor) ExtractLfResearchFromDoc(doc *goquery.Document) (ogame.LfResearches, error) {
panic("not implemented")
}
2 changes: 1 addition & 1 deletion pkg/extractor/v6/extracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,7 @@ func extractFederation(pageHTML []byte) url.Values {
return payload
}

func extractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfTechID ogame.ID, lfTechCountdown int64) {
func extractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfResearchID ogame.ID, lfResearchCountdown int64) {
buildingCountdownMatch := regexp.MustCompile(`getElementByIdWithCache\("Countdown"\),(\d+),`).FindSubmatch(pageHTML)
if len(buildingCountdownMatch) > 0 {
buildingCountdown = int64(utils.ToInt(buildingCountdownMatch[1]))
Expand Down
2 changes: 1 addition & 1 deletion pkg/extractor/v7/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (e Extractor) ExtractResourcesDetails(pageHTML []byte) (out ogame.Resources
}

// ExtractConstructions ...
func (e Extractor) ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfTechID ogame.ID, lfTechCountdown int64) {
func (e Extractor) ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfResearchID ogame.ID, lfResearchCountdown int64) {
return ExtractConstructions(pageHTML, clockwork.NewRealClock())
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/extractor/v7/extracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func extractResourcesDetails(pageHTML []byte) (out ogame.ResourcesDetails, err e
return
}

func ExtractConstructions(pageHTML []byte, clock clockwork.Clock) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfTechID ogame.ID, lfTechCountdown int64) {
func ExtractConstructions(pageHTML []byte, clock clockwork.Clock) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfResearchID ogame.ID, lfResearchCountdown int64) {
buildingCountdownMatch := regexp.MustCompile(`var restTimebuilding = (\d+) -`).FindSubmatch(pageHTML)
if len(buildingCountdownMatch) > 0 {
buildingCountdown = int64(utils.ToInt(buildingCountdownMatch[1])) - clock.Now().Unix()
Expand Down
59 changes: 52 additions & 7 deletions pkg/extractor/v9/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package v9

import (
"bytes"
"encoding/json"
"strings"

"github.com/PuerkitoBio/goquery"
"github.com/alaingilbert/clockwork"
Expand All @@ -19,6 +21,38 @@ func NewExtractor() *Extractor {
return &Extractor{}
}

// ExtractTechnologyDetailsFromDoc ...
func (e *Extractor) ExtractTechnologyDetailsFromDoc(doc *goquery.Document) (ogame.TechnologyDetails, error) {
return extractTechnologyDetailsFromDoc(doc)
}

type technologyDetailsStruct struct {
Target string `json:"target"`
Content struct {
Technologydetails string `json:"technologydetails"`
} `json:"content"`
Files struct {
Js []string `json:"js"`
CSS []string `json:"css"`
} `json:"files"`
Page struct {
StateObj string `json:"stateObj"`
Title string `json:"title"`
URL string `json:"url"`
} `json:"page"`
ServerTime int `json:"serverTime"`
}

// ExtractTechnologyDetails ...
func (e *Extractor) ExtractTechnologyDetails(pageHTML []byte) (out ogame.TechnologyDetails, err error) {
var technologyDetails technologyDetailsStruct
if err := json.Unmarshal(pageHTML, &technologyDetails); err != nil {
return out, err
}
doc, _ := goquery.NewDocumentFromReader(strings.NewReader(technologyDetails.Content.Technologydetails))
return e.ExtractTechnologyDetailsFromDoc(doc)
}

// ExtractCancelLfBuildingInfos ...
func (e *Extractor) ExtractCancelLfBuildingInfos(pageHTML []byte) (token string, id, listID int64, err error) {
return extractCancelLfBuildingInfos(pageHTML)
Expand Down Expand Up @@ -81,7 +115,7 @@ func (e *Extractor) ExtractResourcesDetailsFromFullPageFromDoc(doc *goquery.Docu
}

// ExtractConstructions ...
func (e *Extractor) ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfTechID ogame.ID, lfTechCountdown int64) {
func (e *Extractor) ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfResearchID ogame.ID, lfResearchCountdown int64) {
return ExtractConstructions(pageHTML, clockwork.NewRealClock())
}

Expand All @@ -102,13 +136,24 @@ func (e *Extractor) ExtractLfBuildingsFromDoc(doc *goquery.Document) (ogame.LfBu
return extractLfBuildingsFromDoc(doc)
}

// ExtractLfTechs ...
func (e *Extractor) ExtractLfTechs(pageHTML []byte) (ogame.LfTechs, error) {
// ExtractLfResearch ...
func (e *Extractor) ExtractLfResearch(pageHTML []byte) (ogame.LfResearches, error) {
doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(pageHTML))
return e.ExtractLfResearchFromDoc(doc)
}

// ExtractLfResearchFromDoc ...
func (e *Extractor) ExtractLfResearchFromDoc(doc *goquery.Document) (ogame.LfResearches, error) {
return extractLfResearchFromDoc(doc)
}

// ExtractTearDownButtonEnabled ...
func (e *Extractor) ExtractTearDownButtonEnabled(pageHTML []byte) bool {
doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(pageHTML))
return e.ExtractLfTechsFromDoc(doc)
return e.ExtractTearDownButtonEnabledFromDoc(doc)
}

// ExtractLfTechsFromDoc ...
func (e *Extractor) ExtractLfTechsFromDoc(doc *goquery.Document) (ogame.LfTechs, error) {
return extractLfTechsFromDoc(doc)
// ExtractTearDownButtonEnabledFromDoc ...
func (e *Extractor) ExtractTearDownButtonEnabledFromDoc(doc *goquery.Document) bool {
return extractTearDownButtonEnabledFromDoc(doc)
}
34 changes: 34 additions & 0 deletions pkg/extractor/v9/extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,37 @@ func TestExtractLfBuildingsRocktal(t *testing.T) {
assert.Equal(t, int64(2), res.MeditationEnclave)
assert.Equal(t, int64(1), res.CrystalFarm)
}

func TestExtractTechnologyDetails(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/v9.0.4/en/lifeform/technologyDetails_1.html")
details, err := NewExtractor().ExtractTechnologyDetails(pageHTMLBytes)
assert.NoError(t, err)
assert.Equal(t, ogame.ID(11105), details.TechnologyID)
assert.Equal(t, 41*time.Minute+12*time.Second, details.ProductionDuration)
assert.Equal(t, int64(0), details.Level)
assert.Equal(t, int64(50000), details.Price.Metal)
assert.Equal(t, int64(40000), details.Price.Crystal)
assert.Equal(t, int64(50000), details.Price.Deuterium)
assert.Equal(t, int64(100000000), details.Price.Population)
assert.False(t, details.TearDownEnabled)

pageHTMLBytes, _ = ioutil.ReadFile("../../../samples/v9.0.4/en/lifeform/technologyDetails_lfbuilding_teardown_enabled.html")
details, err = NewExtractor().ExtractTechnologyDetails(pageHTMLBytes)
assert.NoError(t, err)
assert.Equal(t, ogame.ID(11101), details.TechnologyID)
assert.Equal(t, 6*time.Hour+58*time.Minute+48*time.Second, details.ProductionDuration)
assert.Equal(t, int64(34), details.Level)
assert.Equal(t, int64(120594), details.Price.Metal)
assert.Equal(t, int64(34455), details.Price.Crystal)
assert.Equal(t, int64(0), details.Price.Deuterium)
assert.Equal(t, int64(0), details.Price.Population)
assert.True(t, details.TearDownEnabled)

pageHTMLBytes, _ = ioutil.ReadFile("../../../samples/v9.0.4/en/lifeform/technologyDetails_lfbuilding_teardown_disabled.html")
details, _ = NewExtractor().ExtractTechnologyDetails(pageHTMLBytes)
assert.False(t, details.TearDownEnabled)

pageHTMLBytes, _ = ioutil.ReadFile("../../../samples/v9.0.4/en/lifeform/technologyDetails_supplies.html")
details, _ = NewExtractor().ExtractTechnologyDetails(pageHTMLBytes)
assert.True(t, details.TearDownEnabled)
}
52 changes: 44 additions & 8 deletions pkg/extractor/v9/extracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v9

import (
"errors"
"fmt"
"regexp"
"strconv"
"strings"
Expand All @@ -19,7 +20,7 @@ import (
func ExtractConstructions(pageHTML []byte, clock clockwork.Clock) (buildingID ogame.ID, buildingCountdown int64,
researchID ogame.ID, researchCountdown int64,
lfBuildingID ogame.ID, lfBuildingCountdown int64,
lfTechID ogame.ID, lfTechCountdown int64) {
lfResearchID ogame.ID, lfResearchCountdown int64) {
buildingCountdownMatch := regexp.MustCompile(`var restTimebuilding = (\d+) -`).FindSubmatch(pageHTML)
if len(buildingCountdownMatch) > 0 {
buildingCountdown = int64(utils.ToInt(buildingCountdownMatch[1])) - clock.Now().Unix()
Expand All @@ -38,11 +39,11 @@ func ExtractConstructions(pageHTML []byte, clock clockwork.Clock) (buildingID og
lfBuildingIDInt := utils.ToInt(regexp.MustCompile(`onclick="cancellfbuilding\((\d+),`).FindSubmatch(pageHTML)[1])
lfBuildingID = ogame.ID(lfBuildingIDInt)
}
lfTechCountdownMatch := regexp.MustCompile(`var restTimelfresearch = (\d+) -`).FindSubmatch(pageHTML)
if len(lfTechCountdownMatch) > 0 {
lfTechCountdown = int64(utils.ToInt(lfTechCountdownMatch[1])) - clock.Now().Unix()
lfTechIDInt := utils.ToInt(regexp.MustCompile(`onclick="cancellfresearch\((\d+),`).FindSubmatch(pageHTML)[1])
lfTechID = ogame.ID(lfTechIDInt)
lfResearchCountdownMatch := regexp.MustCompile(`var restTimelfresearch = (\d+) -`).FindSubmatch(pageHTML)
if len(lfResearchCountdownMatch) > 0 {
lfResearchCountdown = int64(utils.ToInt(lfResearchCountdownMatch[1])) - clock.Now().Unix()
lfResearchIDInt := utils.ToInt(regexp.MustCompile(`onclick="cancellfresearch\((\d+),`).FindSubmatch(pageHTML)[1])
lfResearchID = ogame.ID(lfResearchIDInt)
}
return
}
Expand Down Expand Up @@ -638,8 +639,8 @@ func extractLfBuildingsFromDoc(doc *goquery.Document) (ogame.LfBuildings, error)
return res, nil
}

func extractLfTechsFromDoc(doc *goquery.Document) (ogame.LfTechs, error) {
res := ogame.LfTechs{}
func extractLfResearchFromDoc(doc *goquery.Document) (ogame.LfResearches, error) {
res := ogame.LfResearches{}
// Can have any lifeform techs whatever current planet lifeform is, so take everything
res.IntergalacticEnvoys = GetNbr(doc, "lifeformTech11201")
res.HighPerformanceExtractors = GetNbr(doc, "lifeformTech11202")
Expand Down Expand Up @@ -716,3 +717,38 @@ func extractLfTechsFromDoc(doc *goquery.Document) (ogame.LfTechs, error) {

return res, nil
}

func extractTechnologyDetailsFromDoc(doc *goquery.Document) (out ogame.TechnologyDetails, err error) {
out.TechnologyID = ogame.ID(utils.DoParseI64(doc.Find("div#technologydetails").AttrOr("data-technology-id", "")))

durationStr := doc.Find("li.build_duration time").AttrOr("datetime", "")
rgx := regexp.MustCompile(`PT(?:(\d+)H)?(?:(\d+)M)?(\d+)S`)
m := rgx.FindStringSubmatch(durationStr)
if len(m) != 4 {
return out, fmt.Errorf("failed to extract duration: %s", durationStr)
}
hour := time.Duration(utils.DoParseI64(m[1])) * time.Hour
min := time.Duration(utils.DoParseI64(m[2])) * time.Minute
sec := time.Duration(utils.DoParseI64(m[3])) * time.Second
out.ProductionDuration = hour + min + sec

out.Level = utils.DoParseI64(doc.Find("span.level").AttrOr("data-value", "")) - 1

out.Price.Metal = utils.DoParseI64(doc.Find("div.costs li.metal").AttrOr("data-value", ""))
out.Price.Crystal = utils.DoParseI64(doc.Find("div.costs li.crystal").AttrOr("data-value", ""))
out.Price.Deuterium = utils.DoParseI64(doc.Find("div.costs li.deuterium").AttrOr("data-value", ""))
out.Price.Population = utils.DoParseI64(doc.Find("div.costs li.population").AttrOr("data-value", ""))

out.TearDownEnabled = extractTearDownButtonEnabledFromDoc(doc)

return out, err
}

func extractTearDownButtonEnabledFromDoc(doc *goquery.Document) (out bool) {
if doc.Find("button.downgrade").Length() == 1 {
if _, exists := doc.Find("button.downgrade").Attr("disabled"); !exists {
out = true
}
}
return
}
2 changes: 1 addition & 1 deletion pkg/ogame/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const (
AssemblyLineID ID = 13101 // Lifeform (mechas)
FusionCellFactoryID ID = 13102
RoboticsResearchCentreID ID = 13103
UpdateNetworkID ID = 12304
UpdateNetworkID ID = 13104
QuantumComputerCentreID ID = 13105
AutomatisedAssemblyCentreID ID = 13106
HighPerformanceTransformerID ID = 13107
Expand Down
Loading

0 comments on commit 67b9fb3

Please sign in to comment.