Update for 2022 API changes
This commit is contained in:
parent
ee6a26629f
commit
09a662a8cd
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -109,3 +110,18 @@ func (m *BotModel) GetString(path []string) (string, error) {
|
||||
func (m *BotModel) SetString(path []string, val string) error {
|
||||
return m.SetBytes(path, []byte(val))
|
||||
}
|
||||
|
||||
func (m *BotModel) GetInt(path []string) (int, error) {
|
||||
bts, err := m.GetBytes(path)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if len(bts) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
return strconv.Atoi(string(bts))
|
||||
}
|
||||
|
||||
func (m *BotModel) SetInt(path []string, val int) error {
|
||||
return m.SetString(path, strconv.Itoa(val))
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -4,7 +4,7 @@ go 1.17
|
||||
|
||||
require (
|
||||
git.bullercodeworks.com/brian/boltease v1.0.0
|
||||
git.bullercodeworks.com/brian/go-adventofcode v1.1.0
|
||||
git.bullercodeworks.com/brian/go-adventofcode v1.1.1
|
||||
github.com/nlopes/slack v0.6.0
|
||||
)
|
||||
|
||||
|
4
go.sum
4
go.sum
@ -1,7 +1,7 @@
|
||||
git.bullercodeworks.com/brian/boltease v1.0.0 h1:kSCdJi+qfnPwdCP2oNUfQ6P4JKWaSWoh10Mx51uuD+Y=
|
||||
git.bullercodeworks.com/brian/boltease v1.0.0/go.mod h1:3EuVzLDHy1zrjBEYc7RsaBohUzYrH1bx2aKM2Fk6t98=
|
||||
git.bullercodeworks.com/brian/go-adventofcode v1.1.0 h1:lrN7JEp+vJmfO7KR+eTitiD90IADBxz62bIKTizs4zU=
|
||||
git.bullercodeworks.com/brian/go-adventofcode v1.1.0/go.mod h1:h/W8Nm8zsrVSjnoA6BRlf38LbaXHR/m6dIq804LOO3w=
|
||||
git.bullercodeworks.com/brian/go-adventofcode v1.1.1 h1:5pp9bPVpTKdErkEcIAqoyuMsvmpQkO8upJ+NUQ+MUv0=
|
||||
git.bullercodeworks.com/brian/go-adventofcode v1.1.1/go.mod h1:h/W8Nm8zsrVSjnoA6BRlf38LbaXHR/m6dIq804LOO3w=
|
||||
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
|
||||
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
|
@ -14,6 +14,8 @@ type Model interface {
|
||||
SetBytes(path []string, val []byte) error
|
||||
GetString(path []string) (string, error)
|
||||
SetString(path []string, val string) error
|
||||
GetInt(path []string) (int, error)
|
||||
SetInt(path []string, val int) error
|
||||
}
|
||||
|
||||
type Message interface {
|
||||
|
@ -140,6 +140,12 @@ func (s *AoCState) runLoop() {
|
||||
if s.GetLatestYear() != s.lastYear {
|
||||
// Latest year changed. Grab that board first.
|
||||
s.lastYear = s.GetLatestYear()
|
||||
admin, adminErr := s.model.GetSlackAdminDMId()
|
||||
if adminErr != nil {
|
||||
s.SendAdminIdError()
|
||||
return
|
||||
}
|
||||
s.SendSlackMessage(fmt.Sprintf(":christmas_tree: AoC Set latest leaderboard to %d", s.lastYear), admin)
|
||||
s.AoCBoardCheckAndUpdate(s.lastYear)
|
||||
time.Sleep(time.Minute)
|
||||
}
|
||||
@ -522,7 +528,7 @@ func (s *AoCState) getChannelId() (string, error) {
|
||||
}
|
||||
|
||||
func (s *AoCState) saveLeaderboard(l *aoc.Leaderboard) error {
|
||||
err := s.model.SetString([]string{"aoc", "leaderboards", l.Event, "owner_id"}, l.OwnerID)
|
||||
err := s.model.SetInt([]string{"aoc", "leaderboards", l.Event, "owner_id"}, l.OwnerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -539,27 +545,28 @@ func (s *AoCState) saveLeaderboard(l *aoc.Leaderboard) error {
|
||||
}
|
||||
|
||||
func (s *AoCState) saveMember(event string, m *aoc.Member) error {
|
||||
err := s.model.SetString([]string{"aoc", "leaderboards", event, "members", m.ID, "id"}, m.ID)
|
||||
strId := strconv.Itoa(m.ID)
|
||||
err := s.model.SetString([]string{"aoc", "leaderboards", event, "members", strId, "id"}, strId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = s.model.SetString([]string{"aoc", "leaderboards", event, "members", m.ID, "stars"}, strconv.Itoa(m.Stars))
|
||||
err = s.model.SetString([]string{"aoc", "leaderboards", event, "members", strId, "stars"}, strconv.Itoa(m.Stars))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = s.model.SetString([]string{"aoc", "leaderboards", event, "members", m.ID, "last_star_ts"}, m.LastStarTs.Format(time.RFC3339))
|
||||
err = s.model.SetString([]string{"aoc", "leaderboards", event, "members", strId, "last_star_ts"}, m.LastStarTs.Format(time.RFC3339))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = s.model.SetString([]string{"aoc", "leaderboards", event, "members", m.ID, "name"}, m.Name)
|
||||
err = s.model.SetString([]string{"aoc", "leaderboards", event, "members", strId, "name"}, m.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = s.model.SetString([]string{"aoc", "leaderboards", event, "members", m.ID, "local_score"}, strconv.Itoa(m.LocalScore))
|
||||
err = s.model.SetString([]string{"aoc", "leaderboards", event, "members", strId, "local_score"}, strconv.Itoa(m.LocalScore))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = s.model.SetString([]string{"aoc", "leaderboards", event, "members", m.ID, "global_score"}, strconv.Itoa(m.GlobalScore))
|
||||
err = s.model.SetString([]string{"aoc", "leaderboards", event, "members", strId, "global_score"}, strconv.Itoa(m.GlobalScore))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -567,7 +574,7 @@ func (s *AoCState) saveMember(event string, m *aoc.Member) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *AoCState) getMemberAllYears(memberId string) map[string]*aoc.Member {
|
||||
func (s *AoCState) getMemberAllYears(memberId int) map[string]*aoc.Member {
|
||||
ret := make(map[string]*aoc.Member)
|
||||
for _, yr := range s.GetListOfAoCYears() {
|
||||
stYr := strconv.Itoa(yr)
|
||||
@ -579,12 +586,12 @@ func (s *AoCState) getMemberAllYears(memberId string) map[string]*aoc.Member {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (s *AoCState) getMember(event string, memberId string) (*aoc.Member, error) {
|
||||
func (s *AoCState) getMember(event string, memberId int) (*aoc.Member, error) {
|
||||
var err error
|
||||
var wrk string
|
||||
mbr := new(aoc.Member)
|
||||
mbrPath := []string{"aoc", "leaderboards", event, "members", memberId}
|
||||
mbr.ID, err = s.model.GetString(append(mbrPath, "id"))
|
||||
mbrPath := []string{"aoc", "leaderboards", event, "members", strconv.Itoa(memberId)}
|
||||
mbr.ID, err = s.model.GetInt(append(mbrPath, "id"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user