Skip to content

Commit

Permalink
extract abandon info
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Aug 22, 2022
1 parent 3c006f7 commit 1b51ef5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pkg/extractor/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ type PremiumExtractorBytes interface {
ExtractPremiumToken(pageHTML []byte, days int64) (token string, err error)
}

type PlanetLayerExtractorDoc interface {
ExtractAbandonInformation(doc *goquery.Document) (abandonToken string, token string)
}

// Extractor ...
type Extractor interface {
GetLanguage() string
Expand Down Expand Up @@ -465,6 +469,7 @@ type Extractor interface {
TraderAuctioneerExtractorBytes
TraderImportExportExtractorBytes

PlanetLayerExtractorDoc
TraderImportExportExtractorDoc

ExtractCoord(v string) (coord ogame.Coordinate)
Expand Down
5 changes: 5 additions & 0 deletions pkg/extractor/v6/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,11 @@ func (e *Extractor) ExtractTechnocratFromDoc(doc *goquery.Document) bool {
return extractTechnocratFromDoc(doc)
}

// ExtractAbandonInformation ...
func (e *Extractor) ExtractAbandonInformation(doc *goquery.Document) (string, string) {
return extractAbandonInformation(doc)
}

// </ Extract from doc> -------------------------------------------------------

// <Works with []byte only> ---------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions pkg/extractor/v6/extracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,12 @@ func extractTechnocratFromDoc(doc *goquery.Document) bool {
return doc.Find("div#officers a.technocrat").HasClass("on")
}

func extractAbandonInformation(doc *goquery.Document) (string, string) {
abandonToken := doc.Find("form#planetMaintenanceDelete input[name=abandon]").AttrOr("value", "")
token := doc.Find("form#planetMaintenanceDelete input[name=token]").AttrOr("value", "")
return abandonToken, token
}

func extractPlanetCoordinate(pageHTML []byte) (ogame.Coordinate, error) {
m := regexp.MustCompile(`<meta name="ogame-planet-coordinates" content="(\d+):(\d+):(\d+)"/>`).FindSubmatch(pageHTML)
if len(m) == 0 {
Expand Down
3 changes: 1 addition & 2 deletions pkg/wrapper/ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -1826,8 +1826,7 @@ func (b *OGame) abandon(v any) error {
}
pageHTML, _ := b.getPage(PlanetlayerPageName, ChangePlanet(planet.GetID()))
doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(pageHTML))
abandonToken := doc.Find("form#planetMaintenanceDelete input[name=abandon]").AttrOr("value", "")
token := doc.Find("form#planetMaintenanceDelete input[name=token]").AttrOr("value", "")
abandonToken, token := b.extractor.ExtractAbandonInformation(doc)
payload := url.Values{
"abandon": {abandonToken},
"token": {token},
Expand Down

0 comments on commit 1b51ef5

Please sign in to comment.