Documentation
¶
Index ¶
- func CheckBalance(ctx context.Context, dbManager *database.DBManager, userID []byte, ...) (requiredDCR float64, currentBalanceDCR float64, err error)
- func DeductBalance(ctx context.Context, dbManager *database.DBManager, userID []byte, ...) (chargedDCR float64, newBalanceDCR float64, err error)
- func ExtractAudioNoteData(message string) (string, error)
- func FormatBalanceMessage(balanceDCR float64, dcrPrice float64) string
- func FormatBillingConfirmation(taskName string, billingEnabled bool, billingAttempted bool, ...) string
- func FormatBillingMessage(chargedDCR float64, chargedUSD float64, remainingBalance float64) string
- func FormatCommandHelpHeader(commandName string, model faladapter.AppModel, userID zkidentity.ShortID, ...) string
- func FormatDebugAfterDeduction(newBalanceAtoms int64) string
- func FormatDebugBalanceInfo(userID string, balanceAtoms int64, costUSD float64, costDCR float64, ...) string
- func FormatDebugCommandInfo(commandName string, userID string, balanceAtoms int64, costUSD float64, ...) string
- func FormatEmbeddedAudioMessage(modelName string, base64Data string) string
- func FormatEmbeddedImageMessage(altText string, contentType string, base64Data string) string
- func FormatInsufficientBalanceMessage(requiredDCR float64, currentDCR float64) string
- func FormatInsufficientBalanceMessageWithUSD(requiredDCR float64, currentDCR float64, usdAmount float64) string
- func FormatModelHelpMessage(modelName string, description string, priceUSD float64, priceDCR float64, ...) string
- func FormatModelListMessage(commandName string, models map[string]interface{}) string
- func FormatThousands(n float64) string
- func FormatUSDThousands(n float64) string
- func GetBTCPrice() (float64, error)
- func GetDCRPrice() (float64, float64, error)
- func GetUserIDString(uid []byte) string
- func HandleServiceResultOrError(ctx context.Context, bot *kit.Bot, msgCtx braibottypes.MessageContext, ...) error
- func IsAudioNote(message string) bool
- func SendFileToUser(ctx context.Context, bot *kit.Bot, userNick string, fileURL string, ...) error
- func SendToUser(ctx context.Context, bot *kit.Bot, isPM bool, nick, gc, msg string) error
- func USDToDCR(usdAmount float64) (float64, error)
- type ErrInsufficientBalance
- type ServiceResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckBalance ¶
func CheckBalance(ctx context.Context, dbManager *database.DBManager, userID []byte, costUSD float64, debug bool, billingEnabled bool) (requiredDCR float64, currentBalanceDCR float64, err error)
CheckBalance checks if a user has sufficient balance for a given cost in USD, without deducting. It returns the required DCR amount, the current balance in DCR, and potentially an ErrInsufficientBalance or other critical error. If billingEnabled is false, it returns success (nil error).
func DeductBalance ¶
func DeductBalance(ctx context.Context, dbManager *database.DBManager, userID []byte, costUSD float64, debug bool, billingEnabled bool) (chargedDCR float64, newBalanceDCR float64, err error)
DeductBalance deducts the specified cost in USD from the user's balance. It assumes the balance check has already passed IF billing is enabled. Returns the amount charged in DCR, the new balance in DCR, and any error encountered. If billingEnabled is false, it returns zero charged and the current balance without hitting the DB.
func ExtractAudioNoteData ¶
ExtractAudioNoteData extracts the base64 audio data from an audio note message
func FormatBalanceMessage ¶
FormatBalanceMessage formats a balance message with DCR and USD values
func FormatBillingConfirmation ¶
func FormatBillingConfirmation(taskName string, billingEnabled bool, billingAttempted bool, billingSucceeded bool, chargedDCR float64, chargedUSD float64, finalBalanceDCR float64) string
FormatBillingConfirmation builds the complete billing confirmation string appended to a task-completion message. It handles all billing outcome cases:
- billing succeeded: show charged DCR, USD, and new balance
- billing attempted but failed: show warning with balance and content type
- billing not attempted (but enabled): show "no charge" with balance
- billing disabled: show "billing is disabled"
taskName is the content type shown in the failure message (e.g. "video", "results", "audio").
func FormatBillingMessage ¶
FormatBillingMessage formats a billing message with charged amount and remaining balance
func FormatCommandHelpHeader ¶
func FormatCommandHelpHeader(commandName string, model faladapter.AppModel, userID zkidentity.ShortID, dbManager braibottypes.DBManagerInterface) string
FormatCommandHelpHeader generates the standard header for command help messages.
func FormatDebugAfterDeduction ¶
FormatDebugAfterDeduction formats debug information after balance deduction
func FormatDebugBalanceInfo ¶
func FormatDebugBalanceInfo(userID string, balanceAtoms int64, costUSD float64, costDCR float64, costAtoms int64) string
FormatDebugBalanceInfo formats debug information about a user's balance
func FormatDebugCommandInfo ¶
func FormatDebugCommandInfo(commandName string, userID string, balanceAtoms int64, costUSD float64, costDCR float64, costAtoms int64) string
FormatDebugCommandInfo formats debug information for a command
func FormatEmbeddedAudioMessage ¶
FormatEmbeddedAudioMessage formats a message with embedded audio
func FormatEmbeddedImageMessage ¶
FormatEmbeddedImageMessage formats a message with an embedded image
func FormatInsufficientBalanceMessage ¶
FormatInsufficientBalanceMessage formats a message for insufficient balance
func FormatInsufficientBalanceMessageWithUSD ¶
func FormatInsufficientBalanceMessageWithUSD(requiredDCR float64, currentDCR float64, usdAmount float64) string
FormatInsufficientBalanceMessageWithUSD formats a message for insufficient balance with USD value
func FormatModelHelpMessage ¶
func FormatModelHelpMessage(modelName string, description string, priceUSD float64, priceDCR float64, balanceDCR float64, helpDoc string) string
FormatModelHelpMessage formats a help message for a model
func FormatModelListMessage ¶
FormatModelListMessage formats a message listing available models
func FormatThousands ¶
FormatThousands formats a float64 with commas as thousands separators, rounded to the nearest integer.
func FormatUSDThousands ¶
FormatUSDThousands formats a float64 as USD with thousands separators and 2 decimal places.
func GetBTCPrice ¶
GetBTCPrice gets the current BTC price in USD from CoinGecko
func GetDCRPrice ¶
GetDCRPrice gets the current DCR price in USD and BTC from CoinGecko
func GetUserIDString ¶
GetUserIDString converts a user's UID bytes to a string ID
func HandleServiceResultOrError ¶
func HandleServiceResultOrError(ctx context.Context, bot *kit.Bot, msgCtx braibottypes.MessageContext, commandName string, result interface{}, err error) error
HandleServiceResultOrError encapsulates common error handling for service calls. It checks for direct errors (like context cancellation, insufficient balance) and then checks the success status within the result. `result` is expected to be a pointer to a struct with `Success bool` and `Error error` fields. Returns nil if the error was handled (PM sent/logged appropriately), otherwise returns the error to propagate.
func IsAudioNote ¶
IsAudioNote checks if a message contains an audio note embed
func SendFileToUser ¶
func SendFileToUser(ctx context.Context, bot *kit.Bot, userNick string, fileURL string, filePrefix string, contentType string) error
SendFileToUser downloads a file from a URL and sends it to a user. It creates a temporary file, downloads the content, and sends it using the bot. The temporary file is automatically cleaned up after sending.
func SendToUser ¶
SendToUser sends a message to either a PM or a group chat based on isPM.
Types ¶
type ErrInsufficientBalance ¶
type ErrInsufficientBalance struct {
Message string
}
ErrInsufficientBalance is a custom error type for insufficient funds.
func (*ErrInsufficientBalance) Error ¶
func (e *ErrInsufficientBalance) Error() string
Error implements the error interface.
type ServiceResult ¶
ServiceResult defines an interface for common fields in service results. Assumes result structs have `Success bool` and `Error error` fields or methods.