select by username rather than id

This commit is contained in:
Michael Zhang 2020-10-11 23:30:04 -05:00
parent 1df8b395ce
commit f7a19636e2
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
2 changed files with 7 additions and 4 deletions

7
bot.go
View file

@ -174,11 +174,13 @@ func (bot *Bot) newMessageHandler(s *discordgo.Session, m *discordgo.MessageCrea
return
}
var mapperId int
mapperId, err = strconv.Atoi(parts[1])
var mapper User
mapperName := strings.Join(parts[1:], " ")
mapper, err = bot.api.GetUser(mapperName)
if err != nil {
return
}
mapperId := mapper.Id
err = bot.db.ChannelTrackMapper(m.ChannelID, mapperId, 3)
if err != nil {
@ -191,6 +193,7 @@ func (bot *Bot) newMessageHandler(s *discordgo.Session, m *discordgo.MessageCrea
}()
bot.MessageReactionAdd(m.ChannelID, m.ID, "\xf0\x9f\x91\x8d")
bot.ChannelMessageSend(m.ChannelID, fmt.Sprintf("subscribed to %+v", mapper))
}
return

View file

@ -159,8 +159,8 @@ func (api *Osuapi) BeatmapsetDownload(beatmapSetId int) (path string, err error)
return
}
func (api *Osuapi) GetUser(userId int) (user User, err error) {
url := fmt.Sprintf("/users/%d", userId)
func (api *Osuapi) GetUser(userId string) (user User, err error) {
url := fmt.Sprintf("/users/%s", userId)
err = api.Request("GET", url, &user)
if err != nil {
return