From a32cd7441b4b8d4ec9ff8fd3d3cfe85b272231fb Mon Sep 17 00:00:00 2001 From: TastyPumPum <79149170+TastyPumPum@users.noreply.github.com> Date: Mon, 12 Feb 2024 02:22:55 +0000 Subject: [PATCH] Add /testpotato setslayertask (#5682) --- src/lib/slayer/tasks/index.ts | 2 + src/mahoji/commands/testpotato.ts | 100 ++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/src/lib/slayer/tasks/index.ts b/src/lib/slayer/tasks/index.ts index a514c6c844..b33c3dccc0 100644 --- a/src/lib/slayer/tasks/index.ts +++ b/src/lib/slayer/tasks/index.ts @@ -18,3 +18,5 @@ export const allSlayerTasks: AssignableSlayerTask[] = [ ...vannakaTasks, ...duradelTasks ]; + +export const allSlayerMonsters = allSlayerTasks.map(m => m.monster); diff --git a/src/mahoji/commands/testpotato.ts b/src/mahoji/commands/testpotato.ts index 11e9f306af..3006ae867a 100644 --- a/src/mahoji/commands/testpotato.ts +++ b/src/mahoji/commands/testpotato.ts @@ -24,6 +24,10 @@ import { prisma } from '../../lib/settings/prisma'; import { getFarmingInfo } from '../../lib/skilling/functions/getFarmingInfo'; import Skills from '../../lib/skilling/skills'; import Farming from '../../lib/skilling/skills/farming'; +import { slayerMasterChoices } from '../../lib/slayer/constants'; +import { slayerMasters } from '../../lib/slayer/slayerMasters'; +import { getUsersCurrentSlayerInfo } from '../../lib/slayer/slayerUtil'; +import { allSlayerMonsters } from '../../lib/slayer/tasks'; import { stringMatches } from '../../lib/util'; import { calcDropRatesFromBankWithoutUniques } from '../../lib/util/calcDropRatesFromBank'; import { @@ -514,6 +518,46 @@ export const testPotatoCommand: OSBMahojiCommand | null = production } } ] + }, + { + type: ApplicationCommandOptionType.Subcommand, + name: 'setslayertask', + description: 'Set slayer task.', + options: [ + { + type: ApplicationCommandOptionType.String, + name: 'master', + description: 'The master you wish to set your task.', + required: true, + choices: slayerMasterChoices + }, + { + type: ApplicationCommandOptionType.String, + name: 'monster', + description: 'The monster you want to set your task as.', + required: true, + autocomplete: async value => { + const filteredMonsters = [...new Set(allSlayerMonsters)].filter(monster => { + if (!value) return true; + return [monster.name.toLowerCase(), ...monster.aliases].some(aliases => + aliases.includes(value.toLowerCase()) + ); + }); + return filteredMonsters.map(monster => ({ + name: monster.name, + value: monster.name + })); + } + }, + { + type: ApplicationCommandOptionType.Integer, + name: 'quantity', + description: 'The task quantity you want to assign.', + required: false, + min_value: 0, + max_value: 1000 + } + ] } ], run: async ({ @@ -534,6 +578,7 @@ export const testPotatoCommand: OSBMahojiCommand | null = production set?: { qp?: number; all_ca_tasks?: boolean }; check?: { monster_droprates?: string }; bingo_tools?: { start_bingo: string }; + setslayertask?: { master: string; monster: string; quantity: number }; }>) => { if (production) { logError('Test command ran in production', { userID: userID.toString() }); @@ -832,6 +877,61 @@ ${droprates.join('\n')}`), return userGrowingProgressStr((await getFarmingInfo(userID)).patchesDetailed); } + if (options.setslayertask) { + const user = await mUserFetch(userID); + const usersTask = await getUsersCurrentSlayerInfo(user.id); + + const { monster, master } = options.setslayertask; + + const selectedMonster = allSlayerMonsters.find(m => stringMatches(m.name, monster)); + const selectedMaster = slayerMasters.find( + sm => stringMatches(master, sm.name) || sm.aliases.some(alias => stringMatches(master, alias)) + ); + + // Set quantity to 50 if user doesn't assign a quantity + const quantity = options.setslayertask?.quantity ?? 50; + + const assignedTask = selectedMaster!.tasks.find(m => m.monster.id === selectedMonster?.id)!; + + if (!selectedMaster) return 'Invalid slayer master.'; + if (!selectedMonster) return 'Invalid monster.'; + if (!assignedTask) return `${selectedMaster.name} can not assign ${selectedMonster.name}.`; + + // Update an existing slayer task for the user + if (usersTask.currentTask?.id) { + await prisma.slayerTask.update({ + where: { + id: usersTask.currentTask?.id + }, + data: { + quantity, + quantity_remaining: quantity, + slayer_master_id: selectedMaster.id, + monster_id: selectedMonster.id, + skipped: false + } + }); + } else { + // Create a new slayer task for the user + await prisma.slayerTask.create({ + data: { + user_id: user.id, + quantity, + quantity_remaining: quantity, + slayer_master_id: selectedMaster.id, + monster_id: selectedMonster.id, + skipped: false + } + }); + } + + await user.update({ + slayer_last_task: selectedMonster.id + }); + + return `You set your slayer task to ${selectedMonster.name} using ${selectedMaster.name}.`; + } + return 'Nothin!'; } };