diff --git a/app/[lang]/(site)/about/page.tsx b/app/[lang]/(site)/about/page.tsx index 111acf4..49956dd 100644 --- a/app/[lang]/(site)/about/page.tsx +++ b/app/[lang]/(site)/about/page.tsx @@ -15,7 +15,7 @@ import { pageSeo } from '@/lib/pageSeo' import { publicPath } from '@/lib/routes' import { alternatesFor, openGraphFor } from '@/lib/seo' import { getRequestLang } from '@/lib/serverLang' -import { loadShopStats } from '@/lib/shopStats' +import { loadDiscordMemberCount } from '@/lib/discordMembers' /** * `/en/about` and `/de/ueber-msk`: the person behind MSK Scripts (plan 5.2, @@ -43,18 +43,17 @@ export async function generateMetadata(): Promise { } export default async function AboutPage() { - const [{ lang }, stats, headline, docPages] = await Promise.all([ + const [{ lang }, discordMembers, headline, docPages] = await Promise.all([ getRequestLang(), // Fail-soft: a source that fails drops its figure, nothing is estimated. - loadShopStats().catch(() => null), + loadDiscordMemberCount().catch(() => null), loadHeadlineStat().catch(() => null), loadDocPageCount().catch(() => null), ]) const t = aboutPageTranslations[lang] const home = homeTranslations[lang] const nav = layoutTranslations[lang] - const locale = lang === 'de' ? 'de-DE' : 'en-GB' - const measured = aboutFigures(lang, stats, headline?.serverCount ?? null, docPages) + const measured = aboutFigures(lang, discordMembers, headline?.serverCount ?? null, docPages) const facts: Array<[string, React.ReactNode]> = [ [t.fact_brand, 'MSK Scripts'], @@ -154,11 +153,6 @@ export default async function AboutPage() { ))} - {stats && ( -

- {t.n_asof.replace('{date}', stats.updatedAt.toLocaleDateString(locale, { day: 'numeric', month: 'long', year: 'numeric' }))} -

- )} )} diff --git a/app/[lang]/(site)/page.tsx b/app/[lang]/(site)/page.tsx index 2997ee9..c31ce0f 100644 --- a/app/[lang]/(site)/page.tsx +++ b/app/[lang]/(site)/page.tsx @@ -13,7 +13,7 @@ import { JsonLd } from '@/components/JsonLd' import { webSiteJsonLd } from '@/lib/jsonLd' import { loadHeadlineStat } from '@/lib/fivestats' import { loadDocPageCount } from '@/lib/docsPages' -import { loadShopStats } from '@/lib/shopStats' +import { loadDiscordMemberCount } from '@/lib/discordMembers' import { cheapestPaidTier, formatTierPrice } from '@/lib/tiers' // The home page collects impressions on generic queries for @@ -50,7 +50,7 @@ export async function generateMetadata(): Promise { * cards and the second closing section (exclusion list, plan 4.2). */ export default async function HomePage() { - const [{ lang }, headline, stats, docPages] = await Promise.all([ + const [{ lang }, headline, discordMembers, docPages] = await Promise.all([ getRequestLang(), // Fail-soft: none of these sources may take down the home page. If one // fails, the corresponding figure disappears; nothing is estimated. @@ -58,8 +58,8 @@ export default async function HomePage() { console.warn('[home] fivestats headline stat unavailable:', err) return null }), - loadShopStats().catch(err => { - console.warn('[home] shop stats unavailable:', err) + loadDiscordMemberCount().catch(err => { + console.warn('[home] discord member count unavailable:', err) return null }), loadDocPageCount().catch(err => { @@ -76,7 +76,7 @@ export default async function HomePage() { Only here: the home page is the one address that stands for the site. */} - + diff --git a/components/home/ProofLine.tsx b/components/home/ProofLine.tsx index a64db98..4b07025 100644 --- a/components/home/ProofLine.tsx +++ b/components/home/ProofLine.tsx @@ -1,6 +1,5 @@ import { LocaleLink as Link } from '@/components/i18n/LocaleLink' import { homeTranslations, type Lang } from '@/lib/i18n' -import type { ShopStats } from '@/lib/shopStats' import type { HeadlineStat } from '@/lib/fivestats' import { SITE_CONFIG } from '@/lib/config' @@ -15,8 +14,7 @@ import { SITE_CONFIG } from '@/lib/config' * * An entry whose source is unavailable is dropped rather than replaced with an * estimate: a line of three numbers of which one is invented teaches the - * reader to discount the other two. The refund rate is not here; it belongs - * on the about page (E6). + * reader to discount the other two. */ interface Entry { @@ -27,10 +25,11 @@ interface Entry { } export function ProofLine({ - lang, stats, servers, docPages, + lang, discordMembers, servers, docPages, }: { lang: Lang - stats: ShopStats | null + /** Members of the MSK Discord, from its invite. `null` when unreachable. */ + discordMembers: number | null servers: HeadlineStat | null /** Documentation pages, counted from its sitemap. `null` when unreachable. */ docPages: number | null @@ -39,7 +38,11 @@ export function ProofLine({ const num = (n: number) => n.toLocaleString(lang === 'de' ? 'de-DE' : 'en-GB') const entries: Entry[] = [] - if (stats) entries.push({ value: num(stats.uniqueBuyers), label: t.proof_buyers }) + // Until 05.11.2026 this was "unique buyers" from the Tebex shop, which no + // longer sells anything. Support runs through the Discord now. + if (discordMembers !== null) { + entries.push({ value: num(discordMembers), label: t.proof_discord, href: SITE_CONFIG.discord, external: true }) + } if (servers) entries.push({ value: num(servers.serverCount), label: t.proof_servers, href: '/stats' }) // Until 05.09.2026 this was a constant `206`; the real figure was 208. If // the source fails, the entry drops out, same as the other two. @@ -55,9 +58,9 @@ export function ProofLine({ return (
-
+
{entries.map(e => ( -
+
{e.href && e.external ? ( {e.label} diff --git a/lib/aboutFigures.ts b/lib/aboutFigures.ts index 312d35a..b6a3c4c 100644 --- a/lib/aboutFigures.ts +++ b/lib/aboutFigures.ts @@ -1,18 +1,15 @@ import { SITE_CONFIG } from '@/lib/config' import { aboutPageTranslations, type Lang } from '@/lib/i18n' -import { formatReversalRate, type ShopStats } from '@/lib/shopStats' /** * The measured figures of the about page, each with the source a reader can * check it against. A figure whose source failed is left out, never - * estimated: a list of five numbers of which one is invented teaches the - * reader to discount the other four. + * estimated: a list of numbers of which one is invented teaches the reader + * to discount the others. * - * The share of refunded or charged-back payments is here and not on the home - * page (decision E6 of the redesign plan). It is the `reversal_rate` that - * scripts/tebex-stats.js writes nightly: refunds plus chargebacks over all - * settled payments. The counts beside it come from the same row, so rate and - * counts cannot describe two different nights. + * Until 05.11.2026 the list also held the shop figures from the nightly Tebex + * snapshot (unique buyers, refund rate, first sale). The shop stopped selling + * FiveM scripts that day, so those figures would only describe the past. */ export interface AboutFigure { @@ -25,43 +22,22 @@ export interface AboutFigure { export function aboutFigures( lang: Lang, - stats: ShopStats | null, + discordMembers: number | null, servers: number | null, docPages: number | null, ): AboutFigure[] { const t = aboutPageTranslations[lang] - const locale = lang === 'de' ? 'de-DE' : 'en-GB' - const num = (n: number) => n.toLocaleString(locale) + const num = (n: number) => n.toLocaleString(lang === 'de' ? 'de-DE' : 'en-GB') const out: AboutFigure[] = [] - if (stats) out.push({ value: num(stats.uniqueBuyers), label: t.n_buyers, source: t.n_buyers_source }) + if (discordMembers !== null && discordMembers > 0) { + out.push({ value: num(discordMembers), label: t.n_discord, source: t.n_discord_source, href: SITE_CONFIG.discord, external: true }) + } if (servers !== null && servers > 0) { out.push({ value: num(servers), label: t.n_servers, source: t.n_servers_source, href: '/stats' }) } if (docPages !== null && docPages > 0) { out.push({ value: num(docPages), label: t.n_docs, source: t.n_docs_source, href: SITE_CONFIG.docs, external: true }) } - if (stats) { - const settled = stats.completedPayments + stats.refunds + stats.chargebacks - // Without a settled payment the rate is 0 by default, not by measurement. - if (settled > 0) { - const rate = formatReversalRate(stats.reversalRate, lang) - out.push({ - value: lang === 'de' ? `${rate} %` : `${rate}%`, - label: t.n_reversal, - source: t.n_reversal_source - .replace('{refunds}', num(stats.refunds)) - .replace('{chargebacks}', num(stats.chargebacks)) - .replace('{settled}', num(settled)), - }) - } - if (stats.firstPaymentAt && !Number.isNaN(stats.firstPaymentAt.getTime())) { - out.push({ - value: stats.firstPaymentAt.toLocaleDateString(locale, { month: 'long', year: 'numeric' }), - label: t.n_first, - source: t.n_buyers_source, - }) - } - } return out } diff --git a/lib/discordMembers.ts b/lib/discordMembers.ts new file mode 100644 index 0000000..6c34aad --- /dev/null +++ b/lib/discordMembers.ts @@ -0,0 +1,67 @@ +// NOTE: server module. No secret behind it: Discord answers an invite lookup +// without a token. Fetching it server-side happens once per hour instead of +// once per page view, and the figure is already in the delivered markup. + +import { SITE_CONFIG } from '@/lib/config' + +/** + * How many members the MSK Scripts Discord has. + * + * Replaces "unique buyers" under the hero and on the about page since + * 05.11.2026, when the paid FiveM scripts went free and the shop stopped + * selling them. Support now runs through that Discord (public channel, tickets + * for GitHub sponsors), so its size is the figure that fits. + * + * The source is Discord's public invite endpoint with `with_counts=true`. Its + * `approximate_member_count` is what Discord itself shows on the invite card, + * so a reader can check it by opening the invite. + */ + +const INVITE_API = 'https://discord.com/api/v10/invites/{code}?with_counts=true' + +/** One hour. The count moves slowly and Discord rate-limits this endpoint. */ +const REVALIDATE_SECONDS = 3600 + +/** `https://discord.gg/abc123` -> `abc123`. `null` for anything else. */ +export function inviteCode(url: string): string | null { + const match = /^https:\/\/(?:www\.)?discord(?:\.gg|(?:app)?\.com\/invite)\/([A-Za-z0-9-]+)\/?$/.exec(url) + return match ? match[1] : null +} + +/** + * The member count from an invite response, or `null` when it is missing or + * not a positive whole number. A zero would be a broken answer, not an empty + * server: the invite belongs to a server with members. + */ +export function memberCountFrom(body: unknown): number | null { + if (typeof body !== 'object' || body === null) return null + const count = (body as { approximate_member_count?: unknown }).approximate_member_count + return typeof count === 'number' && Number.isInteger(count) && count > 0 ? count : null +} + +/** + * Returns the count, or `null` when it cannot be determined. Same rule as the + * other measured figures: a source that fails drops its entry, nothing is + * estimated or frozen. + */ +export async function loadDiscordMemberCount(): Promise { + const code = inviteCode(SITE_CONFIG.discord) + if (!code) { + console.error('[discordMembers] SITE_CONFIG.discord is not an invite link') + return null + } + try { + const res = await fetch(INVITE_API.replace('{code}', code), { + headers: { accept: 'application/json' }, + next: { revalidate: REVALIDATE_SECONDS }, + }) + if (!res.ok) { + console.error(`[discordMembers] invite lookup responded ${res.status}`) + return null + } + return memberCountFrom(await res.json()) + } catch (e) { + console.error('[discordMembers] could not read the invite:', e) + return null + } +} diff --git a/lib/i18n.ts b/lib/i18n.ts index d4762d5..5016896 100644 --- a/lib/i18n.ts +++ b/lib/i18n.ts @@ -1970,9 +1970,9 @@ export const homeTranslations = { entry_tools_price: "Free", // Measured figures under the hero. Every number is measured, see - // PRODUCT.md -> Evidence on Hand. The refund rate is not here (E6). + // PRODUCT.md -> Evidence on Hand. proof_label: "MSK Scripts in numbers", - proof_buyers: "unique buyers", + proof_discord: "members on Discord", proof_servers: "servers running msk_core", proof_docs: "documentation pages", @@ -2034,7 +2034,7 @@ export const homeTranslations = { entry_tools_price: "Kostenlos", proof_label: "MSK Scripts in Zahlen", - proof_buyers: "einzigartige Käufer", + proof_discord: "Mitglieder im Discord", proof_servers: "Server auf msk_core", proof_docs: "Doku-Seiten", @@ -2170,17 +2170,12 @@ export const aboutPageTranslations = { numbers_title: "Measured, not estimated", numbers_intro: "Each figure comes from a source that can be checked. If a source cannot be reached, its figure is left out rather than estimated.", - n_buyers: "unique buyers", - n_buyers_source: "Accounts with at least one completed payment in the shop", + n_discord: "members on Discord", + n_discord_source: "Live count from the invite of the MSK Scripts Discord", n_servers: "servers running msk_core", n_servers_source: "Live count from fivestats.io", n_docs: "documentation pages", n_docs_source: "Counted from the sitemap of the documentation", - n_reversal: "of settled payments refunded or charged back", - // {refunds}, {chargebacks} and {settled} are counts from the same snapshot. - n_reversal_source: "{refunds} refunds and {chargebacks} chargebacks out of {settled} settled payments", - n_first: "first sale on record", - n_asof: "Shop figures as of {date}, updated nightly.", links_kicker: "Where to find him", links_title: "Discord, GitHub and the rest", link_discord: "Support and questions, answered by the developer", @@ -2217,16 +2212,12 @@ export const aboutPageTranslations = { numbers_title: "Gemessen, nicht geschätzt", numbers_intro: "Jede Zahl stammt aus einer Quelle, die sich prüfen lässt. Ist eine Quelle nicht erreichbar, fehlt ihre Zahl, statt geschätzt zu werden.", - n_buyers: "einzigartige Käufer", - n_buyers_source: "Konten mit mindestens einer abgeschlossenen Zahlung im Shop", + n_discord: "Mitglieder im Discord", + n_discord_source: "Live-Zahl aus der Einladung des MSK-Scripts-Discords", n_servers: "Server auf msk_core", n_servers_source: "Live-Zahl von fivestats.io", n_docs: "Doku-Seiten", n_docs_source: "Gezählt aus der Sitemap der Dokumentation", - n_reversal: "der abgerechneten Zahlungen erstattet oder zurückgebucht", - n_reversal_source: "{refunds} Erstattungen und {chargebacks} Rückbuchungen bei {settled} abgerechneten Zahlungen", - n_first: "erster Verkauf", - n_asof: "Shop-Zahlen vom {date}, nachts aktualisiert.", links_kicker: "Wo du ihn findest", links_title: "Discord, GitHub und der Rest", link_discord: "Support und Fragen, beantwortet vom Entwickler", diff --git a/tests/aboutFigures.test.ts b/tests/aboutFigures.test.ts index 68c95f9..0d45939 100644 --- a/tests/aboutFigures.test.ts +++ b/tests/aboutFigures.test.ts @@ -1,53 +1,36 @@ import { describe, expect, it } from 'vitest' import { aboutFigures } from '@/lib/aboutFigures' -import type { ShopStats } from '@/lib/shopStats' /** - * The about page shows measured figures, among them the share of refunded or - * charged-back payments (decision E6). What is shown there must be the - * measured value with its counts, and a figure without a source must vanish - * instead of turning into a zero or an estimate. + * The about page shows measured figures. Each must carry its source, and a + * figure without a source must vanish instead of turning into a zero or an + * estimate. The shop figures from Tebex are gone since the paid scripts went + * free (05.11.2026). */ -const stats: ShopStats = { - uniqueBuyers: 1234, - totalPayments: 1500, - completedPayments: 1385, - refunds: 8, - chargebacks: 3, - reversalRate: 11 / 1396, - firstPaymentAt: new Date('2022-06-14T10:00:00Z'), - updatedAt: new Date('2026-10-28T03:00:00Z'), -} - const byLabel = (figures: ReturnType, part: string) => figures.find(f => f.label.includes(part)) describe('aboutFigures', () => { - it('states the reversal rate with the counts it comes from', () => { - const de = byLabel(aboutFigures('de', stats, 262, 252), 'erstattet oder zurückgebucht') - expect(de?.value).toBe('0,79 %') - expect(de?.source).toBe('8 Erstattungen und 3 Rückbuchungen bei 1.396 abgerechneten Zahlungen') - const en = byLabel(aboutFigures('en', stats, 262, 252), 'refunded or charged back') - expect(en?.value).toBe('0.79%') - expect(en?.source).toBe('8 refunds and 3 chargebacks out of 1,396 settled payments') - }) - - it('leaves out every shop figure when the snapshot is missing', () => { - const figures = aboutFigures('en', null, 262, 252) - expect(figures.map(f => f.label)).toEqual(['servers running msk_core', 'documentation pages']) + it('lists Discord members, servers and documentation pages with their sources', () => { + const figures = aboutFigures('de', 1627, 262, 252) + expect(figures.map(f => f.label)).toEqual(['Mitglieder im Discord', 'Server auf msk_core', 'Doku-Seiten']) + const discord = byLabel(figures, 'Discord') + expect(discord?.value).toBe('1.627') + expect(discord?.href).toBe('https://discord.gg/5hHSBRHvJE') + expect(discord?.external).toBe(true) + expect(byLabel(aboutFigures('en', 1627, 262, 252), 'Discord')?.value).toBe('1,627') }) - it('shows no rate before a single payment was settled', () => { - const none = { ...stats, completedPayments: 0, refunds: 0, chargebacks: 0, reversalRate: 0 } - expect(byLabel(aboutFigures('en', none, null, null), 'refunded')).toBeUndefined() + it('shows no shop figures anymore', () => { + const labels = aboutFigures('en', 627, 262, 252).map(f => f.label).join(' ') + expect(labels).not.toMatch(/buyer|refund|sale/i) }) it('drops a source that returned nothing usable', () => { - const figures = aboutFigures('en', stats, null, 0) - expect(byLabel(figures, 'servers')).toBeUndefined() - expect(byLabel(figures, 'documentation')).toBeUndefined() - expect(byLabel(figures, 'unique buyers')?.value).toBe('1,234') + const figures = aboutFigures('en', null, null, 0) + expect(figures).toEqual([]) + expect(byLabel(aboutFigures('en', 0, 262, 252), 'Discord')).toBeUndefined() }) }) diff --git a/tests/discordMembers.test.ts b/tests/discordMembers.test.ts new file mode 100644 index 0000000..d08c99b --- /dev/null +++ b/tests/discordMembers.test.ts @@ -0,0 +1,38 @@ +import { describe, expect, it } from 'vitest' + +import { inviteCode, memberCountFrom } from '@/lib/discordMembers' + +/** + * The member count under the hero comes from Discord's invite endpoint. A + * malformed answer must drop the figure instead of showing a wrong number. + */ + +describe('inviteCode', () => { + it('reads the code from the usual invite forms', () => { + expect(inviteCode('https://discord.gg/5hHSBRHvJE')).toBe('5hHSBRHvJE') + expect(inviteCode('https://discord.com/invite/5hHSBRHvJE')).toBe('5hHSBRHvJE') + expect(inviteCode('https://discordapp.com/invite/abc-123/')).toBe('abc-123') + }) + + it('rejects anything that is not an invite link', () => { + expect(inviteCode('https://discord.gg/')).toBeNull() + expect(inviteCode('https://evil.example/discord.gg/abc')).toBeNull() + expect(inviteCode('https://discord.gg/abc?x=1')).toBeNull() + }) +}) + +describe('memberCountFrom', () => { + it('takes approximate_member_count', () => { + expect(memberCountFrom({ approximate_member_count: 627, approximate_presence_count: 126 })).toBe(627) + }) + + it('returns null for a missing, zero, negative or non-integer count', () => { + expect(memberCountFrom({})).toBeNull() + expect(memberCountFrom({ approximate_member_count: 0 })).toBeNull() + expect(memberCountFrom({ approximate_member_count: -3 })).toBeNull() + expect(memberCountFrom({ approximate_member_count: 12.5 })).toBeNull() + expect(memberCountFrom({ approximate_member_count: '627' })).toBeNull() + expect(memberCountFrom(null)).toBeNull() + expect(memberCountFrom('627')).toBeNull() + }) +})