Skip to content

Commit

Permalink
fix creatables file
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Mar 4, 2024
1 parent 6366cca commit 87e4a7d
Show file tree
Hide file tree
Showing 7 changed files with 977 additions and 70 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@sapphire/stopwatch": "^1.4.0",
"@sapphire/time-utilities": "^1.6.0",
"@sentry/node": "^7.102.0",
"ascii-table3": "^0.9.0",
"bufferutil": "^4.0.8",
"chart.js": "^3.7.0",
"chartjs-node-canvas": "github:gc/ChartjsNodeCanvas#a598b6dd27c44351f235bca07ca4ee660121f289",
Expand All @@ -52,7 +53,6 @@
"random-js": "^2.1.0",
"simple-statistics": "^7.8.3",
"sonic-boom": "^3.8.0",
"table": "^6.8.1",
"tsx": "^4.7.1",
"zlib-sync": "^0.1.9",
"zod": "^3.22.4"
Expand Down
5 changes: 2 additions & 3 deletions src/lib/data/Collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Bank, Clues, Monsters } from 'oldschooljs';
import { Item } from 'oldschooljs/dist/meta/types';
import { ChambersOfXeric } from 'oldschooljs/dist/simulation/misc/ChambersOfXeric';
import Monster from 'oldschooljs/dist/structures/Monster';
import { table } from 'table';

import { ClueTier, ClueTiers } from '../clues/clueTiers';
import { NEX_ID, PHOSANI_NIGHTMARE_ID, ZALCANO_ID } from '../constants';
Expand All @@ -24,7 +23,7 @@ import { MUserStats } from '../structures/MUserStats';
import type { ItemBank } from '../types';
import { fetchStatsForCL, stringMatches } from '../util';
import resolveItems from '../util/resolveItems';
import { shuffleRandom } from '../util/smallUtils';
import { makeTable, shuffleRandom } from '../util/smallUtils';
import {
abyssalSireCL,
aerialFishingCL,
Expand Down Expand Up @@ -1283,7 +1282,7 @@ export function getPossibleOptions() {
for (const monster of effectiveMonsters) {
categories.push(['Monsters', monster.name, monster.aliases ? monster.aliases.join(', ') : '']);

Check warning on line 1283 in src/lib/data/Collections.ts

View workflow job for this annotation

GitHub Actions / Node v18.12.0 - ubuntu-latest

Unexpected object value in conditional. The condition is always true

Check warning on line 1283 in src/lib/data/Collections.ts

View workflow job for this annotation

GitHub Actions / Node v20 - ubuntu-latest

Unexpected object value in conditional. The condition is always true
}
const normalTable = table([['Type', 'name: ', 'Alias'], ...[...categories, ...activities, ...roles]]);
const normalTable = makeTable(['Type', 'name: ', 'Alias'], [...categories, ...activities, ...roles]);
return new AttachmentBuilder(Buffer.from(normalTable), { name: 'possible_logs.txt' });
}

Expand Down
939 changes: 939 additions & 0 deletions src/lib/data/creatablesTable.txt

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/lib/util/smallUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { readFileSync } from 'node:fs';

import { miniID, toTitleCase } from '@oldschoolgg/toolkit';
import type { Prisma } from '@prisma/client';
import { AlignmentEnum, AsciiTable3 } from 'ascii-table3';
import deepmerge from 'deepmerge';
import { ButtonBuilder, ButtonStyle, InteractionReplyOptions, time } from 'discord.js';
import { clamp, objectEntries, roll, Time } from 'e';
Expand Down Expand Up @@ -339,3 +340,13 @@ export function ellipsize(str: string, maxLen: number = 2000) {
}
return str;
}

