New commit
This commit is contained in:
parent
8e468c4ce9
commit
79c6427fc8
69
aocbot.go
69
aocbot.go
@ -11,7 +11,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gogs.bullercodeworks.com/brian/boltease"
|
"github.com/br0xen/boltease"
|
||||||
)
|
)
|
||||||
|
|
||||||
const programName = "aocbot"
|
const programName = "aocbot"
|
||||||
@ -33,8 +33,12 @@ func main() {
|
|||||||
if db, err = getDatabase(); err != nil {
|
if db, err = getDatabase(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
// AoC Channel
|
||||||
slackChannel = "C0G3X1M5K"
|
slackChannel = "C0G3X1M5K"
|
||||||
|
|
||||||
|
// br0xen DM
|
||||||
|
//slackChannel = "D0D793N5R"
|
||||||
|
|
||||||
// DevICT Leaderboard: 3549
|
// DevICT Leaderboard: 3549
|
||||||
boardID = os.Args[2]
|
boardID = os.Args[2]
|
||||||
|
|
||||||
@ -58,37 +62,36 @@ func aocBotMain(slack *Slack) {
|
|||||||
lastAoCUpdate = time.Now()
|
lastAoCUpdate = time.Now()
|
||||||
var leaderboard *Leaderboard
|
var leaderboard *Leaderboard
|
||||||
fmt.Println(lastAoCUpdate.Format(time.RFC3339) + ": Fetching Online Leaderboard")
|
fmt.Println(lastAoCUpdate.Format(time.RFC3339) + ": Fetching Online Leaderboard")
|
||||||
if leaderboard, err = getAoCLeaderboard(boardID); err != nil {
|
leaderboard, err = getAoCLeaderboard(boardID)
|
||||||
fmt.Println(err.Error())
|
if err == nil {
|
||||||
}
|
for _, v := range leaderboard.Members {
|
||||||
|
var mbr *Member
|
||||||
for _, v := range leaderboard.Members {
|
if mbr, err = getAoCUser(v.ID); err != nil {
|
||||||
var mbr *Member
|
// Member doesn't exist in db, add it
|
||||||
if mbr, err = getAoCUser(v.ID); err != nil {
|
// Notify br0xen ( U030RD9NU )
|
||||||
// Member doesn't exist in db, add it
|
m := new(Message)
|
||||||
// Notify br0xen ( U030RD9NU )
|
m.Type = "message"
|
||||||
m := new(Message)
|
m.Channel = "D0D793N5R"
|
||||||
m.Type = "message"
|
m.Text = "AoC Leaderboard has a new member! " + v.Name
|
||||||
m.Channel = "D0D793N5R"
|
fmt.Println("New Leaderboard Member Found: " + v.Name)
|
||||||
m.Text = "AoC Leaderboard has a new member! " + v.Name
|
if err = slack.postMessage(*m); err != nil {
|
||||||
fmt.Println("New Leaderboard Member Found: " + v.Name)
|
fmt.Println(err.Error())
|
||||||
if err = slack.postMessage(*m); err != nil {
|
}
|
||||||
fmt.Println(err.Error())
|
saveAoCUser(&v)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
saveAoCUser(&v)
|
if mbr.Stars != v.Stars {
|
||||||
continue
|
// Number of stars has changed
|
||||||
}
|
fmt.Println(v.ID + "(" + v.Name + "): " + v.LastStarTs.Format(time.RFC3339))
|
||||||
if mbr.Stars != v.Stars {
|
m := new(Message)
|
||||||
// Number of stars has changed
|
m.Type = "message"
|
||||||
fmt.Println(v.ID + "(" + v.Name + "): " + v.LastStarTs.Format(time.RFC3339))
|
m.Channel = slackChannel
|
||||||
m := new(Message)
|
m.Text = ":christmas_tree: " + v.Name + " now has " + strconv.Itoa(v.Stars) + " stars! :christmas_tree:"
|
||||||
m.Type = "message"
|
if err = slack.postMessage(*m); err != nil {
|
||||||
m.Channel = slackChannel
|
fmt.Println(err.Error())
|
||||||
m.Text = ":christmas_tree: " + v.Name + " now has " + strconv.Itoa(v.Stars) + " stars! :christmas_tree:"
|
}
|
||||||
if err = slack.postMessage(*m); err != nil {
|
saveAoCUser(&v)
|
||||||
fmt.Println(err.Error())
|
|
||||||
}
|
}
|
||||||
saveAoCUser(&v)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time.Sleep(time.Minute * 10)
|
time.Sleep(time.Minute * 10)
|
||||||
@ -126,7 +129,6 @@ func processMessage(slack *Slack, m *Message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Process the message
|
|
||||||
if m.Channel != "" {
|
if m.Channel != "" {
|
||||||
// Check if we know what the channel is
|
// Check if we know what the channel is
|
||||||
chnl, err := getChannelInfo(m.Channel)
|
chnl, err := getChannelInfo(m.Channel)
|
||||||
@ -257,6 +259,7 @@ func getAoCLeaderboard(boardId string) (*Leaderboard, error) {
|
|||||||
resp, err = client.Do(req)
|
resp, err = client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error getting leaderboard")
|
fmt.Println("Error getting leaderboard")
|
||||||
|
return leaderboard, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err = ioutil.ReadAll(resp.Body)
|
body, err = ioutil.ReadAll(resp.Body)
|
||||||
@ -265,6 +268,10 @@ func getAoCLeaderboard(boardId string) (*Leaderboard, error) {
|
|||||||
return leaderboard, err
|
return leaderboard, err
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(body, &leaderboard)
|
err = json.Unmarshal(body, &leaderboard)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error on json unmarshal")
|
||||||
|
return leaderboard, err
|
||||||
|
}
|
||||||
for k, mbr := range leaderboard.Members {
|
for k, mbr := range leaderboard.Members {
|
||||||
mbr.LastStarTs, err = time.Parse("2006-01-02T15:04:05-0700", mbr.RawStarTs)
|
mbr.LastStarTs, err = time.Parse("2006-01-02T15:04:05-0700", mbr.RawStarTs)
|
||||||
leaderboard.Members[k] = mbr
|
leaderboard.Members[k] = mbr
|
||||||
|
10
model.go
10
model.go
@ -4,7 +4,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gogs.bullercodeworks.com/brian/boltease"
|
"github.com/br0xen/boltease"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getDatabase() (*boltease.DB, error) {
|
func getDatabase() (*boltease.DB, error) {
|
||||||
@ -226,3 +226,11 @@ func getAoCUserByName(nm string) (*Member, error) {
|
|||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getUserSlackIDFromAoCName(nm string) (string, error) {
|
||||||
|
m, err := getAoCUserByName(nm)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return m.SlackID, nil
|
||||||
|
}
|
||||||
|
@ -12,7 +12,27 @@ type Message struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
Ts string `json:"ts"`
|
Ts string `json:"ts"`
|
||||||
Time time.Time
|
|
||||||
|
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
|
// Channel object
|
||||||
|
Reference in New Issue
Block a user