Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ A Hypixel and Minecraft focused Discord Bot

### 🚀 Running
* The codebase is split into apps and packages
* Set up a `config.js` file in the root of the project following the `config.schema.js` file (copy paste it over and fill it in)
* Set up a `config.js` file in the root of the project following the `config.schema.js` file (copy and paste it over and fill it in)
* Pull the git submodules (`git submodule update --init`)
* Set up the assets by running `cd assets/public && pnpm`
* Use `pnpm build` to build all packages and apps,
Expand All @@ -35,10 +35,10 @@ A Hypixel and Minecraft focused Discord Bot
### 🤖 Other Important commands
```bash
# Change things in a package/app
$ pnpm workspace {app or package name} {command}
$ pnpm --filter {app or package name} {command}

# Example: Adding a dependency
$ pnpm workspace {app or package name} add {dependency}
$ pnpm --filter {app or package name} add {dependency}

# Linting
$ pnpm lint
Expand Down
2 changes: 1 addition & 1 deletion apps/scripts/src/api-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ const deleteKey = async () => {
},
]);

if (!(await inquirerConfirmation(false))) return;
if (!(await inquirerConfirmation("Are you sure?", false))) return;

const activeKeys = await getKeys();

Expand Down
15 changes: 11 additions & 4 deletions apps/scripts/src/limit-redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,23 @@ import { SimpleIntervalJob, Task } from "toad-scheduler";
const logger = new Logger("Redis Limiter");
const redis = new Redis(process.env.REDIS_URL);

const getLeaderboardPath = (constructor, key, prefix) => {
const name = constructor.name.toLowerCase();
const path = `${name}.${key}`;

return prefix ? `${prefix}:${path}` : path;
};

const runLimit = async (constructors, prefixes) => {
constructors.forEach(async (constructor, i) => {
await Promise.all(constructors.map(async (constructor, i) => {
const oldLeaderboardPipeline = redis.pipeline();
const limitLeaderboardPipeline = redis.pipeline();

const name = constructor.name.toLowerCase();
const fields = MetadataScanner.scan(constructor);

fields.forEach(([key, value]) => {
const path = prefixes ? `${prefixes[i]}:${name}.${key}` : `${name}.${key}`;
const path = getLeaderboardPath(constructor, key, prefixes?.[i]);
if (!value.leaderboard.enabled || (prefixes ? !value.historical.enabled : false))
oldLeaderboardPipeline.del(path);
});
Expand All @@ -38,7 +45,7 @@ const runLimit = async (constructors, prefixes) => {
let memberCount = 0;

leaderboards.forEach(([key, value]) => {
const path = `${name}.${key}`;
const path = getLeaderboardPath(constructor, key, prefixes?.[i]);
const { sort } = value.leaderboard;
let { limit } = value.leaderboard;
if (limit === Number.POSITIVE_INFINITY) return;
Expand All @@ -63,7 +70,7 @@ const runLimit = async (constructors, prefixes) => {
prefixes ? prefixes[i].toLowerCase() : "lifetime"
} ${name} leaderboards`
);
});
}));
};

const limit = async () => {
Expand Down
10 changes: 5 additions & 5 deletions apps/scripts/src/timestamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ const setTimestamps = async (collectionName) => {

if (!bulkOperations.length)
return console.log(`No players to update for ${collectionName}.`);
collection.bulkWrite(bulkOperations).then((res) => {
console.log(
`Updated ${res.modifiedCount}/${players.length} players for ${collectionName}.`
);
});
const res = await collection.bulkWrite(bulkOperations);

console.log(
`Updated ${res.modifiedCount}/${players.length} players for ${collectionName}.`
);
};

await setTimestamps("daily");
Expand Down
14 changes: 7 additions & 7 deletions apps/scripts/src/validate-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
* https://github.com/Statsify/statsify/blob/main/LICENSE
*/

import commands from "discord-bot/commands.json" assert { type: "json" };
import commands from "discord-bot/commands.json" with { type: "json" };
import z from "zod";

function toEnum(...args) {
return z.union(args.map((arg) => z.literal(arg)));
}

const name = z.string().min(3).max(32);
const name_localizations = z.optional(z.record(name));
const name_localizations = z.optional(z.record(z.string(), name));

const description = z.string().min(1).max(100);
const description_localizations = z.optional(z.record(description));
const description_localizations = z.optional(z.record(z.string(), description));

const choicesSchema = z.object({
// this is intentional since choice names can go up to 100 characters
Expand Down Expand Up @@ -58,9 +58,9 @@ Object.entries(commands.commands).forEach(([commandName, command]) => {
} catch (e) {
console.error(e);
console.log(command);
e.errors.forEach((e) => {
console.error(e.message);
console.error(`${command.name}.${e.path.join(".")}`);
(e.issues ?? [e]).forEach((issue) => {
console.error(issue.message);
console.error(`${command.name}.${issue.path?.join(".") ?? ""}`);
});
console.error(`Command "${commandName}" is invalid.`);
process.exit(1);
Expand All @@ -79,7 +79,7 @@ const findOptionsLength = (options = []) =>
option.name.length +
findLongestLocalizationLength(option.description_localizations) +
(
option?.choices?.map((choice) => choice.value.length + choice.name.length) ?? []
option?.choices?.map((choice) => String(choice.value).length + choice.name.length) ?? []
).reduce((a, b) => a + b, 0)
)
.reduce((a, b) => a + b, 0);
Expand Down
Loading