converted ShaiBot casino to Nut Economy
This commit is contained in:
+123
-56
@@ -1,64 +1,131 @@
|
||||
const { mClient } = require('../../../index')
|
||||
require('dotenv').config()
|
||||
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 = mClient.db(process.env.M_DB)
|
||||
const nutsColl = db.collection('items_nuts')
|
||||
const nutsStatsColl = db.collection('stats_nuts')
|
||||
const cdColl = db.collection('items_cooldowns')
|
||||
const cdData = await cdColl.findOne({ userID: message.author.id })
|
||||
name:
|
||||
"nuts",
|
||||
|
||||
if (cdData?.cooldown > (Date.now() / 1000)) {
|
||||
return await message.reply({
|
||||
content: `Du kannst erst <t:${Math.floor(cdData?.cooldown)}:R> wieder nussen :(`,
|
||||
})
|
||||
}
|
||||
description:
|
||||
"get nuts",
|
||||
|
||||
let cd = Math.floor((Date.now() + 3600000) / 1000)
|
||||
await cdColl.findOneAndUpdate({
|
||||
userID: message.author.id
|
||||
}, {
|
||||
$set: {
|
||||
cooldown: cd,
|
||||
application: 'nuts'
|
||||
}
|
||||
}, {
|
||||
upsert: true
|
||||
})
|
||||
aliases: [
|
||||
"n",
|
||||
"nget",
|
||||
"nutsget"
|
||||
],
|
||||
|
||||
const amount = Math.floor(Math.random() * 10)
|
||||
|
||||
await nutsColl.findOneAndUpdate({
|
||||
userID: message.author.id
|
||||
}, {
|
||||
$inc: { nuts: amount }
|
||||
}, {
|
||||
upsert: true
|
||||
})
|
||||
async execute(
|
||||
message,
|
||||
args
|
||||
) {
|
||||
const {
|
||||
db
|
||||
} =
|
||||
getCollections();
|
||||
|
||||
await nutsStatsColl.findOneAndUpdate(
|
||||
{ userID: message.author.id },
|
||||
{ $inc: { [`stat.${amount}`]: 1 } },
|
||||
{ upsert: true }
|
||||
)
|
||||
|
||||
await nutsStatsColl.findOneAndUpdate(
|
||||
{ userID: "__global" },
|
||||
{ $inc: { [`stat.${amount}`]: 1 } },
|
||||
{ upsert: true }
|
||||
)
|
||||
// Helper for singular/plural
|
||||
const formatNut = (amount) => `${amount === 1 ? 'eine' : amount} ${amount === 1 ? 'Nuss' : 'Nüsse'}`
|
||||
const nutsStatsColl =
|
||||
db.collection(
|
||||
"stats_nuts"
|
||||
);
|
||||
|
||||
let nutText = `Du hast ${formatNut(amount)} bekommen! :chestnut:`
|
||||
if (amount <= 0) {
|
||||
nutText = `Du hast keine Nuss bekommen! :yoink_help:`
|
||||
}
|
||||
return await message.reply({
|
||||
content: nutText
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user