Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMonDon committed Sep 26, 2024
2 parents 707e8b9 + 5bc12e9 commit 7d35494
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 49 deletions.
19 changes: 9 additions & 10 deletions commands/Economy/blackjack.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,15 @@ class BlackJack extends Command {
const cash = cashValue === undefined ? startBalance : BigInt(cashValue);

const Arguments = args.join(' ').toLowerCase();
let bet;

if (Arguments === 'all') {
bet = parseInt(cash);
} else {
bet = parseInt(Arguments.replace(/[^0-9]/g, ''));
if (isNaN(bet)) return this.client.util.errorEmbed(msg, 'Bet amount must be a number', 'Invalid Bet');
if (bet < 1) return this.client.util.errorEmbed(msg, `You can't bet less than ${currencySymbol}1`, 'Invalid Bet');
if (BigInt(bet) > cash)
return this.client.util.errorEmbed(msg, "You can't bet more cash than you have", 'Invalid Bet');

const bet = parseInt(Arguments.replace(/[^0-9]/g, ''));
if (bet === Infinity) {
return this.client.util.errorEmbed(msg, "You can't bet infinity.", 'Invalid bet');
}
if (isNaN(bet)) return this.client.util.errorEmbed(msg, 'Bet amount must be a number', 'Invalid Bet');
if (bet < 1) return this.client.util.errorEmbed(msg, `You can't bet less than ${currencySymbol}1`, 'Invalid Bet');
if (BigInt(bet) > cash) {
return this.client.util.errorEmbed(msg, "You can't bet more cash than you have", 'Invalid Bet');
}

const bj = new Blackjack(bet, 1);
Expand Down
9 changes: 3 additions & 6 deletions commands/Economy/rob.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,11 @@ class Rob extends Command {
const authBank = BigInt((await db.get(`servers.${msg.guild.id}.users.${msg.member.id}.economy.bank`)) || 0);
const authNet = authCash + authBank;

const memCash = BigInt(
(await db.get(`servers.${msg.guild.id}.users.${mem.id}.economy.cash`)) ||
(await db.get(`servers.${msg.guild.id}.economy.startBalance`)) ||
0,
);
const memCash = BigInt((await db.get(`servers.${msg.guild.id}.users.${mem.id}.economy.cash`)) || 0);

if (memCash <= BigInt(0))
if (memCash <= BigInt(0)) {
return this.client.util.errorEmbed(msg, `${mem} does not have anything to rob`, 'No Money');
}

const minRate = 20;
const maxRate = 80;
Expand Down
92 changes: 66 additions & 26 deletions commands/Items/create-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CreateItem extends Command {
async run(msg, args) {
const name = args.join(' ').slice(0, 200);
const store = (await db.get(`servers.${msg.guild.id}.economy.store`)) || {};
const botMember = msg.guild.members.cache.get(this.client.user.id);
const filter = (m) => m.author.id === msg.author.id;
const embed = new EmbedBuilder()
.setAuthor({ name: msg.author.tag, iconURL: msg.author.displayAvatarURL() })
Expand Down Expand Up @@ -50,6 +51,7 @@ class CreateItem extends Command {
let cost;
let collected;
let isValid = false;
const messagesToDelete = [];

const message = await msg.channel.send({ content: '1️⃣ What would you like the price to be?', embeds: [embed] });

Expand Down Expand Up @@ -77,13 +79,22 @@ class CreateItem extends Command {
);

if (isNaN(cost)) {
await collected
.first()
.reply('The cost must be a valid number. Please enter the price again or type `cancel` to exit.');
const invalidCostMessage = await msg.channel.send(
'The cost must be a valid number. Please enter the price again or type `cancel` to exit.',
);
messagesToDelete.push(invalidCostMessage);
} else if (cost === Infinity) {
await collected.first().reply(`The price must be less than ${BigInt(Number.MAX_VALUE).toLocaleString()}.`);
const infinityMessage = await msg.channel.send(
`The price must be less than ${BigInt(
Number.MAX_VALUE,
).toLocaleString()}. Please enter the price again or type \`cancel\` to exit.`,
);
messagesToDelete.push(infinityMessage);
} else if (cost < 0) {
await msg.reply('The price must be at least zero. Please enter a valid cost.');
const negativeCostMessage = await msg.channel.send(
'The price must be at least zero. Please enter the price again or type `cancel` to exit.',
);
messagesToDelete.push(negativeCostMessage);
} else {
isValid = true;
}
Expand All @@ -93,13 +104,15 @@ class CreateItem extends Command {
const costString = currencySymbol + cost.toLocaleString();
const limitedCostString = costString.length > 1024 ? costString.slice(0, 1020) + '...' : costString;
embed.addFields([{ name: 'Price', value: limitedCostString, inline: true }]);

await message.edit({
content: '2️⃣ What would you like the description to be? \nThis should be no more than 1000 characters',
embeds: [embed],
});

isValid = false;
let description;
messagesToDelete.forEach((msg) => msg.delete().catch(() => {}));

while (!isValid) {
collected = await msg.channel
Expand All @@ -119,11 +132,10 @@ class CreateItem extends Command {

description = collected.first().content;
if (description.length > 1000) {
collected
.first()
.reply(
'The description must be less than 1000 characters. Please try again or use `cancel` to cancel the command',
);
const invalidDescriptionMessage = await msg.channel.send(
'The description must be less than 1000 characters. Please try again or use `cancel` to cancel the command',
);
messagesToDelete.push(invalidDescriptionMessage);
} else {
isValid = true;
}
Expand All @@ -137,6 +149,7 @@ class CreateItem extends Command {

isValid = false;
let inventory;
messagesToDelete.forEach((msg) => msg.delete().catch(() => {}));

while (!isValid) {
collected = await msg.channel
Expand All @@ -157,9 +170,10 @@ class CreateItem extends Command {
}

if (!this.client.util.no.includes(response) && !this.client.util.yes.includes(response)) {
await collected.first().reply('Please answer with either a `yes` or a `no`.');
const invalidAnswerMessage = await msg.channel.send('Please answer with either a `yes` or a `no`.');
messagesToDelete.push(invalidAnswerMessage);
} else {
if (['yes', 'y', 'true'].includes(response)) {
if (this.client.util.yes.includes(response)) {
inventory = true;
isValid = true;
} else {
Expand All @@ -177,6 +191,7 @@ class CreateItem extends Command {

isValid = false;
let stock;
messagesToDelete.forEach((msg) => msg.delete().catch(() => {}));

while (!isValid) {
collected = await msg.channel
Expand All @@ -203,9 +218,11 @@ class CreateItem extends Command {

stock = parseInt(response.replace(/[^0-9\\.]/g, ''));
if (isNaN(stock)) {
await collected.first().reply('Please answer with a number');
const noNumberMessage = await msg.channel.send('Please answer with a number');
messagesToDelete.push(noNumberMessage);
} else if (stock < 1) {
await collected.first().reply('Please enter a number larger than zero.');
const zeroStockMessage = await msg.channel.send('Please answer with a number larger than zero.');
messagesToDelete.push(zeroStockMessage);
} else {
isValid = true;
break;
Expand All @@ -223,6 +240,7 @@ class CreateItem extends Command {

isValid = false;
let roleRequired;
messagesToDelete.forEach((msg) => msg.delete().catch(() => {}));

while (!isValid) {
collected = await msg.channel
Expand Down Expand Up @@ -250,7 +268,10 @@ class CreateItem extends Command {
roleRequired = this.client.util.getRole(msg, collected.first().content);

if (!roleRequired) {
collected.first().reply('Please reply with a valid server role.');
const invalidRoleMessage = await msg.channel.send(
'Please reply with a valid server role. Try again or use `cancel` to cancel the command',
);
messagesToDelete.push(invalidRoleMessage);
} else {
roleRequired = roleRequired.id;
isValid = true;
Expand All @@ -259,7 +280,7 @@ class CreateItem extends Command {
embed.addFields([
{
name: 'Role Required',
value: roleRequired ? this.client.util.getRole(msg, roleRequired)?.toString() : 'None',
value: roleRequired ? this.client.util.getRole(msg, roleRequired).toString() : 'None',
inline: true,
},
]);
Expand All @@ -272,6 +293,7 @@ class CreateItem extends Command {

isValid = false;
let roleGiven;
messagesToDelete.forEach((msg) => msg.delete().catch(() => {}));

while (!isValid) {
collected = await msg.channel
Expand Down Expand Up @@ -299,7 +321,15 @@ class CreateItem extends Command {
roleGiven = this.client.util.getRole(msg, collected.first().content);

if (!roleGiven) {
collected.first().reply('Please reply with a valid server role.');
const invalidRoleMessage = await msg.channel.send(
'Please reply with a valid server role. Try again or use `cancel` to cancel the command',
);
messagesToDelete.push(invalidRoleMessage);
} else if (roleGiven.position >= botMember.roles.highest.position) {
const roleGivenGreaterMessage = await msg.channel.send(
"The role you mentioned is above or equal to the bot's highest role. Please try again with a different role or use `cancel` to cancel the command",
);
messagesToDelete.push(roleGivenGreaterMessage);
} else {
roleGiven = roleGiven.id;
isValid = true;
Expand All @@ -308,7 +338,7 @@ class CreateItem extends Command {
embed.addFields([
{
name: 'Role Given',
value: roleGiven ? this.client.util.getRole(msg, roleGiven)?.toString() : 'None',
value: roleGiven ? this.client.util.getRole(msg, roleGiven).toString() : 'None',
inline: true,
},
]);
Expand All @@ -321,6 +351,7 @@ class CreateItem extends Command {

isValid = false;
let roleRemoved;
messagesToDelete.forEach((msg) => msg.delete().catch(() => {}));

while (!isValid) {
collected = await msg.channel
Expand Down Expand Up @@ -348,7 +379,15 @@ class CreateItem extends Command {
roleRemoved = this.client.util.getRole(msg, collected.first().content);

if (!roleRemoved) {
collected.first().reply('Please reply with a valid server role.');
const invalidRoleMessage = await msg.channel.send(
'Please reply with a valid server role. Try again or use `cancel` to cancel the command',
);
messagesToDelete.push(invalidRoleMessage);
} else if (roleRemoved.position >= botMember.roles.highest.position) {
const roleRemovedGreaterMessage = await msg.channel.send(
"The role you mentioned is above or equal to the bot's highest role. Please try again with a different role or use `cancel` to cancel the command",
);
messagesToDelete.push(roleRemovedGreaterMessage);
} else {
roleRemoved = roleRemoved.id;
isValid = true;
Expand All @@ -357,19 +396,20 @@ class CreateItem extends Command {
embed.addFields([
{
name: 'Role Removed',
value: roleRemoved ? this.client.util.getRole(msg, roleRemoved)?.toString() : 'None',
value: roleRemoved ? this.client.util.getRole(msg, roleRemoved).toString() : 'None',
inline: true,
},
]);

await message.edit({
content:
'8️⃣ What message do you want the bot to reply with, when the item is bought (or used if an inventory item)? \nYou can use the Member, Server & Role tags from https://unbelievaboat.com/tags in this message. \nThis should be no more than 1000 characters \nIf none, just reply `skip`.',
'8️⃣ What message do you want the bot to reply with, when the item is bought (or used if an inventory item)? \nYou can use the Member, Server & Role tags from https://mythical.cisn.xyz/tags in this message. \nThis should be no more than 1000 characters \nIf none, just reply `skip`.',
embeds: [embed],
});

let replyMessage;
isValid = false;
messagesToDelete.forEach((msg) => msg.delete().catch(() => {}));

while (!isValid) {
collected = await msg.channel
Expand All @@ -391,16 +431,16 @@ class CreateItem extends Command {
if (replyMessage.toLowerCase() === 'skip') replyMessage = false;

if (replyMessage.length > 1000) {
collected
.first()
.reply(
'The reply-message must be less than 1000 characters. Please try again or use `cancel` to cancel the command',
);
const replyTooLongMessage = await msg.channel.send(
'The reply-message must be less than 1000 characters. Please try again or use `cancel` to cancel the command',
);
messagesToDelete.push(replyTooLongMessage);
} else {
isValid = true;
}
}
embed.addFields([{ name: 'Reply message', value: !replyMessage ? 'None' : replyMessage, inline: true }]);
messagesToDelete.forEach((msg) => msg.delete().catch(() => {}));

store[name] = {
cost,
Expand Down
7 changes: 7 additions & 0 deletions commands/Items/edit-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class EditItem extends Command {

async run(msg, args) {
const attribute = args.shift().toLowerCase();
const botMember = msg.guild.members.cache.get(this.client.user.id);
let itemName;
let newValue;
const errorEmbed = new EmbedBuilder()
Expand Down Expand Up @@ -158,6 +159,9 @@ class EditItem extends Command {
if (!role) {
errorEmbed.setDescription('Please re-run the command with a valid role.');
return msg.channel.send({ embeds: [errorEmbed] });
} else if (role.position >= botMember.roles.highest.position) {
errorEmbed.setDescription('I am not able to assign this role. Please move my role higher.');
return msg.channel.send({ embeds: [errorEmbed] });
}
item.roleGiven = role.id;
store[itemKey] = item;
Expand All @@ -174,6 +178,9 @@ class EditItem extends Command {
if (!role) {
errorEmbed.setDescription('Please re-run the command with a valid role.');
return msg.channel.send({ embeds: [errorEmbed] });
} else if (role.position >= botMember.roles.highest.position) {
errorEmbed.setDescription('I am not able to assign this role. Please move my role higher.');
return msg.channel.send({ embeds: [errorEmbed] });
}
item.roleRemoved = role.id;
store[itemKey] = item;
Expand Down
2 changes: 0 additions & 2 deletions events/Guild/guildDelete.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export async function run(client, guild) {

try {
client.user.setActivity(`${client.settings.get('default').prefix}help | ${client.guilds.cache.size} Servers`);
// Well they're gone. Let's remove them from the settings and log it!
client.settings.delete(guild.id);
client.logger.log(`Left guild: ${guild.name} (${guild.id}) with ${guild.memberCount} members`);
} catch (error) {
client.logger.error(`GuildDelete: ${error}`);
Expand Down
4 changes: 2 additions & 2 deletions slash_commands/Economy/crime.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ exports.run = async (interaction) => {

embed
.setColor(interaction.settings.embedErrorColor)
.setDescription(crimeFail[num].replace('csamount', csamount))
.setDescription(crimeFail[num].replace('{amount}', csamount))
.setFooter({ text: `Reply #${num.toLocaleString()}` });
interaction.editReply({ embeds: [embed] });

Expand All @@ -97,7 +97,7 @@ exports.run = async (interaction) => {

embed
.setColor(interaction.settings.embedSuccessColor)
.setDescription(crimeSuccess[num].replace('csamount', csamount))
.setDescription(crimeSuccess[num].replace('{amount}', csamount))
.setFooter({ text: `Reply #${num.toLocaleString()}` });
interaction.editReply({ embeds: [embed] });

Expand Down
4 changes: 2 additions & 2 deletions slash_commands/Economy/slut.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ exports.run = async (interaction) => {
if (ranNum < failRate) {
const csamount = currencySymbol + fineAmount.toLocaleString();
const num = Math.floor(Math.random() * (crimeFail.length - 1)) + 1;
const txt = crimeFail[num].replace('csamount', csamount);
const txt = crimeFail[num].replace('{amount}', csamount);

embed.setDescription(txt).setFooter({ text: `Reply #${num.toLocaleString()}` });
interaction.editReply({ embeds: [embed] });
Expand All @@ -92,7 +92,7 @@ exports.run = async (interaction) => {
const csamount = currencySymbol + amount.toLocaleString();

const num = Math.floor(Math.random() * (crimeSuccess.length - 1)) + 1;
const txt = crimeSuccess[num].replace('csamount', csamount);
const txt = crimeSuccess[num].replace('{amount}', csamount);

embed
.setDescription(txt)
Expand Down
2 changes: 1 addition & 1 deletion slash_commands/Economy/work.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ exports.run = async (interaction) => {
const jobs = require('../../resources/messages/work_jobs.json');

const num = Math.floor(Math.random() * (jobs.length - 1)) + 1;
const job = jobs[num].replace('csamount', csamount);
const job = jobs[num].replace('{amount}', csamount);

userCooldown.time = Date.now() + cooldown * 1000;
userCooldown.active = true;
Expand Down

0 comments on commit 7d35494

Please sign in to comment.