Skip to content

Commit

Permalink
Merge pull request #42 from padlocks/dev
Browse files Browse the repository at this point in the history
Bugfixes
  • Loading branch information
padlocks authored Jun 27, 2024
2 parents c19747c + b99bed9 commit 8b4b756
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/class/Aquarium.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class Aquarium {
return this.aquarium.lastAdjusted;
}

async isFull() {
return this.aquarium.fish.length >= this.aquarium.size;
}

async updateStatus() {
const now = new Date();
const lastCleaned = new Date(this.aquarium.lastCleaned);
Expand Down
2 changes: 1 addition & 1 deletion src/class/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class User {

async removeBait(baitId) {
this.user.inventory.baits = this.user.inventory.baits.filter((b) => b.valueOf() !== baitId);
await this.save();
return await this.save();
}

async getItems() {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/slash/Fish/fish.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const updateUserWithFish = async (interaction, userId) => {
const stats = await user.getStats();
stats.latestFish = [];
if (bait) {
bait.count -= fishArray.length;
bait.count -= fishArray.reduce((acc, f) => acc + (f.count || 1), 0);
if (bait.count <= 0) {
await user.setEquippedBait(null);
// delete bait from user inventory
Expand Down Expand Up @@ -288,7 +288,7 @@ module.exports = {
const collector = followUp.createMessageComponentCollector({
componentType: ComponentType.Button,
// filter,
time: 10000,
time: 30_000,
});

collector.on('collect', async collectionInteraction => {
Expand Down
17 changes: 16 additions & 1 deletion src/commands/slash/Pet/adopt.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,27 @@ module.exports = {
const aquariumData = await aquariums.find((a) => a.name.toLowerCase() === aquariumName.toLowerCase());
const aquarium = new Aquarium(aquariumData);

// check if aquarium is full
if (await aquarium.isFull()) {
if (process.env.ANALYTICS || config.client.analytics) {
await analyticsObject.setStatus('failed');
await analyticsObject.setStatusMessage('Aquarium is full.');
}
return interaction.editReply({ content: 'Your aquarium is full! Use the `upgrade` command to increase its capacity.', ephemeral: true });
}

// find the desired fish in user's inventory
const fishes = await user.getFish();
const fishInInventory = await fishes.find((f) => f.name.toLowerCase() === species.toLowerCase() && !f.locked);

// check if biome origin is the same as the aquarium's water type
if (!await aquarium.compareBiome(fishInInventory.biome)) return await interaction.followUp(`**${fishInInventory.name}** cannot live in a ${await aquarium.getWaterType()} aquarium.`);
if (!await aquarium.compareBiome(fishInInventory.biome)) {
if (process.env.ANALYTICS || config.client.analytics) {
await analyticsObject.setStatus('failed');
await analyticsObject.setStatusMessage(`Fish cannot live in a ${await aquarium.getWaterType()} aquarium.`);
}
return await interaction.followUp(`**${fishInInventory.name}** cannot live in a ${await aquarium.getWaterType()} aquarium.`);
}

// remove fish from inventory
await user.removeFish(fishInInventory.id);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/slash/User/equip.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const selectionOptions = async (inventoryPath, userData, allowNone = true) => {
}

if (uniqueValues.has(name)) {
counts[name] = (counts[name] || 1) + (item.count || 1);
counts[name] += (item.count || 1);
continue;
}
else {
Expand Down
1 change: 1 addition & 0 deletions src/components/buttons/buy-bait.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ const hasEnoughMoney = async (userData, item, amount) => {

const buyItem = async (userData, item, amount) => {
await userData.addMoney(-item.price * amount);
item.count = amount;
let baitItem;
const baits = await userData.getAllBaits();
const itemId = baits.find((bait) => bait.name === item.name);
Expand Down

0 comments on commit 8b4b756

Please sign in to comment.