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:
Michilis
2026-11-18 20:58:43 +00:00
co-authored by Claude Opus 5.5
parent 123cede7f3
commit f7ceadc462
30 changed files with 945 additions and 148 deletions
+24 -19
View File
@@ -156,6 +156,9 @@ pick = "Pick a format:"
cancelled = "Cancelled."
[btn]
qr = "QR code"
copy_link = "Copy link"
share = "Share"
maybe_over = "{{.Label}} ⚠"
remove_from_history = "Remove from history"
clear_yes = "Yes, clear it"
@@ -357,24 +360,6 @@ Downloads at the same time: {{.ActiveJobs}}
Downloads per day: {{.DailyDownloads}}
Volume per day: {{.DailyVolume}}"""
[referral.text]
one = """
<b>Invite friends</b>
Share your link. When somebody you invited makes a first purchase, you get {{.Reward}}.
{{.Link}}
You invited {{.Count}} person so far."""
other = """
<b>Invite friends</b>
Share your link. When somebody you invited makes a first purchase, you get {{.Reward}}.
{{.Link}}
You invited {{.Count}} people so far."""
[redeem]
usage = "Send the code after the command.\nExample: <code>/redeem NR-ABCD-EFGH-JKMN</code>"
invalid = "That code is not valid."
@@ -857,6 +842,10 @@ one = "Usage, last day"
other = "Usage, last {{.Count}} days"
[app.me]
qr = "QR code"
pending = "Waiting for the daily cap"
earned = "Earned"
converted = "Bought something"
downloads_title = "Downloads"
quality_note = "With a default set, a link starts right away instead of asking for a format."
audio_only = "Audio only"
@@ -864,7 +853,7 @@ audio_only_hint = "Always fetch the sound as MP3."
language_title = "Language"
language = "Language"
referral_title = "Invite friends"
referral_note = "When somebody you invited makes a first purchase, you get {{.Reward}}."
referral_note = "When somebody you invited pays for a first purchase in sats (Lightning), you get {{.Reward}} in credits."
copy_link = "Copy link"
share = "Share"
invited = "Invited so far"
@@ -912,3 +901,19 @@ other = "{{.Count}} days ago"
[history.clear_confirm]
one = "Remove {{.Count}} download from your history? Files already in this chat stay where they are."
other = "Remove all {{.Count}} downloads from your history? Files already in this chat stay where they are."
[referral]
qr_caption = """
Your invite link as a QR code:
{{.Link}}"""
share_text = "Download videos and music from a link, right in Telegram."
cap = "You earn at most {{.Cap}} a day. Rewards above that wait for the next day."
text = """
<b>Invite friends</b>
Share your link. When somebody you invited pays for a first purchase in sats (Lightning), you get {{.Reward}} in credits.
{{.Link}}
Invited: {{.Invited}} · Bought something: {{.Converted}}
Earned: {{.Earned}} · Waiting: {{.Pending}}"""
+24 -19
View File
@@ -147,6 +147,9 @@ pick = "Elige un formato:"
cancelled = "Cancelado."
[btn]
qr = "Código QR"
copy_link = "Copiar enlace"
share = "Compartir"
maybe_over = "{{.Label}} ⚠"
remove_from_history = "Quitar del historial"
clear_yes = "Sí, borrarlo"
@@ -343,24 +346,6 @@ Descargas al mismo tiempo: {{.ActiveJobs}}
Descargas por día: {{.DailyDownloads}}
Volumen por día: {{.DailyVolume}}"""
[referral.text]
one = """
<b>Invita a tus amigos</b>
Comparte tu enlace. Cuando alguien que invitaste haga su primera compra, recibes {{.Reward}}.
{{.Link}}
Hasta ahora invitaste a {{.Count}} persona."""
other = """
<b>Invita a tus amigos</b>
Comparte tu enlace. Cuando alguien que invitaste haga su primera compra, recibes {{.Reward}}.
{{.Link}}
Hasta ahora invitaste a {{.Count}} personas."""
[redeem]
usage = "Envía el código después del comando.\nEjemplo: <code>/redeem NR-ABCD-EFGH-JKMN</code>"
invalid = "Ese código no es válido."
@@ -832,6 +817,10 @@ one = "Uso, último día"
other = "Uso, últimos {{.Count}} días"
[app.me]
qr = "Código QR"
pending = "En espera del tope diario"
earned = "Ganado"
converted = "Compraron algo"
downloads_title = "Descargas"
quality_note = "Con un formato por defecto, un enlace empieza enseguida en vez de preguntar."
audio_only = "Solo audio"
@@ -839,7 +828,7 @@ audio_only_hint = "Bajar siempre el sonido en MP3."
language_title = "Idioma"
language = "Idioma"
referral_title = "Invita a tus amigos"
referral_note = "Cuando alguien que invitaste haga su primera compra, recibes {{.Reward}}."
referral_note = "Cuando alguien que invitaste pague una primera compra en sats (Lightning), recibes {{.Reward}} en créditos."
copy_link = "Copiar enlace"
share = "Compartir"
invited = "Invitados hasta ahora"
@@ -885,3 +874,19 @@ other = "hace {{.Count}} días"
[history.clear_confirm]
one = "Quitar {{.Count}} descarga de tu historial? Los archivos que ya están en este chat se quedan donde están."
other = "Quitar las {{.Count}} descargas de tu historial? Los archivos que ya están en este chat se quedan donde están."
[referral]
qr_caption = """
Tu enlace de invitación como código QR:
{{.Link}}"""
share_text = "Descarga videos y música desde un enlace, directo en Telegram."
cap = "Ganas como máximo {{.Cap}} al día. Lo que pase de eso espera al día siguiente."
text = """
<b>Invita a tus amigos</b>
Comparte tu enlace. Cuando alguien que invitaste pague una primera compra en sats (Lightning), recibes {{.Reward}} en créditos.
{{.Link}}
Invitados: {{.Invited}} · Compraron algo: {{.Converted}}
Ganado: {{.Earned}} · En espera: {{.Pending}}"""
+24 -19
View File
@@ -146,6 +146,9 @@ pick = "Kies een formaat:"
cancelled = "Geannuleerd."
[btn]
qr = "QR-code"
copy_link = "Link kopiëren"
share = "Delen"
maybe_over = "{{.Label}} ⚠"
remove_from_history = "Uit geschiedenis halen"
clear_yes = "Ja, wissen"
@@ -342,24 +345,6 @@ Downloads tegelijk: {{.ActiveJobs}}
Downloads per dag: {{.DailyDownloads}}
Volume per dag: {{.DailyVolume}}"""
[referral.text]
one = """
<b>Nodig vrienden uit</b>
Deel je link. Als iemand die je uitnodigde voor het eerst iets koopt, krijg jij {{.Reward}}.
{{.Link}}
Je hebt tot nu toe {{.Count}} persoon uitgenodigd."""
other = """
<b>Nodig vrienden uit</b>
Deel je link. Als iemand die je uitnodigde voor het eerst iets koopt, krijg jij {{.Reward}}.
{{.Link}}
Je hebt tot nu toe {{.Count}} mensen uitgenodigd."""
[redeem]
usage = "Stuur de code achter het commando.\nVoorbeeld: <code>/redeem NR-ABCD-EFGH-JKMN</code>"
invalid = "Die code is niet geldig."
@@ -831,6 +816,10 @@ one = "Gebruik, afgelopen dag"
other = "Gebruik, afgelopen {{.Count}} dagen"
[app.me]
qr = "QR-code"
pending = "Wacht op de daglimiet"
earned = "Verdiend"
converted = "Iets gekocht"
downloads_title = "Downloads"
quality_note = "Met een standaardformaat start een link meteen in plaats van te vragen."
audio_only = "Alleen audio"
@@ -838,7 +827,7 @@ audio_only_hint = "Altijd het geluid als MP3 ophalen."
language_title = "Taal"
language = "Taal"
referral_title = "Nodig vrienden uit"
referral_note = "Als iemand die je uitnodigde voor het eerst iets koopt, krijg jij {{.Reward}}."
referral_note = "Als iemand die je uitnodigde een eerste aankoop in sats (Lightning) betaalt, krijg jij {{.Reward}} aan tegoed."
copy_link = "Link kopiëren"
share = "Delen"
invited = "Tot nu toe uitgenodigd"
@@ -884,3 +873,19 @@ other = "{{.Count}} dagen geleden"
[history.clear_confirm]
one = "{{.Count}} download uit je geschiedenis halen? Bestanden die al in deze chat staan blijven staan."
other = "Alle {{.Count}} downloads uit je geschiedenis halen? Bestanden die al in deze chat staan blijven staan."
[referral]
qr_caption = """
Je uitnodigingslink als QR-code:
{{.Link}}"""
share_text = "Download video's en muziek via een link, gewoon in Telegram."
cap = "Je verdient maximaal {{.Cap}} per dag. Wat daarboven komt, wacht tot de volgende dag."
text = """
<b>Nodig vrienden uit</b>
Deel je link. Als iemand die je uitnodigde een eerste aankoop in sats (Lightning) betaalt, krijg jij {{.Reward}} aan tegoed.
{{.Link}}
Uitgenodigd: {{.Invited}} · Iets gekocht: {{.Converted}}
Verdiend: {{.Earned}} · Wacht nog: {{.Pending}}"""