refactor: make lists more readable (#32)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #32
This commit is contained in:
parent
77c52c117e
commit
ddf7efe273
|
@ -366,15 +366,39 @@ func (c *groupCommand) handleList(s *discordgo.Session, i *discordgo.Interaction
|
|||
return
|
||||
}
|
||||
|
||||
fields := make([]*discordgo.MessageEmbedField, 0, len(groups))
|
||||
for _, g := range groups {
|
||||
channelGains := "Not set"
|
||||
if g.ChannelGains != "" {
|
||||
channelGains = buildChannelMention(g.ChannelGains)
|
||||
}
|
||||
channelLosses := "Not set"
|
||||
if g.ChannelLosses != "" {
|
||||
channelLosses = buildChannelMention(g.ChannelLosses)
|
||||
}
|
||||
fields = append(fields, &discordgo.MessageEmbedField{
|
||||
Name: g.ID,
|
||||
Value: fmt.Sprintf(
|
||||
"**Server**: %s\n**Channel gains**: %s\n**Channel losses**: %s\n**Internals**: %s\n **Barbarians**: %s",
|
||||
g.ServerKey,
|
||||
channelGains,
|
||||
channelLosses,
|
||||
boolToEmoji(g.Internals),
|
||||
boolToEmoji(g.Barbarians),
|
||||
),
|
||||
Inline: false,
|
||||
})
|
||||
}
|
||||
|
||||
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Embeds: []*discordgo.MessageEmbed{
|
||||
{
|
||||
Type: discordgo.EmbedTypeRich,
|
||||
Title: "Group list",
|
||||
Description: buildGroupListDescription(groups),
|
||||
Timestamp: formatTimestamp(time.Now()),
|
||||
Type: discordgo.EmbedTypeRich,
|
||||
Title: "Group list",
|
||||
Fields: fields,
|
||||
Timestamp: formatTimestamp(time.Now()),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -622,28 +646,3 @@ func (c *groupCommand) handleDelete(s *discordgo.Session, i *discordgo.Interacti
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
func buildGroupListDescription(groups []domain.Group) string {
|
||||
description := "**ID** - **Server** - **Channel gains** - **Channel losses** - **Internals** - **Barbarians**"
|
||||
for i, g := range groups {
|
||||
channelGains := "Not set"
|
||||
if g.ChannelGains != "" {
|
||||
channelGains = "<#" + g.ChannelGains + ">"
|
||||
}
|
||||
channelLosses := "Not set"
|
||||
if g.ChannelLosses != "" {
|
||||
channelLosses = "<#" + g.ChannelLosses + ">"
|
||||
}
|
||||
description += fmt.Sprintf(
|
||||
"\n%d. %s - %s - %s - %s - %s - %s",
|
||||
i+1,
|
||||
g.ID,
|
||||
g.ServerKey,
|
||||
channelGains,
|
||||
channelLosses,
|
||||
boolToEmoji(g.Internals),
|
||||
boolToEmoji(g.Barbarians),
|
||||
)
|
||||
}
|
||||
return description
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"gitea.dwysokinski.me/twhelp/dcbot/internal/domain"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
|
@ -168,15 +167,24 @@ func (c *monitorCommand) handleList(s *discordgo.Session, i *discordgo.Interacti
|
|||
return
|
||||
}
|
||||
|
||||
fields := make([]*discordgo.MessageEmbedField, 0, len(monitors))
|
||||
for _, m := range monitors {
|
||||
fields = append(fields, &discordgo.MessageEmbedField{
|
||||
Name: m.ID,
|
||||
Value: fmt.Sprintf("**Tribe**: %s", buildLink(m.Tribe.Tag, m.Tribe.ProfileURL)),
|
||||
Inline: false,
|
||||
})
|
||||
}
|
||||
|
||||
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Embeds: []*discordgo.MessageEmbed{
|
||||
{
|
||||
Type: discordgo.EmbedTypeRich,
|
||||
Title: "Monitor list",
|
||||
Description: buildMonitorListDescription(monitors),
|
||||
Timestamp: formatTimestamp(time.Now()),
|
||||
Type: discordgo.EmbedTypeRich,
|
||||
Title: "Monitor list",
|
||||
Fields: fields,
|
||||
Timestamp: formatTimestamp(time.Now()),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -204,11 +212,3 @@ func (c *monitorCommand) handleDelete(s *discordgo.Session, i *discordgo.Interac
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
func buildMonitorListDescription(monitors []domain.MonitorWithTribe) string {
|
||||
description := "**ID** - **Tribe**"
|
||||
for i, m := range monitors {
|
||||
description += fmt.Sprintf("\n%d. %s - %s", i+1, m.ID, buildLink(m.Tribe.Tag, m.Tribe.ProfileURL))
|
||||
}
|
||||
return description
|
||||
}
|
||||
|
|
|
@ -31,6 +31,10 @@ func buildLink(text string, url string) string {
|
|||
return fmt.Sprintf("[`%s`](%s)", text, url)
|
||||
}
|
||||
|
||||
func buildChannelMention(id string) string {
|
||||
return "<#" + id + ">"
|
||||
}
|
||||
|
||||
func boolToEmoji(val bool) string {
|
||||
if val {
|
||||
return ":white_check_mark:"
|
||||
|
|
Loading…
Reference in New Issue
Block a user