Phase 3: own referral system (sats)
- Referral links carry a random 8 character base32 code (rf_<code>) built from the bot username from getMe. Old ref_<id> links still work but are never shown. - The reward (REFERRAL_REWARD_SATS, old name REFERRAL_REWARD still read) is paid through the ledger once the invited user's first purchase settles, once per invited user, never for self-referrals. - REFERRAL_DAILY_CAP limits what an inviter earns per UTC day; rewards above it wait as pending and are paid on a later day by the billing loop. - /referral shows invited, converted, earned and pending, with Share, Copy link and QR code buttons. The Mini App Me page mirrors it. - Migration 00008: users.ref_code (unique) and referral_rewards, backfilled from earlier referral credits in the ledger. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
123cede7f3
commit
f7ceadc462
@@ -103,6 +103,16 @@ type Config struct {
|
||||
MultiLinkMax int `toml:"multi_link_max" env:"MULTI_LINK_MAX"`
|
||||
// CaptionAttribution adds a "via @botname" line to file captions.
|
||||
CaptionAttribution bool `toml:"caption_attribution" env:"CAPTION_ATTRIBUTION"`
|
||||
|
||||
// ReferralRewardSats is credited to an inviter when somebody they
|
||||
// invited settles a first Lightning purchase. It is the documented name
|
||||
// of [prices] referral_reward (REFERRAL_REWARD), which still works; when
|
||||
// both are set this one wins. -1 means not set.
|
||||
ReferralRewardSats int64 `toml:"referral_reward_sats" env:"REFERRAL_REWARD_SATS"`
|
||||
// ReferralDailyCap is the most one inviter earns in referral rewards per
|
||||
// day (UTC), in sats. Rewards above it wait and are paid on a later
|
||||
// day. 0 means no cap.
|
||||
ReferralDailyCap int64 `toml:"referral_daily_cap" env:"REFERRAL_DAILY_CAP"`
|
||||
}
|
||||
|
||||
// Telegram holds the Bot API settings.
|
||||
@@ -375,6 +385,8 @@ func Default() Config {
|
||||
QueueNoticeThresholdSeconds: 10,
|
||||
MultiLinkMax: 5,
|
||||
CaptionAttribution: true,
|
||||
ReferralRewardSats: -1,
|
||||
ReferralDailyCap: 2000,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,6 +433,9 @@ func Load(path string) (Config, error) {
|
||||
}
|
||||
cfg.PublicURL = strings.TrimRight(cfg.PublicURL, "/")
|
||||
cfg.LNbits.URL = strings.TrimRight(cfg.LNbits.URL, "/")
|
||||
if cfg.ReferralRewardSats >= 0 {
|
||||
cfg.Prices.ReferralReward = cfg.ReferralRewardSats
|
||||
}
|
||||
return cfg, cfg.Validate()
|
||||
}
|
||||
|
||||
@@ -452,6 +467,9 @@ func (c Config) Validate() error {
|
||||
if c.QueueNoticeThresholdSeconds < 0 {
|
||||
errs = append(errs, "QUEUE_NOTICE_THRESHOLD_SECONDS must not be negative")
|
||||
}
|
||||
if c.ReferralDailyCap < 0 {
|
||||
errs = append(errs, "REFERRAL_DAILY_CAP must not be negative")
|
||||
}
|
||||
if c.MultiLinkMax < 1 || c.MultiLinkMax > 20 {
|
||||
errs = append(errs, "MULTI_LINK_MAX must be between 1 and 20")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user