Skip to content

Commit

Permalink
* Added Function
Browse files Browse the repository at this point in the history
- GetLfBuildings(celestialID ogame.CelestialID, opts ...Option) (ogame.LfBuildings, error)
  • Loading branch information
faunX authored and faunX committed Sep 15, 2022
1 parent 6269d60 commit 8bf3d81
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 22 deletions.
7 changes: 6 additions & 1 deletion pkg/parser/fullPage.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package parser

import (
"github.com/alaingilbert/ogame/pkg/ogame"
"time"

"github.com/alaingilbert/ogame/pkg/ogame"
)

func (p FullPage) ExtractOGameSession() string {
Expand Down Expand Up @@ -45,6 +46,10 @@ func (p FullPage) ExtractLifeformEnabled() bool {
return p.e.ExtractLifeformEnabled(p.GetContent())
}

func (p FullPage) ExtractLfBuildings() (ogame.LfBuildings, error) {
return p.e.ExtractLfBuildings(p.GetContent())
}

func (p FullPage) ExtractServerTime() (time.Time, error) {
return p.e.ExtractServerTimeFromDoc(p.GetDoc())
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/wrapper/fetcher.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package wrapper

import (
"github.com/alaingilbert/ogame/pkg/parser"
"net/url"

"github.com/alaingilbert/ogame/pkg/parser"
)

// Page names
Expand Down Expand Up @@ -82,6 +83,8 @@ func getPage[T parser.FullPagePages](b *OGame, opts ...Option) (T, error) {
pageName = DefensesPageName
case parser.ResearchPage:
pageName = ResearchPageName
case parser.LfBuildingsPage:
pageName = LfbuildingsPageName
case parser.ShipyardPage:
pageName = ShipyardPageName
case parser.ResourcesSettingsPage:
Expand Down
8 changes: 5 additions & 3 deletions pkg/wrapper/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package wrapper

import (
"crypto/tls"
"net/http"
"net/url"
"time"

"github.com/alaingilbert/ogame/pkg/extractor"
"github.com/alaingilbert/ogame/pkg/httpclient"
"github.com/alaingilbert/ogame/pkg/ogame"
"github.com/alaingilbert/ogame/pkg/taskRunner"
"net/http"
"net/url"
"time"
)

// Celestial superset of ogame.Celestial.
Expand Down Expand Up @@ -125,6 +126,7 @@ type Prioritizable interface {
GetTechs(celestialID ogame.CelestialID) (ogame.ResourcesBuildings, ogame.Facilities, ogame.ShipsInfos, ogame.DefensesInfos, ogame.Researches, error)
SendFleet(celestialID ogame.CelestialID, ships []ogame.Quantifiable, speed ogame.Speed, where ogame.Coordinate, mission ogame.MissionID, resources ogame.Resources, holdingTime, unionID int64) (ogame.Fleet, error)
TearDown(celestialID ogame.CelestialID, id ogame.ID) error
GetLfBuildings(ogame.CelestialID, ...Option) (ogame.LfBuildings, error)

// Planet specific functions
DestroyRockets(ogame.PlanetID, int64, int64) error
Expand Down
46 changes: 31 additions & 15 deletions pkg/wrapper/ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,6 @@ import (
"encoding/json"
err2 "errors"
"fmt"
"github.com/alaingilbert/clockwork"
"github.com/alaingilbert/ogame/pkg/exponentialBackoff"
"github.com/alaingilbert/ogame/pkg/extractor"
"github.com/alaingilbert/ogame/pkg/extractor/v6"
"github.com/alaingilbert/ogame/pkg/extractor/v7"
"github.com/alaingilbert/ogame/pkg/extractor/v71"
"github.com/alaingilbert/ogame/pkg/extractor/v8"
"github.com/alaingilbert/ogame/pkg/extractor/v874"
"github.com/alaingilbert/ogame/pkg/extractor/v9"
"github.com/alaingilbert/ogame/pkg/httpclient"
"github.com/alaingilbert/ogame/pkg/ogame"
"github.com/alaingilbert/ogame/pkg/parser"
"github.com/alaingilbert/ogame/pkg/taskRunner"
"github.com/alaingilbert/ogame/pkg/utils"
"image"
"image/color"
"image/png"
Expand All @@ -42,6 +28,21 @@ import (
"sync/atomic"
"time"

"github.com/alaingilbert/clockwork"
"github.com/alaingilbert/ogame/pkg/exponentialBackoff"
"github.com/alaingilbert/ogame/pkg/extractor"
v6 "github.com/alaingilbert/ogame/pkg/extractor/v6"
v7 "github.com/alaingilbert/ogame/pkg/extractor/v7"
v71 "github.com/alaingilbert/ogame/pkg/extractor/v71"
v8 "github.com/alaingilbert/ogame/pkg/extractor/v8"
v874 "github.com/alaingilbert/ogame/pkg/extractor/v874"
v9 "github.com/alaingilbert/ogame/pkg/extractor/v9"
"github.com/alaingilbert/ogame/pkg/httpclient"
"github.com/alaingilbert/ogame/pkg/ogame"
"github.com/alaingilbert/ogame/pkg/parser"
"github.com/alaingilbert/ogame/pkg/taskRunner"
"github.com/alaingilbert/ogame/pkg/utils"

"github.com/PuerkitoBio/goquery"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
version "github.com/hashicorp/go-version"
Expand Down Expand Up @@ -2878,6 +2879,15 @@ func (b *OGame) getResourcesBuildings(celestialID ogame.CelestialID, options ...
return page.ExtractResourcesBuildings()
}

func (b *OGame) getLfBuildings(celestialID ogame.CelestialID, options ...Option) (ogame.LfBuildings, error) {
options = append(options, ChangePlanet(celestialID))
page, err := getPage[parser.LfBuildingsPage](b, options...)
if err != nil {
return ogame.LfBuildings{}, err
}
return page.ExtractLfBuildings()
}

func (b *OGame) getDefense(celestialID ogame.CelestialID, options ...Option) (ogame.DefensesInfos, error) {
options = append(options, ChangePlanet(celestialID))
page, err := getPage[parser.DefensesPage](b, options...)
Expand Down Expand Up @@ -4663,7 +4673,8 @@ func (b *OGame) RegisterHTMLInterceptor(fn func(method, url string, params, payl
// Phalanx scan a coordinate from a moon to get fleets information
// IMPORTANT: My account was instantly banned when I scanned an invalid coordinate.
// IMPORTANT: This function DOES validate that the coordinate is a valid planet in range of phalanx
// and that you have enough deuterium.
//
// and that you have enough deuterium.
func (b *OGame) Phalanx(moonID ogame.MoonID, coord ogame.Coordinate) ([]ogame.Fleet, error) {
return b.WithPriority(taskRunner.Normal).Phalanx(moonID, coord)
}
Expand Down Expand Up @@ -4777,3 +4788,8 @@ func (b *OGame) OfferSellMarketplace(itemID any, quantity, priceType, price, pri
func (b *OGame) OfferBuyMarketplace(itemID any, quantity, priceType, price, priceRange int64, celestialID ogame.CelestialID) error {
return b.WithPriority(taskRunner.Normal).OfferBuyMarketplace(itemID, quantity, priceType, price, priceRange, celestialID)
}

// GetLfBuildings ...
func (b *OGame) GetLfBuildings(celestialID ogame.CelestialID, opts ...Option) (ogame.LfBuildings, error) {
return b.WithPriority(taskRunner.Normal).GetLfBuildings(celestialID, opts...)
}
13 changes: 11 additions & 2 deletions pkg/wrapper/prioritize.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package wrapper

import (
"github.com/alaingilbert/ogame/pkg/ogame"
"net/http"
"net/url"
"sync/atomic"
"time"

"github.com/alaingilbert/ogame/pkg/ogame"
)

// Prioritize ...
Expand Down Expand Up @@ -560,7 +561,8 @@ func (b *Prioritize) FlightTime(origin, destination ogame.Coordinate, speed ogam
// Phalanx scan a coordinate from a moon to get fleets information
// IMPORTANT: My account was instantly banned when I scanned an invalid coordinate.
// IMPORTANT: This function DOES validate that the coordinate is a valid planet in range of phalanx
// and that you have enough deuterium.
//
// and that you have enough deuterium.
func (b *Prioritize) Phalanx(moonID ogame.MoonID, coord ogame.Coordinate) ([]ogame.Fleet, error) {
b.begin("Phalanx")
defer b.done()
Expand Down Expand Up @@ -706,3 +708,10 @@ func (b *Prioritize) OfferBuyMarketplace(itemID any, quantity, priceType, price,
defer b.done()
return b.bot.offerMarketplace(3, itemID, quantity, priceType, price, priceRange, celestialID)
}

// OfferBuyMarketplace ...
func (b *Prioritize) GetLfBuildings(celestialID ogame.CelestialID, options ...Option) (ogame.LfBuildings, error) {
b.begin("GetLfBuildings")
defer b.done()
return b.bot.getLfBuildings(celestialID, options...)
}

0 comments on commit 8bf3d81

Please sign in to comment.