2023-02-08 15:42:25 +01:00
|
|
|
const prisma = require("../clients/prisma");
|
2023-02-08 18:01:41 +01:00
|
|
|
const timeout = 1800000;
|
2023-02-08 15:42:25 +01:00
|
|
|
const megisTypes = {
|
|
|
|
0: "bcaa megis PoroSad",
|
|
|
|
7: "lemon sugar free megis BroBalt",
|
|
|
|
15: "sugar free megis! PogChamp",
|
|
|
|
30: "normal megis!!! AngelThump",
|
|
|
|
};
|
|
|
|
|
2023-02-09 12:32:12 +01:00
|
|
|
// 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
|
2023-02-08 15:42:25 +01:00
|
|
|
const command = {
|
|
|
|
name: "megis",
|
|
|
|
desc: "economy command: get megis once per hour",
|
|
|
|
restricted: false,
|
|
|
|
mod: false,
|
|
|
|
run: async (client, msg) => {
|
2023-02-08 16:59:41 +01:00
|
|
|
const user = await prisma.user.findUnique({
|
2023-02-08 15:42:25 +01:00
|
|
|
where: {
|
|
|
|
userId: msg.senderUserID,
|
|
|
|
},
|
2023-02-08 16:59:41 +01:00
|
|
|
include: {
|
|
|
|
megis: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
const createUser = await prisma.user.create({
|
|
|
|
data: {
|
|
|
|
userId: msg.senderUserID,
|
|
|
|
megis: {
|
|
|
|
create: {
|
|
|
|
megis: 0,
|
2023-02-08 15:42:25 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-02-08 16:59:41 +01:00
|
|
|
});
|
2023-02-08 19:59:55 +01:00
|
|
|
|
|
|
|
if (!createUser) {
|
|
|
|
await client.say(
|
|
|
|
msg.channelName,
|
|
|
|
`${msg.displayName}, something went wrong with adding you to the database`
|
|
|
|
);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2023-02-08 16:59:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (user) {
|
2023-02-08 18:39:43 +01:00
|
|
|
const timeMs = new Date().getTime();
|
|
|
|
const timeoutMs = new Date(user.megis.updatedAt).getTime() + timeout;
|
2023-02-08 18:01:41 +01:00
|
|
|
if (timeMs < timeoutMs) {
|
2023-02-08 16:59:41 +01:00
|
|
|
await client.say(
|
|
|
|
msg.channelName,
|
2023-02-08 18:39:43 +01:00
|
|
|
`${msg.displayName}, Two cans per day... (on timeout for ${Math.floor(
|
2023-02-08 18:01:41 +01:00
|
|
|
Math.abs(timeoutMs - timeMs) / 1000 / 60
|
2023-02-08 16:59:41 +01:00
|
|
|
)} minutes 🕒 ) `
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-08 19:59:55 +01:00
|
|
|
const megis =
|
|
|
|
Object.keys(megisTypes)[
|
|
|
|
Math.floor(Math.random() * Object.keys(megisTypes).length)
|
|
|
|
];
|
2023-02-08 16:59:41 +01:00
|
|
|
const updateUser = await prisma.user.update({
|
|
|
|
where: {
|
2023-02-08 15:42:25 +01:00
|
|
|
userId: msg.senderUserID,
|
2023-02-08 16:59:41 +01:00
|
|
|
},
|
|
|
|
data: {
|
2023-02-08 15:42:25 +01:00
|
|
|
megis: {
|
2023-02-08 16:59:41 +01:00
|
|
|
update: {
|
|
|
|
megis: {
|
|
|
|
increment: parseInt(megis),
|
|
|
|
},
|
2023-02-08 15:42:25 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
include: {
|
|
|
|
megis: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-02-08 19:59:55 +01:00
|
|
|
if (!updateUser) {
|
|
|
|
await client.say(
|
|
|
|
msg.channelName,
|
|
|
|
`${msg.displayName}, something went wrong`
|
|
|
|
);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-02-08 15:42:25 +01:00
|
|
|
await client.say(
|
|
|
|
msg.channelName,
|
2023-02-08 18:39:43 +01:00
|
|
|
`${msg.displayName}, +${megis} megis! ${megisTypes[megis]} Total megis: ${updateUser.megis.megis}`
|
2023-02-08 15:42:25 +01:00
|
|
|
);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = { command };
|