From 9cc636f9aaa84c19c842f16265ce900b02e47ef0 Mon Sep 17 00:00:00 2001 From: Alain Gilbert Date: Wed, 27 Jul 2022 00:17:09 -0700 Subject: [PATCH] put account in vacation mode --- README.md | 1 + interfaces.go | 1 + ogame.go | 22 ++++++++++++++++++++++ prioritize.go | 7 +++++++ 4 files changed, 31 insertions(+) diff --git a/README.md b/README.md index 9ad8ecbd..5dcb1edb 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/interfaces.go b/interfaces.go index 6734bd72..f2639132 100644 --- a/interfaces.go +++ b/interfaces.go @@ -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 diff --git a/ogame.go b/ogame.go index 9d2f30b5..52ce8a18 100644 --- a/ogame.go +++ b/ogame.go @@ -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 { @@ -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 diff --git a/prioritize.go b/prioritize.go index 93659474..122ff353 100644 --- a/prioritize.go +++ b/prioritize.go @@ -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")