From b45a28156c4f6ad02cdc9ce5def8777414746d16 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Sat, 12 Feb 2022 01:00:45 -0600 Subject: [PATCH] Add projects to profile user command --- src/discord/commands.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/discord/commands.go b/src/discord/commands.go index 8b9fc641..5918bd6c 100644 --- a/src/discord/commands.go +++ b/src/discord/commands.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" + "git.handmade.network/hmn/hmn/src/hmndata" + "git.handmade.network/hmn/hmn/src/db" "git.handmade.network/hmn/hmn/src/hmnurl" "git.handmade.network/hmn/hmn/src/logging" @@ -122,11 +124,31 @@ func (bot *botInstance) handleProfileCommand(ctx context.Context, i *Interaction } 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) + 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{ Type: InteractionCallbackTypeChannelMessageWithSource, Data: &InteractionCallbackData{ - Content: fmt.Sprintf("<@%s>'s profile can be viewed at %s.", member.User.ID, url), + Content: msg, Flags: FlagEphemeral, }, })