131 lines
2.4 KiB
JavaScript
131 lines
2.4 KiB
JavaScript
const {
|
|
getCollections,
|
|
changeNuts,
|
|
claimCooldown,
|
|
randomInteger
|
|
} = require(
|
|
"../../../utils/nutEconomy"
|
|
);
|
|
|
|
|
|
module.exports = {
|
|
name:
|
|
"nuts",
|
|
|
|
description:
|
|
"get nuts",
|
|
|
|
aliases: [
|
|
"n",
|
|
"nget",
|
|
"nutsget"
|
|
],
|
|
|
|
|
|
async execute(
|
|
message,
|
|
args
|
|
) {
|
|
const {
|
|
db
|
|
} =
|
|
getCollections();
|
|
|
|
|
|
const nutsStatsColl =
|
|
db.collection(
|
|
"stats_nuts"
|
|
);
|
|
|
|
|
|
const cooldown =
|
|
await claimCooldown(
|
|
message.author.id,
|
|
"nut",
|
|
60 * 60
|
|
);
|
|
|
|
|
|
if (
|
|
!cooldown.claimed
|
|
) {
|
|
return message.reply({
|
|
content:
|
|
`Du kannst erst <t:${cooldown.next}:R> wieder nussen :(`
|
|
});
|
|
}
|
|
|
|
|
|
const amount =
|
|
randomInteger(
|
|
0,
|
|
9
|
|
);
|
|
|
|
|
|
await changeNuts(
|
|
message.author.id,
|
|
amount
|
|
);
|
|
|
|
|
|
await nutsStatsColl.findOneAndUpdate(
|
|
{
|
|
userId:
|
|
message.author.id
|
|
},
|
|
{
|
|
$inc: {
|
|
[`stat.${amount}`]:
|
|
1
|
|
}
|
|
},
|
|
{
|
|
upsert:
|
|
true
|
|
}
|
|
);
|
|
|
|
|
|
await nutsStatsColl.findOneAndUpdate(
|
|
{
|
|
userId:
|
|
"__global"
|
|
},
|
|
{
|
|
$inc: {
|
|
[`stat.${amount}`]:
|
|
1
|
|
}
|
|
},
|
|
{
|
|
upsert:
|
|
true
|
|
}
|
|
);
|
|
|
|
|
|
const formatNut =
|
|
amount =>
|
|
`${amount === 1 ? "eine" : amount} ${amount === 1 ? "Nuss" : "Nüsse"}`;
|
|
|
|
|
|
let nutText =
|
|
`Du hast ${formatNut(amount)} bekommen! :chestnut:`;
|
|
|
|
|
|
if (
|
|
amount <=
|
|
0
|
|
) {
|
|
nutText =
|
|
"Du hast keine Nuss bekommen! :yoink_help:";
|
|
}
|
|
|
|
|
|
return message.reply({
|
|
content:
|
|
nutText
|
|
});
|
|
}
|
|
}; |