Skip to content

Commit

Permalink
Fixed small bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
SiebeBaree committed Apr 22, 2024
1 parent 13bca5a commit e566693
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 60 deletions.
2 changes: 1 addition & 1 deletion apps/bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint": "prettier --check . && eslint src --ext .ts --format stylish src",
"format": "prettier --write . && eslint src --ext .ts --fix --format stylish src",
"register-commands": "bun run ./src/register.ts",
"script:balance-items": "nodemon --watch src --exec bun ./src/item-balancer.ts",
"script:balance-items": "bun run --hot ./src/item-balancer.ts",
"script:add-items": "bun run ./src/itemUploader.ts",
"script:convert-commands": "bun run ./src/commandsConverter.ts"
},
Expand Down
2 changes: 1 addition & 1 deletion apps/bot/src/commands/business/business/employee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ async function fire(client: Bot, interaction: ChatInputCommandInteraction, data:
const embed = new EmbedBuilder()
.setTitle(`Fired ${fetchedUser.username}`)
.setDescription(
`${fetchedUser} has been fired from ${data.business.name} and they recieved their cut of ${percentage}% (:coin: ${cut}) of the business balance.`,
`${fetchedUser} has been fired from ${data.business.name} and they received their cut of ${percentage}% (:coin: ${cut}) of the business balance.`,
)
.setColor(Colors.Red);
await interaction.reply({ embeds: [embed] });
Expand Down
45 changes: 41 additions & 4 deletions apps/bot/src/commands/business/business/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ function getInventory(
let worth = 0;

for (const invItem of business.inventory) {
const item = client.items.getById(invItem.itemId);
if (!item?.sellPrice) continue;
const item = client.business.getById(invItem.itemId);
if (!item?.price) continue;

worth += item.sellPrice * invItem.amount;
worth += item.price * invItem.amount;
items.push(`**${invItem.amount}x** <:${invItem.itemId}:${item.emoteId}> ${item.name}`);
}

Expand Down Expand Up @@ -182,6 +182,14 @@ async function getButtons(
.setStyle(ButtonStyle.Danger)
.setDisabled(disabled),
);
} else {
buttons.push(
new ButtonBuilder()
.setCustomId('business_leave')
.setLabel('Leave Business')
.setStyle(ButtonStyle.Danger)
.setDisabled(disabled),
);
}
} else {
buttons.push(
Expand Down Expand Up @@ -284,7 +292,36 @@ export default async function info(

collector.on('collect', async (i) => {
if (i.componentType === ComponentType.Button && i.customId.startsWith('business_')) {
if (i.customId === 'business_create' && business === null) {
if (i.customId === 'business_leave' && business !== null) {
const employee = business.employees.find((e) => e.userId === member.id);
if (!employee) return;

if (employee.position === Positions.CEO) {
await i.reply({
content: 'You cannot leave your business as the CEO. You can sell your business instead.',
ephemeral: true,
});
return;
}

await i.reply({
content: 'You have left the business.',
ephemeral: true,
});

await Business.updateOne(
{ name: business.name },
{
$pull: {
employees: {
userId: member.id,
},
},
},
);

business = null;
} else if (i.customId === 'business_create' && business === null) {
const createNameInput = new TextInputBuilder()
.setCustomId('business-create-name')
.setLabel('Business Name')
Expand Down
5 changes: 3 additions & 2 deletions apps/bot/src/commands/business/business/invest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default async function invest(

const amountStr = interaction.options.getString('amount', true);
const amount = parseStrToNum(amountStr);
const maxAmount = member.premium === 2 ? 10000 : 2000;

if (amount < 100) {
await interaction.reply({
Expand All @@ -42,9 +43,9 @@ export default async function invest(
ephemeral: true,
});
return;
} else if (amount > 2000) {
} else if (amount > maxAmount) {
await interaction.reply({
content: `You cannot invest more than :coin: 2000.`,
content: `You cannot invest more than :coin: ${maxAmount}.${member.premium < 2 ? `(Upgrade to [premium](<${client.config.website}/premium>) to increase the limit to :coin: 10,000)` : ''}`,
ephemeral: true,
});
return;
Expand Down
70 changes: 36 additions & 34 deletions apps/bot/src/commands/business/factory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import type { ColorResolvable, ChatInputCommandInteraction } from 'discord.js';
import type Bot from '../../../domain/Bot';
import type { Command } from '../../../domain/Command';
import { Positions, type BusinessData, type InventoryItem } from '../../../lib/types';
import Business, { type IFactory } from '../../../models/business';
// import Business, { type IFactory } from '../../../models/business';
import Business from '../../../models/business';
import { filter, getBusiness } from '../../../utils';
import levelUp from './_levelUp';
// import levelUp from './_levelUp';
import listItems from './_listItems';
import startProduction from './_startProduction';

Expand Down Expand Up @@ -204,22 +205,22 @@ async function pressButton_CollectProducts(client: Bot, data: BusinessData): Pro
}
}

async function pressButton_BuyFactory(data: BusinessData): Promise<boolean> {
const factoryId = data.business.factories.length;
const cost = getFactoryCost(factoryId + 1);
if (data.business.balance < cost) return false;

const factory: IFactory = {
factoryId,
level: 0,
production: '',
status: 'standby',
produceOn: 0,
};

await Business.updateOne({ name: data.business.name }, { $push: { factories: factory }, $inc: { balance: -cost } });
return true;
}
// async function pressButton_BuyFactory(data: BusinessData): Promise<boolean> {
// const factoryId = data.business.factories.length;
// const cost = getFactoryCost(factoryId + 1);
// if (data.business.balance < cost) return false;

// const factory: IFactory = {
// factoryId,
// level: 0,
// production: '',
// status: 'standby',
// produceOn: 0,
// };

// await Business.updateOne({ name: data.business.name }, { $push: { factories: factory }, $inc: { balance: -cost } });
// return true;
// }

export default {
data: {
Expand Down Expand Up @@ -270,30 +271,32 @@ export default {
await pressButton_CollectProducts(client, data);
await interaction.followUp({ content: 'You have collected all products.', ephemeral: true });
break;
case 'factory_buy_factory':
if (await pressButton_BuyFactory(data)) {
await interaction.followUp({ content: 'You have bought a new factory.', ephemeral: true });
} else {
await interaction.followUp({
content: 'You do not have enough balance to buy a new factory.',
ephemeral: true,
});
}

break;
case 'factory_level_up':
hasReplied = await levelUp(interaction, i, data);
break;
// case 'factory_buy_factory':
// if (await pressButton_BuyFactory(data)) {
// await interaction.followUp({ content: 'You have bought a new factory.', ephemeral: true });
// } else {
// await interaction.followUp({
// content: 'You do not have enough balance to buy a new factory.',
// ephemeral: true,
// });
// }

// break;
// case 'factory_level_up':
// hasReplied = await levelUp(interaction, i, data);
// break;
case 'factory_start_production':
hasReplied = await startProduction(client, interaction, i, data);
break;
case 'factory_list_items':
await listItems(client, interaction, data);
break;
default:
return;
break;
}

if (!hasReplied) await i.deferUpdate();

// get updated business to update embed
data = await getBusiness(interaction.user.id);
if (!data) {
Expand All @@ -302,7 +305,6 @@ export default {
return;
}

if (!hasReplied) await i.deferUpdate();
await interaction.editReply({
embeds: [await createEmbed(client, data)],
components: createComponents(data, finishedCommand),
Expand Down
4 changes: 2 additions & 2 deletions apps/bot/src/commands/business/farm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ async function getEmbed(client: Bot, user: User, member: IMember): Promise<Embed
description += `\n:moneybag: **You can buy a new plot for :coin: ${getPlotPrice(member.plots.length)}.**`;
} else if (member.plots.length >= maxPlots && member.plots.length < 15 && member.premium < 2) {
if (member.premium === 1) {
description += `\n:star: **Upgrade to [Coinz Pro](${client.config.website}/premium) to buy up to 15 plots.**`;
description += `\n:star: **Upgrade to [Coinz Pro](<${client.config.website}/premium>) to buy up to 15 plots.**`;
} else {
description += `\n:star: **Consider [upgrading to Coinz Plus or Pro](${client.config.website}/premium) to unlock up to 15 plots.**`;
description += `\n:star: **Consider [upgrading to Coinz Plus or Pro](<${client.config.website}/premium>) to unlock up to 15 plots.**`;
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/bot/src/commands/general/daily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function getEmbed(
embed.addFields([
{
name: 'Upgrade to Coinz Plus or Pro',
value: `:star: **Coinz Plus rewards:** :coin: ${premiumReward}\n:crown: **Coinz Pro rewards:** :coin: ${premiumReward}, ${xp * 2} XP, and an extra lucky wheel spin!\n:money_with_wings: Consider [**upgrading**](${client.config.website}/premium) to get more rewards!`,
value: `:star: **Coinz Plus rewards:** :coin: ${premiumReward}\n:crown: **Coinz Pro rewards:** :coin: ${premiumReward}, ${xp * 2} XP, and an extra lucky wheel spin!\n:money_with_wings: Consider [**upgrading**](<${client.config.website}/premium>) to get more rewards!`,
inline: false,
},
]);
Expand Down
4 changes: 2 additions & 2 deletions apps/bot/src/commands/general/pay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { addMoney, removeMoney } from '../../utils/money';
const LOWER_LIMIT = 30;
const START_LIMIT = 1000;
const MAX_LIMIT = 15_000;
const PREMIUM_LIMIT = 25_000;
const PREMIUM_LIMIT = 30_000;

function getLimit(level: number, premium: number): number {
if (premium >= 2) return PREMIUM_LIMIT;
Expand Down Expand Up @@ -83,7 +83,7 @@ export default {

let message = `:x: You can't donate more than :coin: ${limit} at your current level.`;
if (member.premium < 2 && amount < PREMIUM_LIMIT) {
message += ` You can increase your limit to :coin: 25.000 by becoming a Coinz Pro subscriber. [**Upgrade now**](${client.config.website}/premium).`;
message += ` You can increase your limit to :coin: 25.000 by becoming a Coinz Pro subscriber. [**Upgrade now**](<${client.config.website}/premium>).`;
}

await interaction.reply({
Expand Down
2 changes: 1 addition & 1 deletion apps/bot/src/commands/misc/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default {
})
.setColor(client.config.embed.color as ColorResolvable)
.setDescription(
`**If you like this bot, consider buying [Coinz Premium](${client.config.website}/premium).**`,
`**If you like this bot, consider buying [Coinz Premium](<${client.config.website}/premium>).**`,
)
.addFields([
{
Expand Down
2 changes: 1 addition & 1 deletion apps/bot/src/commands/misc/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function settingsProfileColor(client: Bot, interaction: ChatInputCommandIn

if (member.premium < 1 && color !== client.config.embed.color) {
await interaction.reply({
content: `This feature is reserved for premium users! Upgrade to [**Coinz Plus**](${client.config.website}/premium) or [**Coinz Pro**](${client.config.website}/premium) today!`,
content: `This feature is reserved for premium users! Upgrade to [**Coinz Plus**](<${client.config.website}/premium>) or [**Coinz Pro**](<${client.config.website}/premium>) today!`,
ephemeral: true,
});
return;
Expand Down
15 changes: 12 additions & 3 deletions apps/bot/src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export default {
)} before using this command again.`;

if (command.data.category === 'games' && member.premium < 2) {
message += `\nYou can reduce this cooldown by becoming a Coinz Pro subscriber. [**Upgrade now**](${client.config.website}/premium)`;
message += `\nYou can reduce this cooldown by becoming a Coinz Pro subscriber. [**Upgrade now**](<${client.config.website}/premium>)`;
} else if (
(command.data.cooldown === undefined || command.data.cooldown === 0) &&
member.premium === 0
) {
message += `\nYou can reduce this cooldown to 1 second by becoming a Coinz Plus or Pro subscriber. [**Upgrade now**](${client.config.website}/premium)`;
message += `\nYou can reduce this cooldown to 1 second by becoming a Coinz Plus or Pro subscriber. [**Upgrade now**](<${client.config.website}/premium>)`;
}

await interaction.reply({
Expand All @@ -52,8 +52,16 @@ export default {
}

if ((command.data.premium ?? 0) > member.premium) {
if (command.data.premium === 2) {
await interaction.reply({
content: `This command is only for Coinz Pro subscribers. To gain access to this command, consider [**upgrading**](<${client.config.website}/premium>).`,
ephemeral: true,
});
return;
}

await interaction.reply({
content: `This command is only for Coinz Plus or Pro subscribers. To gain access to this command, consider [**upgrading**](${client.config.website}/premium).`,
content: `This command is only for Coinz Plus or Pro subscribers. To gain access to this command, consider [**upgrading**](<${client.config.website}/premium>).`,
ephemeral: true,
});
return;
Expand Down Expand Up @@ -95,6 +103,7 @@ export default {
client.achievement.getById('no_life'),
);
} catch (error) {
logger.error(`Error while executing command '${command.data.name}':`);
logger.error((error as Error).stack ?? (error as Error).message);

const errorMsg = `There was an error while executing this command! Please try again.\nIf this keeps happening please join our [support server](<${client.config.supportServer}>).`;
Expand Down
4 changes: 2 additions & 2 deletions apps/bot/src/events/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default {
async execute(bot, client) {
logger.info(`Ready! Logged in as ${client.user.tag}`);

(async () => {
if (process.env.NODE_ENV === 'production') {
const conn = await amqplib.connect(process.env.QUEUE_URI!);

const ch1 = await conn.createChannel();
Expand Down Expand Up @@ -54,6 +54,6 @@ export default {
} catch {}
}
});
})();
}
},
} satisfies Event<Events.ClientReady>;
1 change: 0 additions & 1 deletion apps/bot/src/lib/shop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ export default class Shop {
{ label: 'Crops', value: 'crops' },
{ label: 'Animals', value: 'animals' },
{ label: 'Fish', value: 'fish' },
{ label: 'Factory Products', value: 'factory' },
{ label: 'Rare Items', value: 'rare_items' },
{ label: 'Other', value: 'other' },
{ label: 'All Items', value: 'all' },
Expand Down
1 change: 0 additions & 1 deletion apps/web/src/app/(main)/roadmap/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const roadmap: Roadmap[] = [
'Add /slots command.',
"Add notifications for when it's time to vote again or when you get robbed.",
'Add a business leaderboard of the top 50 businesses in certain categories.',
'Let Coinz Pro users invest up to 🪙 5.000 per day in their business',
],
},
{
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const metadata: Metadata = {
template: 'Coinz - %s',
default: 'Coinz',
},
description: 'A Discord bot with an economy system, stocks, crypto, poker, blackjack, roulette, and more!',
description: 'A Discord bot with an economy system, stocks, crypto, blackjack, roulette, and more!',
generator: 'Coinz',
applicationName: 'Coinz',
referrer: 'origin-when-cross-origin',
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default function manifest(): MetadataRoute.Manifest {
return {
name: 'Coinz',
short_name: 'Coinz',
description: '',
description: 'A Discord bot with an economy system, stocks, crypto, blackjack, roulette, and more!',
start_url: '/',
display: 'standalone',
background_color: '#26272f',
Expand Down
18 changes: 17 additions & 1 deletion apps/web/src/lib/data/changelog.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
[
{
"version": "4.0.1",
"name": "Stability Bug Fixes",
"timestamp": 1713772800,
"content": [
"#### Changed",
"- Let Coinz Pro users invest up to 🪙 10.000 in their business.",
"- Coinz Pro users can now pay up to 🪙 30.000 to other users instead of the previous 🪙 25.000.",
"- Fix an issue where all CEO's are removed from their businesses.",
"- Updated small typo's in messages.",
"- Added the ability for business employee's to leave the business.",
"#### Known Bugs",
"- No ability to upgrade your bank balance.",
"- Factory not working issue, we disabled some features to fix this issue."
]
},
{
"version": "4.0",
"name": "Premium & Quality of Life Update",
"timestamp": 1707382800,
"timestamp": 1713600000,
"content": [
"#### Premium",
"- We've decided to bring back the premium subscription in Coinz. We try to also keep it as fair as possible.",
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/lib/data/products.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"Earn double XP",
"Gamble cooldowns reduced from 10 to 4 minutes",
"Hire a 6th employee for your business",
"Donate someone up to 🪙 25.000 using /pay"
"Donate someone up to 🪙 30.000 using /pay",
"Invest up to 🪙 10.000 in your business"
],
"planId": 247787,
"variantId": 342288,
Expand Down

0 comments on commit e566693

Please sign in to comment.