Spaces:
Runtime error
Runtime error
File size: 2,182 Bytes
272dfc6 64e57ec 272dfc6 64e57ec 272dfc6 55a57c5 272dfc6 64e57ec 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 55a57c5 272dfc6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | require('dotenv').config();
const mongoose = require('mongoose');
const { v4: uuidv4 } = require('uuid');
mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost:27017/discord-app', {
useNewUrlParser: true,
useUnifiedTopology: true
});
const shopItemSchema = new mongoose.Schema({
itemId: String,
name: String,
description: String,
price: Number,
category: String,
image: String,
createdAt: { type: Date, default: Date.now }
});
const ShopItem = mongoose.model('ShopItem', shopItemSchema);
const defaultItems = [
{
itemId: uuidv4(),
name: 'Discord Nitro Badge',
description: 'Show off your premium status',
price: 500,
category: 'badges'
},
{
itemId: uuidv4(),
name: 'Custom Profile Border',
description: 'Personalize your profile',
price: 300,
category: 'profile'
},
{
itemId: uuidv4(),
name: 'Custom Status',
description: 'Set a custom status message',
price: 200,
category: 'status'
},
{
itemId: uuidv4(),
name: 'Emote Pack',
description: 'Get exclusive emotes',
price: 250,
category: 'emotes'
},
{
itemId: uuidv4(),
name: 'Pink Theme',
description: 'UI theme customization',
price: 150,
category: 'themes'
},
{
itemId: uuidv4(),
name: 'Animated Avatar',
description: 'Use animated GIF as avatar',
price: 400,
category: 'avatar'
}
];
async function initializeDatabase() {
try {
await ShopItem.deleteMany({});
console.log('Cleared existing shop items');
await ShopItem.insertMany(defaultItems);
console.log(` Successfully added ${defaultItems.length} shop items to database`);
const items = await ShopItem.find();
console.log('\n Shop Items:');
items.forEach(item => {
console.log(` - ${item.name}: ${item.price} coins`);
});
mongoose.connection.close();
console.log('\n Database initialization complete!');
} catch (error) {
console.error(' Error initializing database:', error.message);
mongoose.connection.close();
process.exit(1);
}
}
console.log(' Initializing Discord-Like App Database...');
initializeDatabase();
|