Add projects to profile user command

This commit is contained in:
Ben Visness 2022-02-12 01:00:45 -06:00
parent b2a2b49abe
commit b45a28156c
1 changed files with 23 additions and 1 deletions

View File

@ -5,6 +5,8 @@ import (
"errors" "errors"
"fmt" "fmt"
"git.handmade.network/hmn/hmn/src/hmndata"
"git.handmade.network/hmn/hmn/src/db" "git.handmade.network/hmn/hmn/src/db"
"git.handmade.network/hmn/hmn/src/hmnurl" "git.handmade.network/hmn/hmn/src/hmnurl"
"git.handmade.network/hmn/hmn/src/logging" "git.handmade.network/hmn/hmn/src/logging"
@ -122,11 +124,31 @@ func (bot *botInstance) handleProfileCommand(ctx context.Context, i *Interaction
} }
res := ires.(*profileResult) res := ires.(*profileResult)
projectsAndStuff, err := hmndata.FetchProjects(ctx, bot.dbConn, nil, hmndata.ProjectsQuery{
OwnerIDs: []int{res.HMNUser.ID},
})
if err != nil {
logging.ExtractLogger(ctx).Error().Err(err).Msg("failed to fetch user projects")
}
url := hmnurl.BuildUserProfile(res.HMNUser.Username) url := hmnurl.BuildUserProfile(res.HMNUser.Username)
msg := fmt.Sprintf("<@%s>'s profile can be viewed at %s.", member.User.ID, url)
if len(projectsAndStuff) > 0 {
projectNoun := "projects"
if len(projectsAndStuff) == 1 {
projectNoun = "project"
}
msg += fmt.Sprintf(" They have %d %s:\n", len(projectsAndStuff), projectNoun)
for _, p := range projectsAndStuff {
msg += fmt.Sprintf("- %s: %s\n", p.Project.Name, hmndata.UrlContextForProject(&p.Project).BuildHomepage())
}
}
err = CreateInteractionResponse(ctx, i.ID, i.Token, InteractionResponse{ err = CreateInteractionResponse(ctx, i.ID, i.Token, InteractionResponse{
Type: InteractionCallbackTypeChannelMessageWithSource, Type: InteractionCallbackTypeChannelMessageWithSource,
Data: &InteractionCallbackData{ Data: &InteractionCallbackData{
Content: fmt.Sprintf("<@%s>'s profile can be viewed at %s.", member.User.ID, url), Content: msg,
Flags: FlagEphemeral, Flags: FlagEphemeral,
}, },
}) })