Skip to content

Commit

Permalink
Add force_comp_update command
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Feb 22, 2024
1 parent 4cd4467 commit 76bbf34
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/lib/bso/calculateCompCapeProgress.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { calcWhatPercent } from 'e';

import { userStatsUpdate } from '../../mahoji/mahojiSettings';
import { compCapeCategories, compCapeTrimmedRequirements } from '../compCape';

export async function calculateCompCapeProgress(user: MUser) {
Expand Down Expand Up @@ -40,6 +41,11 @@ export async function calculateCompCapeProgress(user: MUser) {
2
)}%)`;

await userStatsUpdate(user.id, {
comp_cape_percent: totalPercentTrimmed,
untrimmed_comp_cape_percent: totalPercentUntrimmed
});

return {
resultStr: `Completionist Cape Progress
Expand Down
8 changes: 2 additions & 6 deletions src/mahoji/commands/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ApplicationCommandOptionType, CommandRunOptions } from 'mahoji';
import { calculateCompCapeProgress } from '../../lib/bso/calculateCompCapeProgress';
import { generateAllCompCapeTasksList } from '../../lib/compCape';
import { OSBMahojiCommand } from '../lib/util';
import { userStatsUpdate } from '../mahojiSettings';

export const completionCommand: OSBMahojiCommand = {
name: 'completion',
Expand All @@ -29,11 +28,8 @@ export const completionCommand: OSBMahojiCommand = {
run: async ({ options, userID }: CommandRunOptions<{ check?: {}; view_all_tasks?: {} }>) => {
const user = await mUserFetch(userID);
if (options.check) {
const { resultStr, totalPercentTrimmed, totalPercentUntrimmed } = await calculateCompCapeProgress(user);
await userStatsUpdate(user.id, {
comp_cape_percent: totalPercentTrimmed,
untrimmed_comp_cape_percent: totalPercentUntrimmed
});
const { resultStr } = await calculateCompCapeProgress(user);

return {
files: [new AttachmentBuilder(Buffer.from(resultStr), { name: 'compcape.txt' })]
};
Expand Down
25 changes: 25 additions & 0 deletions src/mahoji/commands/rp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Bank } from 'oldschooljs';
import { Item } from 'oldschooljs/dist/meta/types';

import { ADMIN_IDS, OWNER_IDS, production, SupportServer } from '../../config';
import { calculateCompCapeProgress } from '../../lib/bso/calculateCompCapeProgress';
import { BitField, Channel } from '../../lib/constants';
import { GearSetupType } from '../../lib/gear/types';
import { GrandExchange } from '../../lib/grandExchange';
Expand Down Expand Up @@ -72,6 +73,12 @@ export const rpCommand: OSBMahojiCommand = {
name: 'patreon_reset',
description: 'Reset all patreon data.',
options: []
},
{
type: ApplicationCommandOptionType.Subcommand,
name: 'force_comp_update',
description: 'Force the top 100 completionist users to update their completion percentage.',
options: []
}
]
},
Expand Down Expand Up @@ -315,6 +322,7 @@ export const rpCommand: OSBMahojiCommand = {
action?: {
validate_ge?: {};
patreon_reset?: {};
force_comp_update?: {};
};
player?: {
givetgb?: { user: MahojiUserOption };
Expand Down Expand Up @@ -375,6 +383,23 @@ export const rpCommand: OSBMahojiCommand = {
}
return 'Something was invalid. Check logs!';
}
if (options.action?.force_comp_update) {
const usersToUpdate = await prisma.userStats.findMany({
where: {
untrimmed_comp_cape_percent: {
not: null
}
},
orderBy: {
untrimmed_comp_cape_percent: 'desc'
},
take: 100
});
for (const user of usersToUpdate) {
await calculateCompCapeProgress(await mUserFetch(user.user_id.toString()));
}
return 'Done.';
}

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

0 comments on commit 76bbf34

Please sign in to comment.