71 lines
1.3 KiB
Go
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)
|
|
}
|
|
}
|