min and max limits for counters
This commit is contained in:
parent
233a663d0c
commit
2bb3512316
|
@ -434,8 +434,9 @@ module.exports = {
|
|||
|
||||
await setCounterConfig(counter, 'canIncrement', 'false');
|
||||
await setCounterConfig(counter, 'canDecrement', 'false');
|
||||
await setCounterConfig(counter, 'min', '0');
|
||||
|
||||
await interaction.followUp(`Done. **The counter has been reset** to ${formatItems(item, 0)}. Users will not be able to take out or put in items until you enable this with \`canTake\` or \`canPut\`.\n\`canIncrement\` and \`canDecrement\` have also been **automatically disabled**, and you are recommended to keep them as such if you want to maintain balance in the universe.`);
|
||||
await interaction.followUp(`Done. **The counter has been reset** to ${formatItems(item, 0)}. Users will not be able to take out or put in items until you enable this with \`canTake\` or \`canPut\`.\n\`canIncrement\` and \`canDecrement\` have also been **automatically disabled** and \`min\` has been set to **0**, and you are recommended to keep these values as such if you want to maintain balance in the universe.`);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -199,6 +199,14 @@ export const counterConfigs = new Map([
|
|||
type: ConfigType.Bool,
|
||||
default: false
|
||||
}],
|
||||
['min', {
|
||||
type: ConfigType.Number,
|
||||
default: -Number.MIN_SAFE_INTEGER
|
||||
}],
|
||||
['max', {
|
||||
type: ConfigType.Number,
|
||||
default: Number.MAX_SAFE_INTEGER
|
||||
}],
|
||||
|
||||
// these ones are fake and are just stand-ins for values defined inside the actual counters table
|
||||
['emoji', {
|
||||
|
@ -338,6 +346,19 @@ function changeCounterInteractionBuilder(linked: boolean) {
|
|||
newInv = await giveItem(member.id, item, amtInv);
|
||||
}
|
||||
|
||||
const min = await getCounterConfig(counter.id, 'min') as number;
|
||||
const max = await getCounterConfig(counter.id, 'max') as number;
|
||||
if (counter.value + amount < min) {
|
||||
if (min === 0) {
|
||||
return interaction.followUp(`You cannot remove more than how much is in the counter (${counter.value}x ${counter.emoji})!`);
|
||||
} else {
|
||||
return interaction.followUp(`You cannot decrement past the minimum value (${min})!`);
|
||||
}
|
||||
}
|
||||
if (counter.value + amount > max) {
|
||||
return interaction.followUp(`You are adding more than the counter can hold (${max}x)!`);
|
||||
}
|
||||
|
||||
const newCount = await changeCounter(counter.id, amount);
|
||||
await updateCounter(interaction.client, counter, newCount);
|
||||
await announceCounterUpdate(interaction.client, member, amount, counter, newCount, linked);
|
||||
|
|
Loading…
Reference in New Issue