Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Commit

Permalink
Update commands/shop.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Ray committed Nov 25, 2018
1 parent 22c58f5 commit 19b6b11
Showing 1 changed file with 67 additions and 31 deletions.
98 changes: 67 additions & 31 deletions commands/shop.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ exports.run = async (client, message, args) => {
const shopMessage = await message.channel.send(':gem: Garnet Shop :gem:');
const msg = await message.channel.send('Loading...');

const credits = client.credits.get(message.member.id);
const garnets = client.credits.get(message.member.id);
function isFloat(x) { return !!(x % 1); }

const credits = client.credits.get(`${message.guild.id}-${message.member.id}`, 'credits');
const garnets = client.garnets.get(message.member.id);

if (args[0] === 'exchange') {
if (args[1] === 'credits') {
const creditEmbed = new Discord.RichEmbed();
creditEmbed.setTitle('Credits => Garnets Exchange');
creditEmbed.setDescription('You cannot exchange more than 2200 credits (5 garnets) at one transaction.');
creditEmbed.setDescription('You cannot exchange more than 2200 credits (5 garnets) at one transaction.\n Credits are per server, garnets are global currency.');
creditEmbed.addField('1 Garnet', '500 credits; pass `1` to the exchange parameter for one garnet', true);
creditEmbed.addField('2 Garnets', '800 credits; pass `2` to the exchange parameter for two garnets.', true);
creditEmbed.addField('3 Garnets', '1400 credits; pass `3` to the exchange parameter for three garnets.', true);
Expand All @@ -22,42 +24,76 @@ exports.run = async (client, message, args) => {
creditEmbed.setTimestamp();
if (!args[2]) return msg.edit(creditEmbed);
const exchangeCredits = parseInt(args[2]);
if (exchangeCredits <= 0) return msg.edit('You can\'t transfer a negative or 0 amount.');
if (isNaN(exchangeCredits)) return msg.edit('Please enter an actual integer amount.');
if (exchangeCredits <= 0) {
shopMessage.delete();
return msg.edit('You can\'t transfer a negative or 0 amount.');
}
if (isNaN(exchangeCredits)) {
shopMessage.delete();
return msg.edit('Please enter an actual integer amount.');
}
if (isFloat(exchangeCredits)) {
shopMessage.delete();
return msg.edit('Please enter a non-decimal amount.');
}
//const exchangeRate = 500;
if (args[2] >= 6) return msg.edit('You cannot exchange more then 2200 credits, or 6 garnets at a time.');
if (exchangeCredits >= 6) {
shopMessage.delete();
return msg.edit('You cannot exchange more then 2200 credits, or 6 garnets at a time.');
}
try {
if (args[2] === 1) {
if (credits <= 499) return msg.edit('You do not have enough credits for this transaction, come back later broke ass.');
client.credits.math(message.member.id, 'sub', 500);
client.garnets.math(message.member.id, 'add', 1);
msg.edit(`Success! You've exchanged 500 credits and got one of my precious garnets in return. Isn't that lucky? | You now have ${Math.round(client.credits.get(message.member.id))} credits left.`);
if (exchangeCredits == 1) {
if (credits <= 499) return msg.edit('You do not have enough credits for this transaction, come back later broke ass.'); shopMessage.delete();
client.credits.math(`${message.guild.id}-${message.member.id}`, 'sub', 500, 'credits');
if (garnets === undefined) {
client.garnets.set(message.member.id, 1);
} else {
client.garnets.math(message.member.id, 'add', 1);
}
msg.edit(`Success! You've exchanged 500 credits and got one of my precious garnets in return. Isn't that lucky? | You now have ${Math.round(credits)} credits left.`);
}
else if (args[2] === 2) {
if (credits <= 799) return msg.edit('You do not have enough credits for this transaction, come back later broke ass.');
client.credits.math(message.member.id, 'sub', 800);
client.garnets.math(message.member.id, 'add', 2);
msg.edit(`Success! You've exchanged 800 credits and got two of my precious garnets in return. Isn't that lucky? | You now have ${Math.round(client.credits.get(message.member.id))} credits left.`);
else if (exchangeCredits == 2) {
if (credits <= 799) return msg.edit('You do not have enough credits for this transaction, come back later broke ass.'); shopMessage.delete();
client.credits.math(`${message.guild.id}-${message.member.id}`, 'sub', 800, 'credits');
if (garnets === undefined) {
client.garnets.set(message.member.id, 2);
} else {
client.garnets.math(message.member.id, 'add', 2);
}
msg.edit(`Success! You've exchanged 800 credits and got two of my precious garnets in return. Isn't that lucky? | You now have ${Math.round(credits)} credits left.`);
}
else if (args[2] === 3) {
if (credits <= 1399) return msg.edit('You do not have enough credits for this transaction, come back later broke ass.');
client.credits.math(message.member.id, 'sub', 1400);
client.garnets.math(message.member.id, 'add', 3);
msg.edit(`Success! You've exchanged 1400 credits and got three of my precious garnets in return. Isn't that lucky? | You now have ${Math.round(client.credits.get(message.member.id))} credits left.`);
else if (exchangeCredits == 3) {
if (credits <= 1399) return msg.edit('You do not have enough credits for this transaction, come back later broke ass.'); shopMessage.delete();
client.credits.math(`${message.guild.id}-${message.member.id}`, 'sub', 1400, 'credits');
if (garnets === undefined) {
client.garnets.set(message.member.id, 3);
} else {
client.garnets.math(message.member.id, 'add', 3);
}
msg.edit(`Success! You've exchanged 1400 credits and got three of my precious garnets in return. Isn't that lucky? | You now have ${Math.round(credits)} credits left.`);
}
else if (args[2] === 4) {
if (credits <= 1799) return msg.edit('You do not have enough credits for this transaction, come back later broke ass.');
client.credits.math(message.member.id, 'sub', 1800);
client.garnets.math(message.member.id, 'add', 4);
msg.edit(`Success! You've exchanged 1800 credits and got four of my precious garnets in return. Isn't that lucky? | You now have ${Math.round(client.credits.get(message.member.id))} credits left.`);
else if (exchangeCredits == 4) {
if (credits <= 1799) return msg.edit('You do not have enough credits for this transaction, come back later broke ass.'); shopMessage.delete();
client.credits.math(`${message.guild.id}-${message.member.id}`, 'sub', 1800, 'credits');
if (garnets === undefined) {
client.garnets.set(message.member.id, 4);
} else {
client.garnets.math(message.member.id, 'add', 4);
}
msg.edit(`Success! You've exchanged 1800 credits and got four of my precious garnets in return. Isn't that lucky? | You now have ${Math.round(credits)} credits left.`);
}
else if (args[2] === 5) {
if (credits <= 2199) return msg.edit('You do not have enough credits for this transaction, come back later broke ass.');
client.credits.math(message.member.id, 'sub', 2200);
client.garnets.math(message.member.id, 'add', 5);
msg.edit(`Success! You've exchanged 2200 credits and got four of my precious garnets in return. Isn't that lucky? | You now have ${Math.round(client.credits.get(message.member.id))} credits left.`);
else if (exchangeCredits == 5) {
if (credits <= 2199) return msg.edit('You do not have enough credits for this transaction, come back later broke ass.'); shopMessage.delete();
client.credits.math(`${message.guild.id}-${message.member.id}`, 'sub', 2200, 'credits');
if (garnets === undefined) {
client.garnets.set(message.member.id, 5);
} else {
client.garnets.math(message.member.id, 'add', 5);
}
msg.edit(`Success! You've exchanged 2200 credits and got four of my precious garnets in return. Isn't that lucky? | You now have ${Math.round(credits)} credits left.`);
}
else {
shopMessage.delete();
return msg.edit('This wasn\'t even a number I can recognize. Are you an idiot?');
}
} catch (err) {
Expand Down

0 comments on commit 19b6b11

Please sign in to comment.