Balance is broken but I added page functionality to the shop display. I also added the shop display

This commit is contained in:
ION606
2022-04-18 21:28:13 -04:00
parent 44f02a999e
commit e824977282
7 changed files with 161 additions and 8 deletions
+39 -3
View File
@@ -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(
Binary file not shown.
+112 -3
View File
@@ -22,9 +22,118 @@ const force = process.argv.includes('--force') || process.argv.includes('-f');
sequelize.sync({ force }).then(async () => {
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);
+2 -2
View File
@@ -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.`);
+4
View File
@@ -12,6 +12,10 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.STRING,
unique: true,
},
sect: {
type: DataTypes.STRING,
allowNull: true,
},
}, {
timestamps: false,
});
+4
View File
@@ -10,6 +10,10 @@ module.exports = (sequelize, DataTypes) => {
icon: {
type: DataTypes.STRING,
'default': '🤖',
},
sect: {
type: DataTypes.STRING,
'default': 'M',
}
}, {
timestamps: false,
BIN
View File
Binary file not shown.