export function makeTable(headers: string[], rows: unknown[][]) {
return new AsciiTable3()
.setHeading(...headers)
.setAlign(1, AlignmentEnum.RIGHT)
.setAlign(2, AlignmentEnum.CENTER)
.setAlign(3, AlignmentEnum.LEFT)
.addRowMatrix(rows)
.toString();
}
14 changes: 4 additions & 10 deletions src/mahoji/lib/abstracted_commands/slayerShopCommand.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ChatInputCommandInteraction } from 'discord.js';
import { removeFromArr } from 'e';
import { Bank } from 'oldschooljs';
import { table } from 'table';

import { BitField } from '../../../lib/constants';
import { SlayerRewardsShop } from '../../../lib/slayer/slayerUnlocks';
import { stringMatches } from '../../../lib/util';
import { makeTable, stringMatches } from '../../../lib/util';
import { handleMahojiConfirmation } from '../../../lib/util/handleMahojiConfirmation';
import { logError } from '../../../lib/util/logError';

Expand Down Expand Up @@ -129,15 +128,10 @@ export function slayerShopListRewards(type: 'all' | 'unlocks' | 'buyables') {
type === 'all' ? true : type === 'unlocks' ? !srs.item : Boolean(srs.item)
);

const unlockTable = table([
const unlockTable = makeTable(
['Slayer Points', 'name: ', 'Description', 'Type'],
...availableUnlocks.map(i => [
i.slayerPointCost,
i.name,
i.desc,
i.extendMult === undefined ? 'unlock' : 'extend'
])
]);
availableUnlocks.map(i => [i.slayerPointCost, i.name, i.desc, i.extendMult === undefined ? 'unlock' : 'extend'])
);

