twitch_bot/commands/megis.js

91 lines
1.9 KiB
JavaScript

const prisma = require("../clients/prisma");
const megisTypes = {
0: "bcaa megis PoroSad",
7: "lemon sugar free megis BroBalt",
15: "sugar free megis! PogChamp",
30: "normal megis!!! AngelThump",
};
const command = {
name: "megis",
desc: "economy command: get megis once per hour",
restricted: false,
mod: false,
run: async (client, msg) => {
const megis =
Object.keys(megisTypes)[
Math.floor(Math.random() * Object.keys(megisTypes).length)
];
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 (user) {
if (
new Date().getTime() <
new Date(user.megis.updatedAt).getTime() + 3600000
) {
await client.say(
msg.channelName,
`${
msg.displayName
}, remember kids, only one megis per hour! (on timeout ${Math.floor(
Math.abs(
new Date(user.megis.updatedAt).getTime() +
3600000 -
new Date().getTime()
) /
1000 /
60
)} minutes 🕒 ) `
);
return;
}
}
const updateUser = await prisma.user.update({
where: {
userId: msg.senderUserID,
},
data: {
megis: {
update: {
megis: {
increment: parseInt(megis),
},
},
},
},
include: {
megis: true,
},
});
await client.say(
msg.channelName,
`${msg.displayName}, +${megis}! ${megisTypes[megis]} Total megis: ${updateUser.megis.megis}`
);
},
};
module.exports = { command };