-
Notifications
You must be signed in to change notification settings - Fork 1
Flesh coin dev #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Flesh coin dev #17
Conversation
|
You gotta clarify what the fuck this is |
|
+420 −11 😏 |
|
No changes to base functionality. Added !post, !market, and !market rules |
|
also how does your CI work, seems like it just always fails npm |
It doesn't yet. I think we need to add a test file which exercises certain functionality. You're welcome to take a crack at it. |
Does this mean you can only buy and sell with other people? |
| message.author.send('Your posting:\n' + id.padStart(18,'0') + '\tS ' + String(market[1][id].quantity).padStart(10,' ') + '\t@' + String(market[1][id].price).padStart(8,' ') + '\n'); | ||
| return; | ||
| } | ||
| response += ', is looking to unload some meat, get it while it\'s hot'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this lmao
response += ', is looking to unload some meat, get it while it's hot';
index.js
Outdated
| // history not sure if we want this in history here, probably in processMarket().... | ||
| // if (userData.history.length > 9) | ||
| // userData.history.pop(); | ||
| // userData.history.unshift('b' + ',' + amount.toFixed(2) + ',' + price.toFixed(2)); | ||
|
|
||
| // statistics | ||
| //volume.bought += amount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if want to remove?
index.js
Outdated
| // history not sure if we want this in history here, probably in processMarket().... | ||
| // if (userData.history.length > 9) | ||
| // userData.history.pop(); | ||
| // userData.history.unshift('b' + ',' + amount.toFixed(2) + ',' + price.toFixed(2)); | ||
|
|
||
| // statistics | ||
| //volume.bought += amount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if want to remove?
|
Need to change DMs to users to use name instead of ID or just remove altogether |
|
fix name padding - moot if we make anon |
|
|
|
Need to handle when two posts match 2:1 buyer:seller or vice versa, currently causes crash |
| data/token.txt | ||
| #keep price local |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a space.
| } | ||
| market[0]=buyerData; | ||
| market[1]=sellerData; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove newline.
| function printMarket(message) { | ||
| var response = '```glsl\nGET YER FLESH HERE!\n'; | ||
| if (Object.keys(market[1]).length > 0) { | ||
| response += 'SELLERS'.padEnd(18,'-') + '+' + 'QUANTITY'.padStart(20,'-') + '+' + 'PRICE'.padStart(14,'-') + '+\n'; | ||
| Object.keys(market[1]).forEach(function(key) { | ||
| response += market[1][key].username.padEnd(18,' ') + '|' + String(market[1][key].quantity).padStart(20,' ') + '|' + String(market[1][key].price).padStart(14,' ') + '|\n'; | ||
| }); | ||
| } | ||
| if (Object.keys(market[0]).length > 0) { | ||
| response += 'BUYERS'.padEnd(18,'-') + '+' + 'QUANTITY'.padStart(20,'-') + '+' + 'PRICE'.padStart(14,'-') + '+\n'; | ||
| Object.keys(market[0]).forEach(function(key) { | ||
| response += market[0][key].username.padEnd(18,' ') + '|' + String(market[0][key].quantity).padStart(20,' ') + '|' + String(market[0][key].price).padStart(14,' ') + '|\n'; | ||
| }); | ||
| } | ||
| response += '```'; | ||
| message.channel.send(response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NO TABS????????????
| function post(message, command, price, coinage){ | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a space before { and remove the newline.
| return; | ||
| } | ||
| //check that the user is not already buying | ||
| if (id in market[0]){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space before {
| else if (command == 'adjust'){ | ||
| //adjusting a buy | ||
| if (id in market[0]){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space before {
| //adjusting a buy | ||
| if (id in market[0]){ | ||
| //remvoing post | ||
| if (amount <= 0.0 || floatPrice <= 0.0){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure there is a space before every {. I'll stop making this comment.
|
|
||
| } | ||
| else{ | ||
| response += ', ' + command + ' is not a valid command. ya dingus!'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙇
| var buyers = market[0]; | ||
| var sellers = market[1]; | ||
| //iterate through buyers | ||
| if (Object.keys(buyers).length > 0) { | ||
| Object.keys(buyers).forEach(function(Bkey) { | ||
| //iterate through sellers | ||
| if (Object.keys(sellers).length > 0) { | ||
| Object.keys(sellers).forEach(function(Skey) { | ||
| // check if we can make a deal | ||
| if(buyers[Bkey].price >= sellers[Skey].price){ //price match | ||
| var negPrice = buyers[Bkey].price; //probably won't happen too much, but good to be safe, buyers lose | ||
| //Buying > Selling | ||
| if(buyers[Bkey].quantity > sellers[Skey].quantity){ | ||
| var buyerData = ledger[Bkey]; | ||
| var sellerData = ledger[Skey]; | ||
| //credit both parties as they have already paid | ||
| buyerData.meatCoin += parseFloat(sellers[Skey].quantity); | ||
| volume.bought += parseFloat(sellers[Skey].quantity); | ||
| sellerData.gold += sellers[Skey].quantity * negPrice; | ||
| if (buyerData.history.length > 9) | ||
| buyerData.history.pop(); | ||
| buyerData.history.unshift('b' + ',' + parseFloat(sellers[Skey].quantity).toFixed(2) + ',' + negPrice.toFixed(2)); | ||
| if (sellerData.history.length > 9) | ||
| sellerData.history.pop(); | ||
| sellerData.history.unshift('s' + ',' + parseFloat(sellers[Skey].quantity).toFixed(2) + ',' + negPrice.toFixed(2)); | ||
| //decrease buyer quantity by amount sold, remove seller posting | ||
| buyers[Bkey].quantity -= sellers[Skey].quantity; | ||
| delete sellers[Skey]; | ||
| } | ||
| //Selling > Buying | ||
| else if (sellers[Skey].quantity > buyers[Bkey].quantity){ | ||
| var buyerData = ledger[Bkey]; | ||
| var sellerData = ledger[Skey]; | ||
| //credit both parties as they have already paid | ||
| buyerData.meatCoin += parseFloat(buyers[Bkey].quantity); | ||
| volume.bought += parseFloat(buyers[Bkey].quantity); | ||
| sellerData.gold += buyers[Bkey].quantity * negPrice; | ||
| if (buyerData.history.length > 9) | ||
| buyerData.history.pop(); | ||
| buyerData.history.unshift('b' + ',' + parseFloat(buyers[Bkey].quantity).toFixed(2) + ',' + negPrice.toFixed(2)); | ||
| if (sellerData.history.length > 9) | ||
| sellerData.history.pop(); | ||
| sellerData.history.unshift('s' + ',' + parseFloat(buyers[Bkey].quantity).toFixed(2) + ',' + negPrice.toFixed(2)); | ||
| //decrease seller quantity by amount sold, remove buyer posting | ||
| sellers[Skey].quantity -= buyers[Bkey].quantity; | ||
| delete buyers[Bkey]; | ||
| } | ||
| //equal | ||
| else{ | ||
| var buyerData = ledger[Bkey]; | ||
| var sellerData = ledger[Skey]; | ||
| //credit both parties as they have already paid | ||
| buyerData.meatCoin += parseFloat(buyers[Bkey].quantity); | ||
| volume.bought += parseFloat(buyers[Bkey].quantity); | ||
| sellerData.gold += buyers[Bkey].quantity * negPrice; | ||
| if (buyerData.history.length > 9) | ||
| buyerData.history.pop(); | ||
| buyerData.history.unshift('b' + ',' + parseFloat(buyers[Bkey].quantity).toFixed(2) + ',' + negPrice.toFixed(2)); | ||
| if (sellerData.history.length > 9) | ||
| sellerData.history.pop(); | ||
| sellerData.history.unshift('s' + ',' + parseFloat(buyers[Bkey].quantity).toFixed(2) + ',' + negPrice.toFixed(2)); | ||
| //decrease seller quantity by amount sold, remove buyer posting | ||
| delete sellers[Skey]; | ||
| delete buyers[Bkey]; | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to space out the code. Put a newline before all the comments (thank you for having comments) and some of the if statements.
| var sellers = market[1]; | ||
| //iterate through buyers | ||
| if (Object.keys(buyers).length > 0) { | ||
| Object.keys(buyers).forEach(function(Bkey) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we doing list iterations here? Can we perhaps use a hash map instead? To find matching buy/sells.
the meatMarket is open babyyy