mirror of
https://git.sr.ht/~ashkeel/strimertul
synced 2024-09-18 01:50:50 +00:00
Use fixed kilovolt (again..)
This commit is contained in:
parent
d8da04224f
commit
019e48355a
3 changed files with 19 additions and 10 deletions
2
go.mod
2
go.mod
|
@ -10,6 +10,6 @@ require (
|
||||||
github.com/nicklaw5/helix v1.14.0 // indirect
|
github.com/nicklaw5/helix v1.14.0 // indirect
|
||||||
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4
|
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4
|
||||||
github.com/sirupsen/logrus v1.8.1
|
github.com/sirupsen/logrus v1.8.1
|
||||||
github.com/strimertul/kilovolt/v3 v3.0.0
|
github.com/strimertul/kilovolt/v3 v3.0.3
|
||||||
github.com/strimertul/stulbe v0.2.5
|
github.com/strimertul/stulbe v0.2.5
|
||||||
)
|
)
|
||||||
|
|
3
go.sum
3
go.sum
|
@ -105,8 +105,9 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/strimertul/kilovolt-client-go v1.1.1 h1:uy6y/WKJyubAPHb+wPJz5We+fVwzWIplHiclSAhEY2E=
|
github.com/strimertul/kilovolt-client-go v1.1.1 h1:uy6y/WKJyubAPHb+wPJz5We+fVwzWIplHiclSAhEY2E=
|
||||||
github.com/strimertul/kilovolt-client-go v1.1.1/go.mod h1:jXbd37kXDdDeKnOWao/JSNMdSYmuhBBHG+LWIBzuXr8=
|
github.com/strimertul/kilovolt-client-go v1.1.1/go.mod h1:jXbd37kXDdDeKnOWao/JSNMdSYmuhBBHG+LWIBzuXr8=
|
||||||
github.com/strimertul/kilovolt/v3 v3.0.0 h1:3gE0FdH3fL5UgMocR6Z7lI9hk3jD8ds8yL47D4Z7758=
|
|
||||||
github.com/strimertul/kilovolt/v3 v3.0.0/go.mod h1:AgfPYRp+kffN64tcqCcQUZdpL/Dm5DGHIYRDm9t3E0Y=
|
github.com/strimertul/kilovolt/v3 v3.0.0/go.mod h1:AgfPYRp+kffN64tcqCcQUZdpL/Dm5DGHIYRDm9t3E0Y=
|
||||||
|
github.com/strimertul/kilovolt/v3 v3.0.3 h1:1+WmI8bi3Uwylr2l7+zkzr3kFHN73fm1Oala4aXxLQI=
|
||||||
|
github.com/strimertul/kilovolt/v3 v3.0.3/go.mod h1:eweKrkaRD061PYcLS06L0FirEZ+uuQCWMcew7aZhXfk=
|
||||||
github.com/strimertul/stulbe v0.2.5 h1:qrJFwttrWfwSfHsvTgI3moZjhBwbYN8Xe8gicCeISpc=
|
github.com/strimertul/stulbe v0.2.5 h1:qrJFwttrWfwSfHsvTgI3moZjhBwbYN8Xe8gicCeISpc=
|
||||||
github.com/strimertul/stulbe v0.2.5/go.mod h1:0AsY4OVf1dNCwOn9s7KySuAxJ85w88pXeostu1n9E7w=
|
github.com/strimertul/stulbe v0.2.5/go.mod h1:0AsY4OVf1dNCwOn9s7KySuAxJ85w88pXeostu1n9E7w=
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.0/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
github.com/twitchyliquid64/golang-asm v0.15.0/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||||
|
|
|
@ -78,20 +78,28 @@ func NewManager(db *database.DB, hub *kv.Hub, log logrus.FieldLogger) (*Manager,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) update(kvs []database.ModifiedKV) error {
|
func (m *Manager) update(kvs []database.ModifiedKV) error {
|
||||||
m.mu.Lock()
|
|
||||||
defer m.mu.Unlock()
|
|
||||||
for _, kv := range kvs {
|
for _, kv := range kvs {
|
||||||
var err error
|
var err error
|
||||||
switch string(kv.Key) {
|
switch string(kv.Key) {
|
||||||
case ConfigKey:
|
case ConfigKey:
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
err = jsoniter.ConfigFastest.Unmarshal(kv.Data, &m.config)
|
err = jsoniter.ConfigFastest.Unmarshal(kv.Data, &m.config)
|
||||||
case PointsKey:
|
case PointsKey:
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
err = jsoniter.ConfigFastest.Unmarshal(kv.Data, &m.points)
|
err = jsoniter.ConfigFastest.Unmarshal(kv.Data, &m.points)
|
||||||
case GoalsKey:
|
case GoalsKey:
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
err = jsoniter.ConfigFastest.Unmarshal(kv.Data, &m.goals)
|
err = jsoniter.ConfigFastest.Unmarshal(kv.Data, &m.goals)
|
||||||
case RewardsKey:
|
case RewardsKey:
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
err = jsoniter.ConfigFastest.Unmarshal(kv.Data, &m.rewards)
|
err = jsoniter.ConfigFastest.Unmarshal(kv.Data, &m.rewards)
|
||||||
case QueueKey:
|
case QueueKey:
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
err = jsoniter.ConfigFastest.Unmarshal(kv.Data, &m.queue)
|
err = jsoniter.ConfigFastest.Unmarshal(kv.Data, &m.queue)
|
||||||
case CreateRedeemRPC:
|
case CreateRedeemRPC:
|
||||||
var redeem Redeem
|
var redeem Redeem
|
||||||
|
@ -118,7 +126,7 @@ func (m *Manager) update(kvs []database.ModifiedKV) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) SavePoints() error {
|
func (m *Manager) savePoints() error {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
data, _ := jsoniter.ConfigFastest.Marshal(m.points)
|
data, _ := jsoniter.ConfigFastest.Marshal(m.points)
|
||||||
|
@ -135,7 +143,7 @@ func (m *Manager) GetPoints(user string) int64 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) SetPoints(user string, points int64) {
|
func (m *Manager) setPoints(user string, points int64) {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
m.points[user] = points
|
m.points[user] = points
|
||||||
|
@ -145,22 +153,22 @@ func (m *Manager) GivePoints(pointsToGive map[string]int64) error {
|
||||||
// Add points to each user
|
// Add points to each user
|
||||||
for user, points := range pointsToGive {
|
for user, points := range pointsToGive {
|
||||||
balance := m.GetPoints(user)
|
balance := m.GetPoints(user)
|
||||||
m.SetPoints(user, balance+points)
|
m.setPoints(user, balance+points)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save points
|
// Save points
|
||||||
return m.SavePoints()
|
return m.savePoints()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) TakePoints(pointsToTake map[string]int64) error {
|
func (m *Manager) TakePoints(pointsToTake map[string]int64) error {
|
||||||
// Add points to each user
|
// Add points to each user
|
||||||
for user, points := range pointsToTake {
|
for user, points := range pointsToTake {
|
||||||
balance := m.GetPoints(user)
|
balance := m.GetPoints(user)
|
||||||
m.SetPoints(user, balance-points)
|
m.setPoints(user, balance-points)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save points
|
// Save points
|
||||||
return m.SavePoints()
|
return m.savePoints()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) saveQueue() error {
|
func (m *Manager) saveQueue() error {
|
||||||
|
|
Loading…
Reference in a new issue