Skip to content

Commit

Permalink
fix detected attacks when attacking someone
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Sep 8, 2018
1 parent 070c98e commit 16b59f4
Show file tree
Hide file tree
Showing 3 changed files with 1,050 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,10 @@ func extractAttacks(pageHTML string) []AttackEvent {
if strings.Contains(classes, "partnerInfo") {
return
}
isHostile := s.Find("td.countDown.hostile").Size() > 0
if !isHostile {
return
}
missionTypeStr, _ := s.Attr("data-mission-type")
arrivalTimeStr, _ := s.Attr("data-arrival-time")
missionTypeInt, _ := strconv.Atoi(missionTypeStr)
Expand Down
6 changes: 6 additions & 0 deletions ogame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ func TestExtractAttacks(t *testing.T) {
assert.Equal(t, 1, len(attacks))
}

func TestExtractAttacksMeAttacking(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/eventlist_me_attacking.html")
attacks := extractAttacks(string(pageHTMLBytes))
assert.Equal(t, 0, len(attacks))
}

func TestExtractAttacksWithoutShips(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/event_list_attack.html")
attacks := extractAttacks(string(pageHTMLBytes))
Expand Down
Loading

0 comments on commit 16b59f4

Please sign in to comment.