dcbot/internal/discord/discord.go
Dawid Wysokiński cfbaba198a
All checks were successful
ci/woodpecker/push/govulncheck Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
refactor: twhelp - migrate to /v2 API endpoints (#155)
Reviewed-on: #155
2024-05-02 05:57:24 +00:00

71 lines
1.3 KiB
Go

package discord
import (
"fmt"
"time"
"gitea.dwysokinski.me/twhelp/dcbot/internal/domain"
)
const (
colorGrey = 0x808080
embedDescriptionCharLimit = 4096
)
func formatTimestamp(t time.Time) string {
return t.Format(time.RFC3339)
}
func buildLink(text string, url string) string {
if url == "" {
return text
}
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:"
}
return ":x:"
}
func buildLangMessageID(languageTag string) string {
return "lang." + languageTag
}
func buildPlayerMarkdown(p any) (string, error) {
switch player := p.(type) {
case domain.PlayerMeta:
tag := player.Tribe.Tribe.Tag
if tag == "" {
tag = "-"
}
return buildLink(player.Name, player.ProfileURL) +
" [" +
buildLink(tag, player.Tribe.Tribe.ProfileURL) +
"]", nil
case domain.NullPlayerMeta:
if !player.Valid {
return "-", nil
}
tag := player.Player.Tribe.Tribe.Tag
if tag == "" {
tag = "-"
}
return buildLink(player.Player.Name, player.Player.ProfileURL) +
" [" +
buildLink(tag, player.Player.Tribe.Tribe.ProfileURL) +
"]", nil
default:
return "", fmt.Errorf("can't build player markdown for type: %T", p)
}
}