New commit

This commit is contained in:
Brian Buller 2017-09-26 11:24:17 -05:00
parent 8e468c4ce9
commit 79c6427fc8
3 changed files with 68 additions and 33 deletions

View File

@ -11,7 +11,7 @@ import (
"strings"
"time"
"gogs.bullercodeworks.com/brian/boltease"
"github.com/br0xen/boltease"
)
const programName = "aocbot"
@ -33,8 +33,12 @@ func main() {
if db, err = getDatabase(); err != nil {
panic(err)
}
// AoC Channel
slackChannel = "C0G3X1M5K"
// br0xen DM
//slackChannel = "D0D793N5R"
// DevICT Leaderboard: 3549
boardID = os.Args[2]
@ -58,10 +62,8 @@ func aocBotMain(slack *Slack) {
lastAoCUpdate = time.Now()
var leaderboard *Leaderboard
fmt.Println(lastAoCUpdate.Format(time.RFC3339) + ": Fetching Online Leaderboard")
if leaderboard, err = getAoCLeaderboard(boardID); err != nil {
fmt.Println(err.Error())
}
leaderboard, err = getAoCLeaderboard(boardID)
if err == nil {
for _, v := range leaderboard.Members {
var mbr *Member
if mbr, err = getAoCUser(v.ID); err != nil {
@ -91,6 +93,7 @@ func aocBotMain(slack *Slack) {
saveAoCUser(&v)
}
}
}
time.Sleep(time.Minute * 10)
}
}()
@ -126,7 +129,6 @@ func processMessage(slack *Slack, m *Message) {
}
}
// TODO: Process the message
if m.Channel != "" {
// Check if we know what the channel is
chnl, err := getChannelInfo(m.Channel)
@ -257,6 +259,7 @@ func getAoCLeaderboard(boardId string) (*Leaderboard, error) {
resp, err = client.Do(req)
if err != nil {
fmt.Println("Error getting leaderboard")
return leaderboard, err
}
defer resp.Body.Close()
body, err = ioutil.ReadAll(resp.Body)
@ -265,6 +268,10 @@ func getAoCLeaderboard(boardId string) (*Leaderboard, error) {
return leaderboard, err
}
err = json.Unmarshal(body, &leaderboard)
if err != nil {
fmt.Println("Error on json unmarshal")
return leaderboard, err
}
for k, mbr := range leaderboard.Members {
mbr.LastStarTs, err = time.Parse("2006-01-02T15:04:05-0700", mbr.RawStarTs)
leaderboard.Members[k] = mbr

View File

@ -4,7 +4,7 @@ import (
"strings"
"time"
"gogs.bullercodeworks.com/brian/boltease"
"github.com/br0xen/boltease"
)
func getDatabase() (*boltease.DB, error) {
@ -226,3 +226,11 @@ func getAoCUserByName(nm string) (*Member, error) {
}
return nil, err
}
func getUserSlackIDFromAoCName(nm string) (string, error) {
m, err := getAoCUserByName(nm)
if err != nil {
return "", err
}
return m.SlackID, nil
}

View File

@ -12,9 +12,29 @@ type Message struct {
Name string `json:"name"`
Text string `json:"text"`
Ts string `json:"ts"`
Time time.Time
}
type Attachment struct {
Fallback string `json:"fallback"`
Color string `json:"color"`
Pretext string `json:"pretext"`
AuthorName string `json:"author_name"`
AuthorLink string `json:"author_link"`
AuthorIcon string `json:"author_icon"`
Title string `json:"title"`
TitleLink string `json:"title_link"`
Text string `json:"text"`
//Fields []AttachmentFields `json:"fields"`
ImageUrl string `json:"image_url"`
ThumbUrl string `json:"thumb_url"`
Footer string `json:"footer"`
FooterIcon string `json:"footer_icon"`
RawTS int `json:"ts"`
TS time.Time
}
// Channel object
type Channel struct {
ID string `json:"id"`