Compare commits
2 Commits
d510caa123
...
9a7ef61d93
Author | SHA1 | Date |
---|---|---|
|
9a7ef61d93 | |
|
bad5dc52f7 |
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "schat2-clive",
|
"name": "schat2-clive",
|
||||||
"version": "1.28.3",
|
"version": "1.28.4",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "schat2-clive",
|
"name": "schat2-clive",
|
||||||
"version": "1.28.3",
|
"version": "1.28.4",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"better-sqlite3": "^8.3.0",
|
"better-sqlite3": "^8.3.0",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "schat2-clive",
|
"name": "schat2-clive",
|
||||||
"version": "1.28.3",
|
"version": "1.28.4",
|
||||||
"description": "Game host for SChat 2-powered chat sites",
|
"description": "Game host for SChat 2-powered chat sites",
|
||||||
"main": "src/app.js",
|
"main": "src/app.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
const path = require('path');
|
||||||
|
const args = require('yargs').argv;
|
||||||
|
const fs = require('fs').promises;
|
||||||
|
|
||||||
|
async function init() {
|
||||||
|
await fs.copyFile(args.file, `${path.basename(args.file, path.extname(args.file))}_backup_${Date.now()}.json`);
|
||||||
|
|
||||||
|
const filepath = path.join(process.cwd(), args.file);
|
||||||
|
const points = require(filepath); // eslint-disable-line
|
||||||
|
|
||||||
|
Object.entries(points).forEach(([game, scores]) => {
|
||||||
|
const originKey = Object.keys(scores).find((userKey) => userKey.includes(`:${args.origin}`));
|
||||||
|
const originScore = scores[originKey];
|
||||||
|
|
||||||
|
const targetKey = Object.keys(scores).find((userKey) => userKey.includes(`:${args.target}`));
|
||||||
|
const targetScore = scores[targetKey];
|
||||||
|
|
||||||
|
if (typeof originScore === 'undefined' || typeof targetScore === 'undefined') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const totalScore = targetScore + originScore;
|
||||||
|
|
||||||
|
points[game][targetKey] = targetScore + originScore;
|
||||||
|
delete points[game][originKey];
|
||||||
|
|
||||||
|
console.log(`${game} ${targetScore} (${args.target}) + ${originScore} (${args.origin}) = ${totalScore}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
await fs.writeFile(filepath, JSON.stringify(points, null, 4));
|
||||||
|
|
||||||
|
console.log(`Saved ${filepath}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
Loading…
Reference in New Issue