Phase 2: money

Lightning payments through LNbits, wallets, passes, credits, the
entitlement resolver and priority lanes.

- internal/entitle: pure resolver (one-off, own pass, group pass, group
  credits, own credits, free) with a table-driven suite and an invariant
  check over every input combination
- internal/billing: wallets, append-only ledger with dedupe keys, stacking
  passes, purchases, gift codes, referral reward
- LNbits client verified against v0.12.12 and v1.7.1 source
- Settlement by one conditional UPDATE: idempotent under any mix of
  webhooks, polls and the check button. Webhooks are unsigned, so every
  payment is confirmed with LNbits before it is credited
- Polling fallback, reconciliation of all unsettled invoices at startup,
  late payments still honored, no expiry while LNbits is unreachable
- Charge, quota and job are written in one transaction; failed, cancelled
  and undeliverable downloads are refunded exactly once
- Paid lane first with one slot of the fleet reserved for free users
- Daily download quota and daily volume cap, per-user and per-group rate
  limits
- Bot: /buy /account /limits /credits /redeem /referral /donate, QR invoice
  message that flips to paid, over-limit offer (passes or this file only),
  deep links from groups, skip the queue
- Fake LNbits server for tests; end-to-end money flows including a payment
  made while the core was down

Cashu redemption is behind an interface and not implemented.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Michilis
2026-11-18 08:09:35 +00:00
co-authored by Claude Fable 5.2
parent 3b361c17a1
commit 0d50f453a0
42 changed files with 7040 additions and 140 deletions
+154
View File
@@ -35,6 +35,15 @@ In a group, use /dl with a link, or reply /dl to a message that has a link.
/queue - your running downloads
/cancel - cancel your downloads
<b>Account</b>
/account - your pass, balance and usage
/limits - the limits that apply to you
/buy - get a pass or credits
/credits - your balance and top up
/redeem code - use a gift code
/referral - invite friends and earn sats
/donate - send a tip
<b>Your limits</b>
Up to {{.MaxSize}} and {{.MaxDuration}} per download."""
@@ -49,6 +58,8 @@ thumb = "Get the thumbnail"
info = "Show formats and sizes"
queue = "Your downloads in progress"
cancel = "Cancel your downloads"
account = "Your pass, balance and usage"
buy = "Get a pass or credits"
help = "How to use the bot"
[hint]
@@ -90,6 +101,12 @@ thumb = "Thumbnail"
subs = "Subtitles ({{.Lang}})"
with_size = "{{.Label}} · {{.Size}}"
cancel = "Cancel"
skip_queue = "Skip the queue"
open_private = "Open a private chat"
open_wallet = "Open in wallet"
check_payment = "Check payment"
this_file = "This file only"
buy_for_me = "Buy for me"
[status]
queued = "In the queue. Position {{.Position}}, about {{.Wait}}."
@@ -101,6 +118,7 @@ uploading = "Sending it to Telegram…"
done = "Done. Enjoy."
cancelled = "Cancelled."
failed = "That did not work. {{.Reason}}"
refunded = "{{.Amount}} went back to your balance."
[notice]
cancelled = "Cancelled."
@@ -108,17 +126,34 @@ not_yours = "These buttons belong to the person who asked."
too_late = "Too late to cancel that."
expired = "This card has expired. Send the link again."
already_chosen = "A download from this card is already running."
private_only = "This works in a private chat with me."
rate_limited = "That is a lot of links. Please wait a minute and try again."
paid = "Payment received."
not_paid_yet = "Not paid yet. It can take a few seconds after you pay."
invoice_closed = "This invoice is closed."
skipped = "Done. Your download moved to the front."
skip_too_late = "This download is not waiting in the queue anymore."
skip_private = "Open a private chat with me to pay for this."
[limit]
too_large = "This file is larger than your limit of {{.MaxSize}}. Try a lower quality."
too_long = "This is longer than your limit of {{.MaxDuration}}."
live = "Live streams cannot be downloaded."
queue_full = "The queue is full right now. Please try again in a few minutes."
daily_volume = "You reached your daily volume of {{.MaxVolume}}. It resets at midnight UTC."
[limit.daily_downloads]
one = "You used your {{.Count}} download for today. It resets at midnight UTC."
other = "You used your {{.Count}} downloads for today. It resets at midnight UTC."
[limit.active_jobs]
one = "You already have {{.Count}} download running. Wait for it to finish or use /cancel."
other = "You already have {{.Count}} downloads running. Wait for one to finish or use /cancel."
[unit.sats]
one = "{{.N}} sat"
other = "{{.N}} sats"
[unit.seconds]
one = "{{.Count}} second"
other = "{{.Count}} seconds"
@@ -156,3 +191,122 @@ internal = "Something went wrong on my side. Please try again."
unknown = "The download failed. Please try again later."
playlist = "That link is a playlist. Send the link of a single video for now."
send_failed = "I could not send the file to Telegram. Please try again."
# --- Money -------------------------------------------------------------------
[product]
pass_day = "Day pass"
pass_week = "Week pass"
pass_month = "Month pass"
credits = "Credits"
one_off = "Single download"
skip_queue = "Skip the queue"
donation = "Donation"
# What pays for a download.
[source]
one_off = "Single download"
own_pass = "Your pass"
group_pass = "Group pass"
group_credits = "Group credits"
own_credits = "Your credits"
free = "Free"
[buy]
intro = """
<b>Passes and credits</b>
A <b>pass</b> lifts your limits to {{.MaxSize}} and {{.MaxDuration}} per download and puts you in the priority queue for as long as it runs.
<b>Credits</b> pay per download, {{.PerDownload}} each, with the same limits and priority. They never expire.
You pay in sats over Lightning."""
unavailable = "Payments are not set up on this bot yet."
backend_down = "I cannot reach the payment service right now. Please try again in a moment."
backend_down_short = "The payment service is not reachable right now. Please try again in a moment."
bad_amount = "That amount is not possible."
[credits]
text = """
<b>Your balance: {{.Balance}}</b>
One download costs {{.PerDownload}}. Top up:"""
[donate]
intro = "Thank you for supporting the bot. Pick an amount:"
[account]
title = "<b>Your account</b>"
pass_active = "Pass: active until {{.Until}}"
pass_none = "Pass: none"
balance = "Balance: {{.Balance}}"
today = "<b>Today</b>"
usage_downloads = "Downloads: {{.Used}} of {{.Max}}"
usage_volume = "Volume: {{.Used}} of {{.Max}}"
unlimited = "unlimited"
[limits]
text = """
<b>Your limits</b> ({{.Tier}})
Size per download: {{.MaxSize}}
Length per download: {{.MaxDuration}}
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."
used = "That code was already used or has expired."
credits = "Done. {{.Amount}} were added to your balance."
pass = "Done. Your pass is active until {{.Until}}."
cashu_off = "Cashu tokens are not accepted on this bot."
cashu_mint = "I do not accept tokens from that mint."
[invoice]
memo = "The Noderunners Download Bot: {{.Title}}"
caption = """
<b>{{.Title}}</b> · {{.Amount}}
<code>{{.Invoice}}</code>
Scan the code or tap the invoice to copy it. Valid for {{.Valid}}."""
paid = "<b>Paid.</b> {{.Title}} · {{.Amount}}"
balance = "Your balance is now {{.Balance}}."
pass_until = "Your pass is active until {{.Until}}."
thanks = "Thank you for the support."
expired = "This invoice for {{.Title}} has expired. Nothing was charged."
cancelled = "Invoice cancelled."
[pay]
title = "Pay with Lightning"
hint = "Your Lightning wallet should open now."
open = "Open in wallet"
gone = "This invoice is no longer open."
too_late_skip = "Your payment arrived, but the download had already left the queue. {{.Amount}} were added to your balance instead."
too_late_file = "Your payment arrived, but the download could not be started. {{.Amount}} were added to your balance instead."
not_started = "The download could not be started. {{.Reason}}"
skip_not_needed = "That download is not waiting in the queue anymore, so there is nothing to pay."
[over]
options = "You can lift the limit:"
started = "Your limits allow it now. The download has started."