@totoraj930/gbf-tweet-parser
Version:
Parser for Granblue Fantasy request backup tweets.
45 lines • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parse = void 0;
function parse(text) {
var _a, _b;
const lines = text.trim().split('\n').reverse();
const hasImage = lines[0].trim().startsWith('https://');
let image;
if (hasImage) {
image = lines.shift();
}
if (lines.length < 3)
return null;
const enemyLine = lines[0].trim();
const battleIdLine = lines[2].trim();
const battleId = (_a = battleIdLine.match(/([0-9A-z]{8,8})\s(:Battle\sID|:参戦ID)$/)) === null || _a === void 0 ? void 0 : _a[1];
if (!battleId)
return null;
const language = battleIdLine.endsWith(':参戦ID')
? 'ja'
: 'en';
// 3: level, 4: enemyName
const enemyParseRes = enemyLine.match(/^((Lvl\s|Lv)(\d+)\s|)(.+)$/);
if (!enemyParseRes)
return null;
const level = (_b = enemyParseRes[3]) !== null && _b !== void 0 ? _b : '???';
if (!enemyParseRes[4])
return null;
const enemyName = enemyParseRes[4];
const commentLines = lines.slice(2);
commentLines[0] = commentLines[0]
.replace(/([0-9A-z]{8,8})\s(:Battle\sID|:参戦ID)$/, '')
.trim();
const comment = commentLines.reverse().join('\n');
return {
battleId,
enemyName,
level,
image,
language,
comment: comment.length ? comment : undefined,
};
}
exports.parse = parse;
//# sourceMappingURL=index.js.map