From 76bbf340d3324b9ad0694e84116e980899ab03ec Mon Sep 17 00:00:00 2001 From: gc <30398469+gc@users.noreply.github.com> Date: Thu, 22 Feb 2024 17:13:00 +1100 Subject: [PATCH] Add force_comp_update command --- src/lib/bso/calculateCompCapeProgress.ts | 6 ++++++ src/mahoji/commands/completion.ts | 8 ++------ src/mahoji/commands/rp.ts | 25 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/lib/bso/calculateCompCapeProgress.ts b/src/lib/bso/calculateCompCapeProgress.ts index 1743f77001..687d2bd709 100644 --- a/src/lib/bso/calculateCompCapeProgress.ts +++ b/src/lib/bso/calculateCompCapeProgress.ts @@ -1,5 +1,6 @@ import { calcWhatPercent } from 'e'; +import { userStatsUpdate } from '../../mahoji/mahojiSettings'; import { compCapeCategories, compCapeTrimmedRequirements } from '../compCape'; export async function calculateCompCapeProgress(user: MUser) { @@ -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 diff --git a/src/mahoji/commands/completion.ts b/src/mahoji/commands/completion.ts index c9121e4c41..0e6eb7f2de 100644 --- a/src/mahoji/commands/completion.ts +++ b/src/mahoji/commands/completion.ts @@ -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', @@ -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' })] }; diff --git a/src/mahoji/commands/rp.ts b/src/mahoji/commands/rp.ts index 889bab91fb..a233022d06 100644 --- a/src/mahoji/commands/rp.ts +++ b/src/mahoji/commands/rp.ts @@ -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'; @@ -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: [] } ] }, @@ -315,6 +322,7 @@ export const rpCommand: OSBMahojiCommand = { action?: { validate_ge?: {}; patreon_reset?: {}; + force_comp_update?: {}; }; player?: { givetgb?: { user: MahojiUserOption }; @@ -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 = [