Skip to content

Commit

Permalink
simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Mar 15, 2020
1 parent 8e7191e commit 04a79a0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
2 changes: 1 addition & 1 deletion interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type Wrapper interface {
BuyOfferOfTheDay() error
BytesDownloaded() int64
BytesUploaded() int64
CreateUnion(fleet Fleet) (int64, error)
CreateUnion(fleet Fleet, unionUsers []string) (int64, error)
GetEmpire(nbr int64) (interface{}, error)
HeadersForPage(url string) (http.Header, error)
CharacterClass() CharacterClass
Expand Down
21 changes: 6 additions & 15 deletions ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/hashicorp/go-version"
cookiejar "github.com/orirawlings/persistent-cookiejar"
"github.com/pkg/errors"
lua "github.com/yuin/gopher-lua"
"github.com/yuin/gopher-lua"
"golang.org/x/net/proxy"
"golang.org/x/net/websocket"
)
Expand Down Expand Up @@ -1862,25 +1862,16 @@ func (b *OGame) getEmpire(nbr int64) (interface{}, error) {
return b.extractor.ExtractEmpire([]byte(pageHTML), nbr)
}

func (b *OGame) createUnion(fleet Fleet, allUnionUsers []UserInfos) (int64, error) {
func (b *OGame) createUnion(fleet Fleet, unionUsers []string) (int64, error) {
if fleet.ID == 0 {
return 0, errors.New("invalid fleet id")
}
pageHTML, _ := b.getPageContent(url.Values{"page": {"federationlayer"}, "union": {"0"}, "fleet": {strconv.FormatInt(int64(fleet.ID), 10)}, "target": {strconv.FormatInt(fleet.TargetPlanetID, 10)}, "ajax": {"1"}})
payload := b.extractor.ExtractFederation(pageHTML)

payload.Del("unionUsers")

var unionUsers string
for _, uu := range allUnionUsers {
if unionUsers == "" {
unionUsers += uu.PlayerName
} else {
unionUsers += ";" + uu.PlayerName
}
}

payload.Add("unionUsers", unionUsers)
unionUser := payload.Get("unionUsers")
unionUsers = append(unionUsers, unionUser)
payload.Add("unionUsers", strings.Join(unionUsers, ";"))

by, err := b.postPageContent(url.Values{"page": {"unionchange"}, "ajax": {"1"}}, payload)
if err != nil {
Expand Down Expand Up @@ -4383,7 +4374,7 @@ func (b *OGame) BuyOfferOfTheDay() error {
}

// CreateUnion creates a union
func (b *OGame) CreateUnion(fleet Fleet, users []UserInfos) (int64, error) {
func (b *OGame) CreateUnion(fleet Fleet, users []string) (int64, error) {
return b.WithPriority(Normal).CreateUnion(fleet, users)
}

Expand Down
2 changes: 1 addition & 1 deletion prioritize.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ func (b *Prioritize) BuyOfferOfTheDay() error {
}

// CreateUnion creates a union
func (b *Prioritize) CreateUnion(fleet Fleet, users []UserInfos) (int64, error) {
func (b *Prioritize) CreateUnion(fleet Fleet, users []string) (int64, error) {
b.begin("CreateUnion")
defer b.done()
return b.bot.createUnion(fleet, users)
Expand Down

0 comments on commit 04a79a0

Please sign in to comment.