fix pending list
This commit is contained in:
parent
e84affb5e2
commit
6ccacec1ec
2 changed files with 28 additions and 21 deletions
33
bot.go
33
bot.go
|
@ -75,16 +75,14 @@ func (bot *Bot) errWrap(fn interface{}) interface{} {
|
|||
}
|
||||
|
||||
func (bot *Bot) NotifyNewBeatmap(channels []string, newMaps []Beatmapset) (err error) {
|
||||
for i, beatmapSet := range newMaps {
|
||||
for _, beatmapSet := range newMaps {
|
||||
var eventTime time.Time
|
||||
eventTime, err = time.Parse(time.RFC3339, beatmapSet.LastUpdated)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
log.Println(i, "event time", eventTime)
|
||||
|
||||
var (
|
||||
beatmapSet Beatmapset
|
||||
gotDownloadedBeatmap = false
|
||||
downloadedBeatmap BeatmapsetDownloaded
|
||||
// status git.Status
|
||||
|
@ -130,10 +128,6 @@ func (bot *Bot) NotifyNewBeatmap(channels []string, newMaps []Beatmapset) (err e
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
// status, err = worktree.Status()
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
files, err = ioutil.ReadDir(repoDir)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -155,31 +149,34 @@ func (bot *Bot) NotifyNewBeatmap(channels []string, newMaps []Beatmapset) (err e
|
|||
},
|
||||
)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("couldn't create commit for %s: %w", beatmapSet.ID, err)
|
||||
return
|
||||
}
|
||||
|
||||
commit, err = repo.CommitObject(hash)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("couldn't find commit with hash %s: %w", hash, err)
|
||||
return
|
||||
}
|
||||
parent, err = commit.Parent(0)
|
||||
if err == object.ErrParentNotFound {
|
||||
|
||||
if errors.Is(err, object.ErrParentNotFound) {
|
||||
err = nil
|
||||
} else if err != nil {
|
||||
err = fmt.Errorf("couldn't retrieve commit parent: %w", err)
|
||||
return
|
||||
} else {
|
||||
patch, err = commit.Patch(parent)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("couldn't retrieve patch: %w", err)
|
||||
return
|
||||
}
|
||||
foundPatch = true
|
||||
}
|
||||
|
||||
log.Println("BEATMAP SET", beatmapSet)
|
||||
embed := &discordgo.MessageEmbed{
|
||||
URL: fmt.Sprintf("https://osu.ppy.sh/s/%d", beatmapSet.ID),
|
||||
Title: fmt.Sprintf("Update: %s - %s", beatmapSet.Artist, beatmapSet.Title),
|
||||
Timestamp: eventTime.String(),
|
||||
Timestamp: eventTime.Format(time.RFC3339),
|
||||
Author: &discordgo.MessageEmbedAuthor{
|
||||
URL: "https://osu.ppy.sh/u/" + strconv.Itoa(beatmapSet.UserId),
|
||||
Name: beatmapSet.Creator,
|
||||
|
@ -197,12 +194,22 @@ func (bot *Bot) NotifyNewBeatmap(channels []string, newMaps []Beatmapset) (err e
|
|||
if gotDownloadedBeatmap {
|
||||
log.Println(downloadedBeatmap)
|
||||
if foundPatch {
|
||||
embed.Description = patch.Stats().String()
|
||||
embed.Description = fmt.Sprintf(
|
||||
"Latest revision: %s\n%s",
|
||||
hash,
|
||||
patch.Stats().String(),
|
||||
)
|
||||
} else {
|
||||
embed.Description = "Newly tracked map; diff information will be reported upon next update!"
|
||||
}
|
||||
}
|
||||
|
||||
for _, channelId := range channels {
|
||||
bot.ChannelMessageSendEmbed(channelId, embed)
|
||||
_, err = bot.ChannelMessageSendEmbed(channelId, embed)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to send to %s: %w", channelId, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
16
scrape.go
16
scrape.go
|
@ -14,7 +14,7 @@ var (
|
|||
func RunScraper(bot *Bot, db *Db, api *Osuapi, requests chan int) {
|
||||
lastUpdateTime := time.Now()
|
||||
go func() {
|
||||
for range ticker.C {
|
||||
for ; true; <-ticker.C {
|
||||
// build a list of currently tracked mappers
|
||||
trackedMappers := make(map[int]int)
|
||||
db.IterTrackedMappers(func(userId int) error {
|
||||
|
@ -30,8 +30,8 @@ func RunScraper(bot *Bot, db *Db, api *Osuapi, requests chan int) {
|
|||
|
||||
allNewMaps := make(map[int][]Beatmapset, 0)
|
||||
var newLastUpdateTime = time.Unix(0, 0)
|
||||
for _, beatmap := range pendingSets.Beatmapsets {
|
||||
updatedTime, err := time.Parse(time.RFC3339, beatmap.LastUpdated)
|
||||
for _, beatmapSet := range pendingSets.Beatmapsets {
|
||||
updatedTime, err := time.Parse(time.RFC3339, beatmapSet.LastUpdated)
|
||||
if err != nil {
|
||||
log.Println("error parsing last updated time", updatedTime)
|
||||
}
|
||||
|
@ -45,33 +45,33 @@ func RunScraper(bot *Bot, db *Db, api *Osuapi, requests chan int) {
|
|||
break
|
||||
}
|
||||
|
||||
if mapperId, ok := trackedMappers[beatmap.UserId]; ok {
|
||||
mapperId := beatmapSet.UserId
|
||||
if _, ok := trackedMappers[mapperId]; ok {
|
||||
if _, ok2 := allNewMaps[mapperId]; !ok2 {
|
||||
allNewMaps[mapperId] = make([]Beatmapset, 0)
|
||||
}
|
||||
|
||||
allNewMaps[mapperId] = append(allNewMaps[mapperId], beatmap)
|
||||
allNewMaps[mapperId] = append(allNewMaps[mapperId], beatmapSet)
|
||||
}
|
||||
}
|
||||
|
||||
if len(allNewMaps) > 0 {
|
||||
log.Println("all new maps", allNewMaps)
|
||||
for mapperId, newMaps := range allNewMaps {
|
||||
channels := make([]string, 0)
|
||||
db.IterTrackingChannels(mapperId, func(channelId string) error {
|
||||
channels = append(channels, channelId)
|
||||
return nil
|
||||
})
|
||||
log.Println(newMaps)
|
||||
|
||||
err := bot.NotifyNewBeatmap(channels, newMaps)
|
||||
if err != nil {
|
||||
log.Println("error notifying new maps", err)
|
||||
log.Println("error notifying new maps:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastUpdateTime = newLastUpdateTime
|
||||
fmt.Print("\a")
|
||||
log.Println("last updated time", lastUpdateTime)
|
||||
}
|
||||
}()
|
||||
|
|
Loading…
Reference in a new issue