Skip to content

Commit

Permalink
Merge branch 'master' into Disable-high-peak-time-warning
Browse files Browse the repository at this point in the history
  • Loading branch information
nwjgit authored Feb 12, 2024
2 parents a8a2f25 + a32cd74 commit c84a92d
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib/slayer/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ export const allSlayerTasks: AssignableSlayerTask[] = [
...vannakaTasks,
...duradelTasks
];

export const allSlayerMonsters = allSlayerTasks.map(m => m.monster);
100 changes: 100 additions & 0 deletions src/mahoji/commands/testpotato.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 ({
Expand All @@ -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() });
Expand Down Expand Up @@ -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!';
}
};

0 comments on commit c84a92d

Please sign in to comment.