Skip to content

Commit

Permalink
chore: add more info to the profile command (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
namnhce authored Dec 28, 2023
1 parent 35ecc0d commit 80d2a32
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 98 deletions.
2 changes: 1 addition & 1 deletion pkg/discord/command/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ func (e *ProfileCmd) GetProfile(message *model.DiscordMessage) error {
return e.view.Error().Raise(message, "Failed to get employee profile.")
}

return e.view.Profile().List(message, employees)
return e.view.Profile().Render(message, employees)
}
4 changes: 3 additions & 1 deletion pkg/discord/view/profile/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ import "github.com/dwarvesf/fortress-discord/pkg/model"

type Viewer interface {
Help(message *model.DiscordMessage) error
List(original *model.DiscordMessage, employee []model.Employee) error
Render(original *model.DiscordMessage, employees []model.Employee) error
List(original *model.DiscordMessage, employees []model.Employee) error
Details(original *model.DiscordMessage, employee *model.Employee) error
}
205 changes: 109 additions & 96 deletions pkg/discord/view/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,130 +36,143 @@ func (v *Profile) Help(message *model.DiscordMessage) error {
return base.SendEmbededMessage(v.ses, message, msg)
}

func (v *Profile) List(original *model.DiscordMessage, employees []model.Employee) error {
content := ""
func (v *Profile) Render(original *model.DiscordMessage, employees []model.Employee) error {
msg := &discordgo.MessageEmbed{}
if len(employees) == 0 {
msg.Title = ":warning: **Error Message** :warning: "
msg.Description = fmt.Sprintf("This discord user was not belong to the organization\n\n")
return base.SendEmbededMessage(v.ses, original, msg)
}

if len(employees) == 1 {
employee := employees[0]
targetUser, err := v.ses.GuildMember(original.GuildId, employee.DiscordID)
return v.Details(original, &employees[0])
}
return v.List(original, employees)
}

func (v *Profile) List(original *model.DiscordMessage, employees []model.Employee) error {
msg := &discordgo.MessageEmbed{}
listUsers := ""
for idx, e := range employees {
de, err := v.ses.GuildMember(original.GuildId, e.DiscordID)
if err != nil {
return err
}

avatar := fmt.Sprintf("https://cdn.discordapp.com/avatars/%v/%v.webp?size=240", targetUser.User.ID, targetUser.User.Avatar)
if targetUser.Avatar != "" {
avatar = fmt.Sprintf("https://cdn.discordapp.com/guilds/%v/users/%v/avatars/%v.webp?size=240", original.GuildId, targetUser.User.ID, targetUser.Avatar)
}
listUsers += fmt.Sprintf("%v. %v - `%v` - `%v`\n", idx+1, e.FullName, e.TeamEmail, de.User.Username)
}

if len(targetUser.Roles) > 0 {
roles, err := v.ses.GuildRoles(v.ses.State.Guilds[0].ID)
if err != nil {
return err
}
messageEmbed := []*discordgo.MessageEmbedField{
{
Name: "Search Result:",
Value: listUsers,
Inline: false,
},
}

dfRoles := SortRoleByLevel(DwarvesRoles(roles))
roleStr := ""
previousLevel := -1
line := 0
for _, r := range dfRoles {
for _, ur := range targetUser.Roles {
if r.ID == ur {
if r.Level != previousLevel {
roleStr += fmt.Sprintf("\n`%v.` ", line)
previousLevel = r.Level
line++
}
roleStr += fmt.Sprintf("<@&%v> ", r.ID)
}
}
}
content += fmt.Sprintf("**Roles** %v", strings.TrimSuffix(roleStr, " "))
}
msg.Title = "🔎 Team Profile Search"
msg.Fields = messageEmbed
msg.Description = "To get user profile detail, please search with: \n`?profile @user`\n`?profile email`\n`?profile discordID`"

gender := ":woman:"
if employee.Gender == "Male" {
gender = ":man:"
}
userInfo := ""
userInfo += fmt.Sprintf("%v `Full Name. `**%v**\n", gender, employee.FullName)
userInfo += fmt.Sprintf(":birthday: `DoB. `%v\n", employee.Birthday.Format("2006 Jan 02"))
mmaScores := fmt.Sprintf("%v `Mastery. `%v\n", constant.GetEmoji("BADGE1"), employee.MmaScore.MasteryScore.Round(1))
mmaScores += fmt.Sprintf("%v `Meaning. `%v\n", constant.GetEmoji("BADGE2"), employee.MmaScore.MeaningScore.Round(1))
mmaScores += fmt.Sprintf("%v `Autonomy. `%v\n", constant.GetEmoji("BADGE3"), employee.MmaScore.AutonomyScore.Round(1))

userInfo += "\n**MMA Scores**\n" + mmaScores

userSkill := ""
positions := ""
for _, p := range employee.Positions {
positions += fmt.Sprintf("%v, ", p.Name)
}
return base.SendEmbededMessage(v.ses, original, msg)
}

stacks := ""
for _, s := range employee.Stacks {
stacks += fmt.Sprintf("%v, ", s.Name)
}
func (v *Profile) Details(original *model.DiscordMessage, employee *model.Employee) error {
msg := &discordgo.MessageEmbed{}
content := ""

userSkill += fmt.Sprintf("%v `Position. `%v\n", constant.GetEmoji("BADGE5"), strings.TrimRight(positions, ", "))
userSkill += fmt.Sprintf(":jigsaw: `Stacks. `%v\n", strings.TrimRight(stacks, ", "))
targetUser, err := v.ses.GuildMember(original.GuildId, employee.DiscordID)
if err != nil {
return err
}

userInfo += "\n**Skills**\n" + userSkill
avatar := fmt.Sprintf("https://cdn.discordapp.com/avatars/%v/%v.webp?size=240", targetUser.User.ID, targetUser.User.Avatar)
if targetUser.Avatar != "" {
avatar = fmt.Sprintf("https://cdn.discordapp.com/guilds/%v/users/%v/avatars/%v.webp?size=240", original.GuildId, targetUser.User.ID, targetUser.Avatar)
}

projects := ""
for _, p := range employee.Projects {
projects += fmt.Sprintf("%v, ", p.Name)
if len(targetUser.Roles) > 0 {
roles, err := v.ses.GuildRoles(v.ses.State.Guilds[0].ID)
if err != nil {
return err
}

if projects == "" {
projects = "N/A"
dfRoles := SortRoleByLevel(DwarvesRoles(roles))
roleStr := ""
previousLevel := -1
line := 0
for _, r := range dfRoles {
for _, ur := range targetUser.Roles {
if r.ID == ur {
if r.Level != previousLevel {
roleStr += fmt.Sprintf("\n`%v.` ", line)
previousLevel = r.Level
line++
}
roleStr += fmt.Sprintf("<@&%v> ", r.ID)
}
}
}
content += fmt.Sprintf("**Roles** %v", strings.TrimSuffix(roleStr, " "))
}

userInfo += "\n**Projects:** " + strings.TrimRight(projects, ", ")
gender := ":woman:"
if employee.Gender == "Male" {
gender = ":man:"
}
userInfo := ""
userInfo += fmt.Sprintf("%v `Full Name. `**%v**\n", gender, employee.FullName)
userInfo += fmt.Sprintf(":birthday: `DoB. `%v\n", employee.Birthday.Format("2006 Jan 02"))
userInfo += fmt.Sprintf(":identification_card: `Github. `%v\n", employee.GithubID)
userInfo += fmt.Sprintf(":e_mail: `Team Email. `%v\n", employee.TeamEmail)
userInfo += fmt.Sprintf(":e_mail: `Personal Email. `%v\n", employee.PersonalEmail)
mmaScores := fmt.Sprintf("%v `Mastery. `%v\n", constant.GetEmoji("BADGE1"), employee.MmaScore.MasteryScore.Round(1))
mmaScores += fmt.Sprintf("%v `Meaning. `%v\n", constant.GetEmoji("BADGE2"), employee.MmaScore.MeaningScore.Round(1))
mmaScores += fmt.Sprintf("%v `Autonomy. `%v\n", constant.GetEmoji("BADGE3"), employee.MmaScore.AutonomyScore.Round(1))

userInfo += "\n**MMA Scores**\n" + mmaScores

userSkill := ""
positions := ""
for _, p := range employee.Positions {
positions += fmt.Sprintf("%v, ", p.Name)
}

messageEmbed := []*discordgo.MessageEmbedField{
{
Name: "User Info",
Value: userInfo,
Inline: false,
},
}
stacks := ""
for _, s := range employee.Stacks {
stacks += fmt.Sprintf("%v, ", s.Name)
}

msg.Author = &discordgo.MessageEmbedAuthor{
URL: "https://fortress.d.foundation/" + employee.Username,
Name: targetUser.User.Username,
IconURL: avatar,
}
msg.Fields = messageEmbed
msg.Description = content
} else {
listUsers := ""
for idx, e := range employees {
de, err := v.ses.GuildMember(original.GuildId, e.DiscordID)
if err != nil {
return err
}
userSkill += fmt.Sprintf("%v `Position. `%v\n", constant.GetEmoji("BADGE5"), strings.TrimRight(positions, ", "))
userSkill += fmt.Sprintf(":jigsaw: `Stacks. `%v\n", strings.TrimRight(stacks, ", "))

listUsers += fmt.Sprintf("%v. %v - `%v` - `%v`\n", idx+1, e.FullName, e.TeamEmail, de.User.Username)
}
userInfo += "\n**Skills**\n" + userSkill

messageEmbed := []*discordgo.MessageEmbedField{
{
Name: "Search Result:",
Value: listUsers,
Inline: false,
},
}
projects := ""
for _, p := range employee.Projects {
projects += fmt.Sprintf("%v, ", p.Name)
}

if projects == "" {
projects = "N/A"
}

userInfo += "\n**Projects:** " + strings.TrimRight(projects, ", ")

messageEmbed := []*discordgo.MessageEmbedField{
{
Name: "User Info",
Value: userInfo,
Inline: false,
},
}

msg.Title = "🔎 Team Profile Search"
msg.Fields = messageEmbed
msg.Description = "To get user profile detail, please search with: \n`?profile @user`\n`?profile email`\n`?profile discordID`"
msg.Author = &discordgo.MessageEmbedAuthor{
URL: "https://fortress.d.foundation/" + employee.Username,
Name: targetUser.User.Username,
IconURL: avatar,
}
msg.Fields = messageEmbed
msg.Description = content

return base.SendEmbededMessage(v.ses, original, msg)
}
Expand Down

0 comments on commit 80d2a32

Please sign in to comment.