Skip to content

Commit

Permalink
Merge branch 'release/47.1.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Jul 27, 2022
2 parents cd785bc + 9cc636f commit 3e96743
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ ServerVersion() string
ServerTime() time.Time
Location() *time.Location
IsUnderAttack() (bool, error)
SetVacationMode() error
GetUserInfos() UserInfos
SendMessage(playerID int64, message string) error
SendMessageAlliance(associationID int64, message string) error
Expand Down
1 change: 1 addition & 0 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Prioritizable interface {
SendMessageAlliance(associationID int64, message string) error
ServerTime() time.Time
SetInitiator(initiator string) Prioritizable
SetVacationMode() error
Tx(clb func(tx Prioritizable) error) error
UseDM(string, CelestialID) error

Expand Down
22 changes: 22 additions & 0 deletions ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -2582,6 +2582,23 @@ func (b *OGame) isUnderAttack() (bool, error) {
return res.Hostile > 0, err
}

func (b *OGame) setVacationMode() error {
vals := url.Values{"page": {"ingame"}, "component": {"preferences"}}
pageHTML, err := b.getPageContent(vals)
if err != nil {
return err
}
rgx := regexp.MustCompile(`type='hidden' name='token' value='(\w+)'`)
m := rgx.FindSubmatch(pageHTML)
if len(m) < 2 {
return errors.New("unable to find token")
}
token := string(m[1])
payload := url.Values{"mode": {"save"}, "selectedTab": {"0"}, "urlaubs_modus": {"on"}, "token": {token}}
_, err = b.postPageContent(vals, payload)
return err
}

type resourcesResp struct {
Metal struct {
Resources struct {
Expand Down Expand Up @@ -5378,6 +5395,11 @@ func (b *OGame) GetCachedPreferences() Preferences {
return b.CachedPreferences
}

// SetVacationMode puts account in vacation mode
func (b *OGame) SetVacationMode() error {
return b.WithPriority(Normal).SetVacationMode()
}

// IsVacationModeEnabled returns either or not the bot is in vacation mode
func (b *OGame) IsVacationModeEnabled() bool {
return b.isVacationModeEnabled
Expand Down
7 changes: 7 additions & 0 deletions prioritize.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ func (b *Prioritize) IsUnderAttack() (bool, error) {
return b.bot.isUnderAttack()
}

// SetVacationMode puts account in vacation mode
func (b *Prioritize) SetVacationMode() error {
b.begin("SetVacationMode")
defer b.done()
return b.bot.setVacationMode()
}

// GetPlanets returns the user planets
func (b *Prioritize) GetPlanets() []Planet {
b.begin("GetPlanets")
Expand Down

0 comments on commit 3e96743

Please sign in to comment.