Файли
2026-11-08 03:46:11 +00:00

79 рядки
2.2 KiB
Go

package share
import (
"fmt"
"strings"
"git.entityseven.com/rilaxik/pllist/internal/domain"
"git.entityseven.com/rilaxik/pllist/internal/service"
"git.entityseven.com/rilaxik/pllist/internal/telegram/shared"
)
const (
addSharePrompt = "Send the Telegram @username or user ID to share with. /cancel to stop."
shareExpiredText = "This share prompt expired. Open the shares menu again."
)
func sharesText(list service.ShareList) string {
var text strings.Builder
fmt.Fprintf(&text, "<b>Shares: %s</b>\n\n", shared.Escape(list.Access.List.Title))
if len(list.Shares) == 0 {
text.WriteString("No shares yet.\n\nOnly users with bot access can be added.")
return text.String()
}
hasPending := false
for _, share := range list.Shares {
fmt.Fprintf(&text, "• %s — %s", shared.Escape(shareLabel(share)), share.Role)
if share.Pending {
text.WriteString(" (pending)")
hasPending = true
}
text.WriteByte('\n')
}
if hasPending {
text.WriteString("\n<i>Pending shares activate when the user contacts the bot.</i>")
}
return strings.TrimRight(text.String(), "\n")
}
func shareDetailText(list service.ShareList, share domain.Share) string {
var text strings.Builder
fmt.Fprintf(&text, "<b>Share · %s</b>\n", shared.Escape(list.Access.List.Title))
fmt.Fprintf(&text, "User: %s\nRole: %s\nStatus: %s",
shared.Escape(shareLabel(share)), share.Role, shareStatus(share))
if share.Pending {
text.WriteString("\n\n<i>This share activates when the user contacts the bot.</i>")
}
return text.String()
}
func revokeConfirmText(list service.ShareList, share domain.Share) string {
return fmt.Sprintf(
"<b>Revoke access?</b>\n\n%s will lose access to \"%s\".",
shared.Escape(shareLabel(share)), shared.Escape(list.Access.List.Title),
)
}
func roleChoiceText(label string) string {
return fmt.Sprintf("Choose a role for %s.", shared.Escape(label))
}
func shareLabel(share domain.Share) string {
switch {
case share.Username != "":
return "@" + share.Username
case share.TelegramID > 0:
return fmt.Sprintf("ID %d", share.TelegramID)
default:
return "Unknown user"
}
}
func shareStatus(share domain.Share) string {
if share.Pending {
return "pending"
}
return "active"
}