-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathview.go
More file actions
110 lines (87 loc) · 2.82 KB
/
view.go
File metadata and controls
110 lines (87 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import (
"fmt"
"math/big"
"strings"
"time"
tb "gopkg.in/tucnak/telebot.v2"
)
func (et *etubot) gas(msg *tb.Message) {
et.gasMu.RLock()
gasPrice := et.gasPrice
et.gasMu.RUnlock()
et.bot.Reply(msg, fmt.Sprintf("%d gwei", ToGwei(gasPrice)))
}
func (et *etubot) raidGas(msg *tb.Message) {
et.raidGasMu.RLock()
gasPrice := big.NewInt(0).Add(et.raidGasPrice, RaidGasExtra)
et.raidGasMu.RUnlock()
et.bot.Reply(msg, fmt.Sprintf("%d gwei", ToGwei(gasPrice)))
}
func (et *etubot) sendTeams(msg *tb.Message) {
teams, err := et.allTeams()
if err != nil {
et.sendError(fmt.Errorf("error fetching teams: %v", err))
return
}
sb := fmt.Sprintf("%d teams\n---------------------\n", len(teams))
for _, team := range teams {
teamSummary := fmt.Sprintf("ID: %d\n", team.ID)
teamSummary += fmt.Sprintf("Strength: %d\n", team.Strength)
teamSummary += fmt.Sprintf("Account: %s\n", team.Wallet[:7])
teamSummary += fmt.Sprintf("Status: %s\n", strings.ToLower(team.Status))
sb += "\n" + teamSummary
}
et.bot.Reply(msg, sb)
}
func (et *etubot) sendActiveLoots(msg *tb.Message) {
games, err := et.activeLoots()
if err != nil {
et.sendError(fmt.Errorf("error fetching active loots: %v", err))
return
}
sb := fmt.Sprintf("%d active loots 💰🤑💰\n-------------------------\n", len(games))
for _, game := range games {
lootSummary := "💰 Loot\n"
lootSummary += fmt.Sprintf("Game: %d\n", game.ID)
lootSummary += fmt.Sprintf("Team: %d\n", game.AttackTeamID)
lootSummary += fmt.Sprintf("Account: %s\n", game.AttackTeamOwner[:7])
var lastAction, status string
lastAction = "attacked"
status = "waiting for opponent's reinforcement"
if time.Since(game.lastAttackTime()) > processIntervals {
status = "won"
}
if game.reinforceAttackCount() > game.reinforceDefenseCount() {
lastAction = "reinforced"
if time.Since(game.lastAttackTime()) > processIntervals {
status = "won"
} else if game.reinforceAttackCount() == 2 { // game completed
status = "waiting to settle"
} else {
status = "waiting for opponent's reinforcement"
}
} else if game.reinforceDefenseCount() > game.reinforceAttackCount() {
lastAction = "opponent reinforced"
if time.Since(game.lastAttackTime()) > processIntervals {
status = "lost"
} else {
reinforceStrength, err := game.requiredReinforceStrength(et)
if err != nil {
log.Info("Error getting reinforcement strength")
return
}
status = fmt.Sprintf("%d reinforcement needed", reinforceStrength)
}
}
lootSummary += fmt.Sprintf("Last action: %s\n", lastAction)
lootSummary += fmt.Sprintf("Status: %s\n", status)
if game.canSettle() {
lootSummary += "Ready: yes\n"
} else {
lootSummary += fmt.Sprintf("Settle in: %s\n", time.Until(game.settleTime()))
}
sb += "\n" + lootSummary
}
et.bot.Reply(msg, sb)
}