Skip to content

Commit

Permalink
Add view_all_items rp action
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Feb 22, 2024
1 parent cb94307 commit 982591e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/mahoji/commands/rp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { allPerkBitfields } from '../../lib/perkTiers';
import { prisma } from '../../lib/settings/prisma';
import { TeamLoot } from '../../lib/simulation/TeamLoot';
import { ItemBank } from '../../lib/types';
import { dateFm, formatDuration } from '../../lib/util';
import { dateFm, formatDuration, returnStringOrFile } from '../../lib/util';
import getOSItem from '../../lib/util/getOSItem';
import { handleMahojiConfirmation } from '../../lib/util/handleMahojiConfirmation';
import { deferInteraction } from '../../lib/util/interactionReply';
Expand Down Expand Up @@ -72,6 +72,12 @@ export const rpCommand: OSBMahojiCommand = {
name: 'patreon_reset',
description: 'Reset all patreon data.',
options: []
},
{
type: ApplicationCommandOptionType.Subcommand,
name: 'view_all_items',
description: 'View all item IDs present in banks/cls.',
options: []
}
]
},
Expand Down Expand Up @@ -302,6 +308,7 @@ export const rpCommand: OSBMahojiCommand = {
action?: {
validate_ge?: {};
patreon_reset?: {};
view_all_items?: {};
};
player?: {
viewbank?: { user: MahojiUserOption; json?: boolean };
Expand Down Expand Up @@ -349,6 +356,18 @@ export const rpCommand: OSBMahojiCommand = {
return 'Something was invalid. Check logs!';
}

if (options.action?.view_all_items) {
const result = await prisma.$queryRawUnsafe<
{ item_id: number }[]
>(`SELECT DISTINCT json_object_keys(bank)::int AS item_id
FROM users
UNION
SELECT DISTINCT jsonb_object_keys("collectionLogBank")::int AS item_id
FROM users
ORDER BY item_id ASC;`);
return returnStringOrFile(`[${result.map(i => i.item_id).join(',')}]`);
}

if (options.action?.patreon_reset) {
const bitfieldsToRemove = [
BitField.IsPatronTier1,
Expand Down

0 comments on commit 982591e

Please sign in to comment.