From 80bf3193787ada9c3272671d3cab4ee4e6d4917e Mon Sep 17 00:00:00 2001 From: ewin Date: Thu, 4 Sep 2025 23:55:43 -0400 Subject: [PATCH] add script for fixing flavor text formatting from robogurgum see --- bin/one-time/flavor-text-color-fix | 53 ++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 bin/one-time/flavor-text-color-fix diff --git a/bin/one-time/flavor-text-color-fix b/bin/one-time/flavor-text-color-fix new file mode 100755 index 0000000..898691a --- /dev/null +++ b/bin/one-time/flavor-text-color-fix @@ -0,0 +1,53 @@ +#!/usr/bin/env -S node --env-file-if-exists=.env +// Fixes flavor text formatting on files robogurgum created for patches 7.3/7.31 +// see https://discord.com/channels/312060255469305856/1412850908668100810 + +import {getMediawikiClient} from '../../lib/config.js'; +import {diff} from '../../lib/util/diff.js'; + +const mw = await getMediawikiClient(); + +function fixPageContent (pageContent) { + const flavorTextRegexp = /\| flavor-text = ([\s\S]*?)\n\|/; + + let match = pageContent.match(flavorTextRegexp); + if (!match) return pageContent; + let flavorText = match[1]; + if (!flavorText.trim()) return pageContent; + + let newFlavorText = flavorText + // linebreaks with + // - no
or
etc before or after + // - no {{action fact}} after (that renders a line break at the start) + .replace(/(?)\n(?!)(?!{{action fact|\s*$)/gi, '
\n') + // spans that set color via inline style instead of using {{colorize}} + .replace(/([^<]+)<\/span>/g, '`$1`') + .replace(/([^<]+)<\/span>/g, '``$1``') + .replace(/([^<]+)<\/span>/g, '```$1```') + // convert lunar/phaenna credit bonuses to use {{action fact}}, but only + // when we can be sure it won't add extra line breaks + .replace( + /(\n?)`([\w\d _-]+)(?<=Credit Bonus)(?::`|`:) +([^\n<]+)/g, + '$1{{action fact|$2|$3}}', + ) + // flavor-text is automatically colorized, remove redundant invocations + .replace(/{{colorize\|([^|{}]+)}}/g, '$1'); + + return pageContent.replace(flavorTextRegexp, `| flavor-text = ${newFlavorText}\n|`); +} + +const pages = await mw.listUserContribs('RoboGurgum', {namespaces: [0], show: 'new', limit: 1000}); +for (const page of pages) { + const {title} = page; + const pageContent = await mw.readPage(title); + let fixedContent = fixPageContent(pageContent); + if (fixedContent === pageContent) { + console.log('#', title, ' No change\n'); + continue; + } + console.write('\n'); + diff(pageContent, fixedContent, page); + console.log(); + + await mw.editPage(title, fixedContent, 'fix flavor text formatting', true); +}