Skip to content

Commit

Permalink
Add ability to remove custom tame icon (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
themrrobert authored Feb 29, 2024
1 parent d3f69ba commit 76fdb3b
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/mahoji/commands/tames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1993,10 +1993,12 @@ export const tamesCommand: OSBMahojiCommand = {
description: 'The image to pick.',
required: true,
autocomplete: async () => {
return tameImageReplacementChoices.map(t => ({
const options = tameImageReplacementChoices.map(t => ({
name: `${t.name} (${tameSpecies.find(s => s.id === t.species)!.name})`,
value: t.name
}));
options.unshift({ name: 'None', value: 'none' });
return options;
}
}
]
Expand Down Expand Up @@ -2075,12 +2077,31 @@ export const tamesCommand: OSBMahojiCommand = {
if (user.perkTier() < PerkTier.Four) {
return 'You need to be a Tier 3 patron to set a custom image for your tame.';
}

// Handle resetting the custom image:
if (options.set_custom_image?.image.toLowerCase() === 'none') {
const { tame } = await getUsersTame(user);
if (tame === null) {
return "You don't have a tame selected, select the tame who's icon should be reset.";
}
await prisma.tame.update({
where: {
id: tame.id
},
data: {
custom_icon_id: null
}
});
return 'Successfully removed the custom tame icon!';
}

// Handle updating the image:
const replacement = tameImageReplacementChoices.find(i => i.name === options.set_custom_image?.image);
if (!replacement) {
return 'Invalid image.';
}
const { tame } = await getUsersTame(user);
if (!tame) {
if (tame === null) {
return "You don't have a tame selected, select the tame you want to give this icon.";
}
if (tame.species_id !== replacement.species) {
Expand Down

0 comments on commit 76fdb3b

Please sign in to comment.