From e8249772824a9c67c95a283a71ee3ceef462e555 Mon Sep 17 00:00:00 2001 From: ION606 Date: Mon, 18 Apr 2022 21:28:13 -0400 Subject: [PATCH] Balance is broken but I added page functionality to the shop display. I also added the shop display --- commands/currency/app.js | 42 ++++++++- commands/currency/database.sqlite | Bin 32768 -> 0 bytes commands/currency/dbInit.js | 115 ++++++++++++++++++++++- commands/currency/dbObjects.js | 4 +- commands/currency/models/CurrencyShop.js | 4 + commands/currency/models/UserItems.js | 4 + database.sqlite | Bin 32768 -> 0 bytes 7 files changed, 161 insertions(+), 8 deletions(-) delete mode 100644 commands/currency/database.sqlite diff --git a/commands/currency/app.js b/commands/currency/app.js index 5d8fbce..18dab31 100644 --- a/commands/currency/app.js +++ b/commands/currency/app.js @@ -74,7 +74,7 @@ module.exports = { //Replace all instances of "command" with "commandName" //Replace "message.author;" with "interaction.options.getUser('user') || interaction.user;" const user = await Users.findOne({ where: { user_id: message.author.id } }); - if (!user) { currency.add(message.author.id, 0); } + // if (!user) { currency.add(message.author.id, 0); } if (command == 'reset') { @@ -104,8 +104,16 @@ module.exports = { } } } else if (command === 'balance') { + //BROKEN PLEASE FIX!!! const target = message.author; - return message.reply(`${target.tag} has \$${currency.getBalance(target.id)}`); + let user = currency.get(target.id); + + //let user = await Users.findOne({ where: { user_id: message.author.id } }); + if (!user) { + const newUser = await Users.create({ user_id: user, balance: 0 }); + currency.set(target.id, newUser); + } else { console.log(user); } + return message.reply(`${target.tag} has \$${currency.getBalance(target)}`); } else if (command === 'inventory') { const target = message.author; const user = await Users.findOne({ where: { user_id: target.id } }); @@ -173,7 +181,35 @@ module.exports = { }else if (command === 'shop') { const items = await CurrencyShop.findAll(); - return message.reply(Formatters.codeBlock(items.map(i => `${i.icon} (${i.name}): \$${i.cost}`).join('\n'))); + if (args.length == 0) { + let temp = Formatters.codeBlock(items.map(i => `${i.sect}`).join(' ')); + temp = [...new Set(temp.split(' '))]; + + return message.reply("Please use the format /shop [type] [page number]\nTypes are: " + temp); + } + + let ind = 1; + let noinp = false; + + if (args.length > 1) { + if (args[1] < (items.length / 9)) { + ind = Number(args[1]); + } else { + return message.reply("That number is too large"); + } + } else { + noinp = true; + } + + const items2 = items.slice((ind - 1)*10, (ind - 1)*10+10); + newText = Formatters.codeBlock(items2.map(i => `${i.icon} (${i.name}): \$${i.cost}`) + .filter(f => f.sect = args[0]).join('\n')); + + if (noinp) { + newText += "(Use /shop [type] [page number] to access other pages)"; + } + + return message.reply(newText); } else if (command === 'leaderboard') { return message.reply( Formatters.codeBlock( diff --git a/commands/currency/database.sqlite b/commands/currency/database.sqlite deleted file mode 100644 index b41e07e249c07d552e04735d225140641ca470c9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32768 zcmeI)K~EDw7zW^(9kxq}?HHS8Lr8SFv4NOw0V5$2YF)9R6sTJh;$gd#B{tGlx~c0x z)@${O)6mArWkM;L)igrLka+cr*GXa`(|1x3S9&UcUUrCFf0&H$pG1ksB)ZFY`HN^d z@*z4SibxQE00bZa0SG_<0uX=z1pd9i){LU4!^3oYuHme1xJ}Qk+hSEz@!Glmblyx^ zre>vXXHBixt|)3F#qwHF%j7I`&dh5|`OHEpzoN~XD_W{xEoO3}<${^B#!gy^n;)d| z>3gaCNOE#g7oYoM*{3=YA32p;v)X8Pn_INBTp^qF?=IDgXt4X+?N^tLJVuT`@*SQ4U1iQ8`j|D(;wQsc+3vMb&k>J>BZF z)U4MWlUO)zxsIrQJ0Rx7_&(wL{5${E3ll_) z5P$##AOHafKmY;|fB*y_009V`DbUa2)ZY+b18k5U?*xQcEG+f_j@JJNgdg$)aZDcx z0uX=z1Rwwb2tWV=5P$##AOL~h74UZe{L=tTVKFKW0Z0mqhyCaO{`r52epuTZAbj^6?B*Z-7@=l=&iH$4Ol0SG_< z0uX=z1Rwwb2tWV=5P(2XK&8x(#wTx1B$89(31iAI5;qbPQ{ { const shop = [ - CurrencyShop.upsert({ name: 'Tea', cost: 1, icon: '🍵' }), - CurrencyShop.upsert({ name: 'Coffee', cost: 2, icon: '☕' }), - CurrencyShop.upsert({ name: 'Cake', cost: 5, icon: '🍰' }), + CurrencyShop.upsert({ name: 'Grapes', cost: 2, icon: '🍇', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Melon', cost: 5, icon: '🍈', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Watermelon', cost: 5, icon: '🍉', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Tangerine', cost: 3, icon: '🍊', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Lemon', cost: 3, icon: '🍋', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Banana', cost: 4, icon: '🍌', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Pineapple', cost: 4, icon: '🍍', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Mango', cost: 3, icon: '🥭', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Red Apple', cost: 3, icon: '🍎', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Green Apple', cost: 3, icon: '🍏', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Pear', cost: 3, icon: '🍐', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Peach', cost: 3, icon: '🍑', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Cherries', cost: 4, icon: '🍒', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Strawberry', cost: 3, icon: '🍓', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Blueberries', cost: 3, icon: '🫐', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Kiwi', cost: 3, icon: '🥝', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Tomato', cost: 4, icon: '🍅', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Olive', cost: 4, icon: '🫒', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Coconut', cost: 3, icon: '🥥', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Avocado', cost: 3, icon: '🥑', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Eggplant', cost: 10, icon: '🍆', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Potato', cost: 3, icon: '🥔', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Carrot', cost: 3, icon: '🥕', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Ear of Corn', cost: 3, icon: '🌽', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Hot Pepper', cost: 3, icon: '🌶️', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Bell Pepper', cost: 3, icon: '🫑', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Cucumber', cost: 3, icon: '🥒', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Leafy Green', cost: 3, icon: '🥬', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Broccoli', cost: 2, icon: '🥦', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Garlic', cost: 3, icon: '🧄', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Onion', cost: 3, icon: '🧅', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Mushroom', cost: 3, icon: '🍄', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Peanuts', cost: 4, icon: '🥜', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Chestnut', cost: 3, icon: '🌰', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Bread', cost: 5, icon: '🍞', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Croissant', cost: 7, icon: '🥐', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Baguette Bread', cost: 10, icon: '🥖', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Flatbread', cost: 9, icon: '🫓', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Pretzel', cost: 5, icon: '🥨', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Bagel', cost: 4, icon: '🥯', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Pancakes', cost: 5, icon: '🥞', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Waffle', cost: 5, icon: '🧇', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Cheese Wedge', cost: 3, icon: '🧀', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Meat on the Bone', cost: 5, icon: '🍖', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Checken Leg', cost: 5, icon: '🍗', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Cut of Meat', cost: 4, icon: '🥩', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Bacon', cost: 4, icon: '🥓', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Hamburger', cost: 5, icon: '🍔', sect: 'Food' }), + CurrencyShop.upsert({ name: 'French Fries', cost: 3, icon: '🍟', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Pizza', cost: 6, icon: '🍕', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Hot Dog', cost: 3, icon: '🌭', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Sandwich', cost: 3, icon: '🥪', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Taco', cost: 3, icon: '🌮', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Burrito', cost: 5, icon: '🌯', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Tamale', cost: 5, icon: '🫔', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Stuffed Flatbread', cost: 5, icon: '🥙', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Falafel', cost: 4, icon: '🧆', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Egg', cost: 3, icon: '🥚', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Hot Pot', cost: 12, icon: '🍲', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Fondue', cost: 8, icon: '🫕', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Green Salad', cost: 3, icon: '🥗', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Popcorn', cost: 3, icon: '🍿', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Butter', cost: 2, icon: '🧈', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Salt', cost: 2, icon: '🧂', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Canned Food', cost: 3, icon: '🥫', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Bento Box', cost: 7, icon: '🍱', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Rice Cracker', cost: 1, icon: '🍘', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Rice Ball', cost: 3, icon: '🍙', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Cooked Rice', cost: 3, icon: '🍚', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Curry Rice', cost: 4, icon: '🍛', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Ramen', cost: 4, icon: '🍜', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Spaghetti', cost: 5, icon: '🍝', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Roasted Sweet Potato', cost: 3, icon: '🍠', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Oden', cost: 3, icon: '🍢', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Sushi', cost: 4, icon: '🍣', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Fried Shrimp', cost: 3, icon: '🍤', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Fish Cake', cost: 3, icon: '🍥', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Moon Cake', cost: 3, icon: '🥮', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Dango', cost: 3, icon: '🍡', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Dumpling', cost: 3, icon: '🥟', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Fortune Cookie', cost: 3, icon: '🥠', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Oyster', cost: 4, icon: '🦪', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Ice Cream Cone', cost: 3, icon: '🍦', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Shaved Ice', cost: 3, icon: '🍧', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Ice Cream', cost: 3, icon: '🍨', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Doughnut', cost: 3, icon: '🍩', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Cookie', cost: 3, icon: '🍪', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Birthday Cake', cost: 7, icon: '🎂', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Shortcake', cost: 4, icon: '🍰', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Cupcake', cost: 3, icon: '🧁', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Pie', cost: 4, icon: '🥧', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Chocolate Bar', cost: 2, icon: '🍫', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Candy', cost: 1, icon: '🍬', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Lollipop', cost: 1, icon: '🍭', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Custard', cost: 3, icon: '🍮', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Honey Pot', cost: 3, icon: '🍯', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Baby Bottle', cost: 3, icon: '🍼', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Glass of Milk', cost: 3, icon: '🥛', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Coffee', cost: 3, icon: '☕', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Teapot', cost: 3, icon: '🫖', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Tea', cost: 3, icon: '🍵', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Sake', cost: 3, icon: '🍶', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Champagne', cost: 3, icon: '🍾', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Wine Glass', cost: 3, icon: '🍷', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Cocktail Glass', cost: 3, icon: '🍸', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Tropical Drink', cost: 3, icon: '🍹', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Beer Mug', cost: 3, icon: '🍺', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Tumbler', cost: 3, icon: '🥃', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Soda', cost: 3, icon: '🥤', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Bubble Tea', cost: 3, icon: '🧋', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Beverage Box', cost: 30, icon: '🧃', sect: 'Food' }), + CurrencyShop.upsert({ name: 'Mate', cost: 3, icon: '🧉', sect: 'Food' }), ]; await Promise.all(shop); diff --git a/commands/currency/dbObjects.js b/commands/currency/dbObjects.js index 038492d..42146d2 100644 --- a/commands/currency/dbObjects.js +++ b/commands/currency/dbObjects.js @@ -22,7 +22,7 @@ Reflect.defineProperty(Users.prototype, 'addItem', { /* eslint-disable-next-line func-name-matching */ value: async function addItem(item, message, currency, numItems) { const userItem = await UserItems.findOne({ - where: { user_id: this.user_id, item_id: item.id }, + where: { user_id: this.user_id, item_id: item.id, sect: item.sect}, }); //Makes it so you can only buy as many items as you can afford @@ -38,7 +38,7 @@ Reflect.defineProperty(Users.prototype, 'addItem', { userItem.amount += numItemsFinal; userItem.save(); } else { - UserItems.create({ user_id: this.user_id, item_id: item.id, amount: numItemsFinal, icon: item.icon }); + UserItems.create({ user_id: this.user_id, item_id: item.id, amount: numItemsFinal, icon: item.icon, sect: item.sect }); } //console.log(numItemsFinal); return message.reply(`You bought ${numItemsFinal} ${item.icon} for \$${numItemsFinal * item.cost}. You have \$${currency.getBalance(message.author.id)} left.`); diff --git a/commands/currency/models/CurrencyShop.js b/commands/currency/models/CurrencyShop.js index 5fecc4e..05ad69b 100644 --- a/commands/currency/models/CurrencyShop.js +++ b/commands/currency/models/CurrencyShop.js @@ -12,6 +12,10 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.STRING, unique: true, }, + sect: { + type: DataTypes.STRING, + allowNull: true, + }, }, { timestamps: false, }); diff --git a/commands/currency/models/UserItems.js b/commands/currency/models/UserItems.js index a65923c..6530e37 100644 --- a/commands/currency/models/UserItems.js +++ b/commands/currency/models/UserItems.js @@ -10,6 +10,10 @@ module.exports = (sequelize, DataTypes) => { icon: { type: DataTypes.STRING, 'default': '🤖', + }, + sect: { + type: DataTypes.STRING, + 'default': 'M', } }, { timestamps: false, diff --git a/database.sqlite b/database.sqlite index cb3559993f875da4bb2e707f7d73bd8fa2c0d1aa..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 GIT binary patch literal 0 HcmV?d00001 literal 32768 zcmeI)K~EDw7zW^(4!cWB{n?EQQBYReNF zjb_bliAgd{C?)ek5F)dL49d?*Vlp#uQjlkQDt}&fm|T09j`1Hvizy_&%Xj&Ucs2Gu zJ|~Mv5P$##AOHafKmY;|fB*#ky}`VD0eTE#aOwzUKY86Z7oN~8trr=c`nvbb-`bP|aol#R(J4DY zFTP`TPTIcSrV+$@c;G?JFaBRGF4wT&hrb0>7>Ku zf!W9fDx2ZT!CbyGw~xsT;~xnB&iCXA2?7v+00bZa0SG_<0uX=z1Rwx`eh`Q=g(PV* z>pu3B!#6MA@`yr4Xd>I#*zml_r`NA8QH3O;N!xSf<#$7JOpNanzR$n$pZzdE#0UWh zKmY;|fB*y_009U<00Izzz#jz$S&{||0&Iwl(BqW=l_jEb4d7`0e?a&lKakt>ksts8 z2tWV=5P$##AOHafKmY;|=wE?g1t8cBz%-ViauYyAW65an{6E_;jYhk#s<=#hz9e2%0Cl%AVB~E5P$##AOHaf zKmY;|fB*y_(B}eIC^PBg^o^-hdS)_Z&X{KEdTMG$3HJX}{)NZ`2?7v+00bZa0SG_< z0uX=z1Rwx`z86R`GupcVaP<6tkMO;|A0P$*0SG_<0uX=z1Rwwb2tWV=5cq!uu2Pkl OG@9(4`m^AL0KWhm_DG@t