-
Notifications
You must be signed in to change notification settings - Fork 1
/
apis.go
81 lines (73 loc) · 2.7 KB
/
apis.go
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
package apis
import (
"darkbot/app/configurator"
"darkbot/app/discorder"
"darkbot/app/scrappy"
"darkbot/app/settings/types"
)
type Players struct {
Systems configurator.ConfiguratorSystem
Regions configurator.ConfiguratorRegion
Enemies configurator.ConfiguratorPlayerEnemy
Friends configurator.ConfiguratorPlayerFriend
Events configurator.ConfiguratorPlayerEvent
}
type Alerts struct {
NeutralsGreaterThan configurator.CfgAlertNeutralPlayersGreaterThan
EnemiesGreaterThan configurator.CfgAlertEnemyPlayersGreaterThan
FriendsGreaterThan configurator.CfgAlertFriendPlayersGreaterThan
BaseHealthLowerThan configurator.CfgAlertBaseHealthLowerThan
BaseHealthIsDecreasing configurator.CfgAlertBaseHealthIsDecreasing
BaseIsUnderAttack configurator.CfgAlertBaseIsUnderAttack
PingMessage configurator.CfgAlertPingMessage
}
type API struct {
Discorder discorder.Discorder
ChannelID types.DiscordChannelID
Scrappy *scrappy.ScrappyStorage
Bases configurator.ConfiguratorBase
Players Players
Alerts Alerts
Configur *configurator.Configurator
}
type apiParam func(api *API)
func WithStorage(storage *scrappy.ScrappyStorage) apiParam {
return func(api *API) {
api.Scrappy = storage
}
}
// Reusing API is important. db connections are memory leaking or some other stuff
func (api *API) SetChannelID(ChannelID types.DiscordChannelID) *API {
api.ChannelID = ChannelID
return api
}
func NewAPI(ChannelID types.DiscordChannelID, dbpath types.Dbpath, opts ...apiParam) *API {
configur := configurator.NewConfigurator(dbpath)
api := &API{
Configur: configur,
ChannelID: ChannelID,
Discorder: discorder.NewClient(),
Scrappy: scrappy.Storage,
Bases: configurator.NewConfiguratorBase(configur),
Players: Players{
Systems: configurator.NewConfiguratorSystem(configur),
Regions: configurator.NewConfiguratorRegion(configur),
Enemies: configurator.NewConfiguratorPlayerEnemy(configur),
Friends: configurator.NewConfiguratorPlayerFriend(configur),
Events: configurator.NewConfiguratorPlayerEvent(configur),
},
Alerts: Alerts{
NeutralsGreaterThan: configurator.NewCfgAlertNeutralPlayersGreaterThan(configur),
EnemiesGreaterThan: configurator.NewCfgAlertEnemyPlayersGreaterThan(configur),
FriendsGreaterThan: configurator.NewCfgAlertFriendPlayersGreaterThan(configur),
BaseHealthLowerThan: configurator.NewCfgAlertBaseHealthLowerThan(configur),
BaseHealthIsDecreasing: configurator.NewCfgAlertBaseHealthIsDecreasing(configur),
BaseIsUnderAttack: configurator.NewCfgAlertBaseIsUnderAttack(configur),
PingMessage: configurator.NewCfgAlertPingMessage(configur),
},
}
for _, opt := range opts {
opt(api)
}
return api
}