const prisma = require("../clients/prisma"); const timeout = 1800000; const megisTypes = { 0: "bcaa megis PoroSad", 7: "lemon sugar free megis BroBalt", 15: "sugar free megis! PogChamp", 30: "normal megis!!! AngelThump", }; // this command does things that should be done seperately, // probably will extract adding the user to the database to // another command when i start doing another command that also needs that functionality const command = { name: "megis", desc: "economy command: get megis once per hour", restricted: false, mod: false, run: async (client, msg) => { const user = await prisma.user.findUnique({ where: { userId: msg.senderUserID, }, include: { megis: true, }, }); if (!user) { const createUser = await prisma.user.create({ data: { userId: msg.senderUserID, megis: { create: { megis: 0, }, }, }, }); if (!createUser) { await client.say( msg.channelName, `${msg.displayName}, something went wrong with adding you to the database` ); return; } } if (user) { const timeMs = new Date().getTime(); const timeoutMs = new Date(user.megis.updatedAt).getTime() + timeout; if (timeMs < timeoutMs) { await client.say( msg.channelName, `${msg.displayName}, Two cans per day... (on timeout for ${Math.floor( Math.abs(timeoutMs - timeMs) / 1000 / 60 )} minutes 🕒 ) ` ); return; } } const megis = Object.keys(megisTypes)[ Math.floor(Math.random() * Object.keys(megisTypes).length) ]; const updateUser = await prisma.user.update({ where: { userId: msg.senderUserID, }, data: { megis: { update: { megis: { increment: parseInt(megis), }, }, }, }, include: { megis: true, }, }); if (!updateUser) { await client.say( msg.channelName, `${msg.displayName}, something went wrong` ); return; } await client.say( msg.channelName, `${msg.displayName}, +${megis} megis! ${megisTypes[megis]} Total megis: ${updateUser.megis.megis}` ); }, }; module.exports = { command };