const content = type === 'all' ? 'List of all slayer rewards' : `List sof slayer ${type}`;
return {
Expand Down
32 changes: 7 additions & 25 deletions src/scripts/render-creatables-file.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
import '../lib/data/itemAliases';

import { Stopwatch } from '@sapphire/stopwatch';
import { existsSync, writeFileSync } from 'fs';
import { writeFileSync } from 'fs';
import { Bank } from 'oldschooljs';
import { table } from 'table';

import Createables from '../lib/data/createables';
import { md5sum } from '../lib/util';
import { makeTable } from '../lib/util/smallUtils';

export function main() {
const data = [
['Item name', 'Input Items', 'Output Items', 'GP Cost'],
...Createables.map(i => {
return [i.name, `${new Bank(i.inputItems)}`, `${new Bank(i.outputItems)}`, `${i.GPCost ?? 0}`];
})
];
const hash = md5sum(JSON.stringify(data)).slice(0, 5);
const fileName = `./src/lib/data/creatablesTable_${hash}.txt`;
const headers = ['Item name', 'Input Items', 'Output Items', 'GP Cost'];
const rows = Createables.map(i => {
return [i.name, `${new Bank(i.inputItems)}`, `${new Bank(i.outputItems)}`, `${i.GPCost ?? 0}`];
});

const exists = existsSync(fileName);
if (exists) {
console.log('No changes to creatables');
return;
}

const stopwatch = new Stopwatch();
stopwatch.start();
const creatableTable = table(data);
stopwatch.stop();
console.log(`Rendered creatables table in ${stopwatch.toString()}`);

writeFileSync(fileName, creatableTable);
writeFileSync('./src/lib/data/creatablesTable.txt', makeTable(headers, rows));
}

main();
44 changes: 13 additions & 31 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ ajv@^6.10.0, ajv@^6.12.4:
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"

ajv@^8.0.0, ajv@^8.0.1, ajv@^8.10.0, ajv@^8.11.0:
ajv@^8.0.0, ajv@^8.10.0, ajv@^8.11.0:
version "8.12.0"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.12.0.tgz#d1a0527323e22f53562c567c00991577dfbe19d1"
integrity sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==
Expand Down Expand Up @@ -1351,6 +1351,13 @@ array.prototype.flatmap@^1.3.1:
es-abstract "^1.20.4"
es-shim-unscopables "^1.0.0"

ascii-table3@^0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/ascii-table3/-/ascii-table3-0.9.0.tgz#fed1f8c735bd056f1d67b4dff482a72b0858ebad"
integrity sha512-/JcvVCQRTVQHwLI8TCxSeOS9AcCV01MbCJC4plSP5ulygJH+D30lz85nvMcER5k+qoX2fJ1C/i13Zo1/eoMGTw==
dependencies:
printable-characters "^1.0.42"

assertion-error@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b"
Expand All @@ -1366,11 +1373,6 @@ ast-module-types@^3.0.0:
resolved "https://registry.yarnpkg.com/ast-module-types/-/ast-module-types-3.0.0.tgz#9a6d8a80f438b6b8fe4995699d700297f398bf81"
integrity sha512-CMxMCOCS+4D+DkOQfuZf+vLrSEmY/7xtORwdxs4wtcC1wVgvk2MqFFTwQCFhvWsI4KPU9lcWXPI8DgRiz+xetQ==

astral-regex@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31"
integrity sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==

asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
Expand Down Expand Up @@ -3626,11 +3628,6 @@ lodash.snakecase@^4.1.1:
resolved "https://registry.yarnpkg.com/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz#39d714a35357147837aefd64b5dcbb16becd8f8d"
integrity sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==

lodash.truncate@^4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/lodash.truncate/-/lodash.truncate-4.4.2.tgz#5a350da0b1113b837ecfffd5812cbe58d6eae193"
integrity sha1-WjUNoLERO4N+z//VgSy+WNbq4ZM=

lodash@^4.17.21, lodash@^4.17.4:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
Expand Down Expand Up @@ -4439,6 +4436,11 @@ pretty-ms@^7.0.1:
dependencies:
parse-ms "^2.1.0"

printable-characters@^1.0.42:
version "1.0.42"
resolved "https://registry.yarnpkg.com/printable-characters/-/printable-characters-1.0.42.tgz#3f18e977a9bd8eb37fcc4ff5659d7be90868b3d8"
integrity sha512-dKp+C4iXWK4vVYZmYSd0KBH5F/h1HoZRsbJ82AVKRO3PEo8L4lBS/vLwhVtpwwuYcoIsVY+1JYKR268yn480uQ==

prisma@^5.10.2:
version "5.10.2"
resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.10.2.tgz#aa63085c49dc74cdb5c3816e8dd1fb4d74a2aadd"
Expand Down Expand Up @@ -4875,15 +4877,6 @@ slash@^3.0.0:
resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634"
integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==

slice-ansi@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-4.0.0.tgz#500e8dd0fd55b05815086255b3195adf2a45fe6b"
integrity sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==
dependencies:
ansi-styles "^4.0.0"
astral-regex "^2.0.0"
is-fullwidth-code-point "^3.0.0"

sonic-boom@^3.1.0:
version "3.2.1"
resolved "https://registry.yarnpkg.com/sonic-boom/-/sonic-boom-3.2.1.tgz#972ceab831b5840a08a002fa95a672008bda1c38"
Expand Down Expand Up @@ -5116,17 +5109,6 @@ supports-preserve-symlinks-flag@^1.0.0:
resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==

table@^6.8.1:
version "6.8.1"
resolved "https://registry.yarnpkg.com/table/-/table-6.8.1.tgz#ea2b71359fe03b017a5fbc296204471158080bdf"
integrity sha512-Y4X9zqrCftUhMeH2EptSSERdVKt/nEdijTOacGD/97EKjhQ/Qs8RTlEGABSJNNN8lac9kheH+af7yAkEWlgneA==
dependencies:
ajv "^8.0.1"
lodash.truncate "^4.4.2"
slice-ansi "^4.0.0"
string-width "^4.2.3"
strip-ansi "^6.0.1"

tapable@^2.2.0:
version "2.2.1"
resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.1.tgz#1967a73ef4060a82f12ab96af86d52fdb76eeca0"
Expand Down

0 comments on commit 87e4a7d

Please sign in to comment.