|
|
|
@@ -4,7 +4,7 @@ require('dotenv').config()
|
|
|
|
|
|
|
|
|
|
function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
|
|
|
|
|
|
|
|
|
|
const ASSETS = './assets/Command_Nuts/'
|
|
|
|
|
const asset_path = './assets/Command_Nuts/'
|
|
|
|
|
|
|
|
|
|
async function nutsGive(interaction) {
|
|
|
|
|
async function tradeWindow(buttonID1, buttonID2) {
|
|
|
|
@@ -109,7 +109,7 @@ async function nutsCheck(interaction) {
|
|
|
|
|
|
|
|
|
|
await interaction.editReply({
|
|
|
|
|
embeds: [embed],
|
|
|
|
|
files: [`${ASSETS}nuts_main.png`]
|
|
|
|
|
files: [`${asset_path}nuts_main.png`]
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -158,15 +158,24 @@ async function nutsLeaderboard(interaction) {
|
|
|
|
|
await interaction.editReply({
|
|
|
|
|
embeds: [embed],
|
|
|
|
|
components: [row],
|
|
|
|
|
files: [`${ASSETS}nuts_main.png`]
|
|
|
|
|
files: [`${asset_path}nuts_main.png`]
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function nutsStats(interaction) {
|
|
|
|
|
const db = mClient.db(process.env.M_DB);
|
|
|
|
|
const nStatsColl = db.collection('stats_nuts');
|
|
|
|
|
var type = interaction?.options?.getString('type') || 'lookup'
|
|
|
|
|
var target = interaction?.options?.getUser('lookup') || {}
|
|
|
|
|
|
|
|
|
|
const statsDoc = await nStatsColl.findOne({ userID: interaction.user.id });
|
|
|
|
|
if(type == 'global') {
|
|
|
|
|
target.id = '__global'
|
|
|
|
|
} else if (!target?.id){
|
|
|
|
|
target = interaction.user
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(target)
|
|
|
|
|
const statsDoc = await nStatsColl.findOne({ userID: target.id });
|
|
|
|
|
const stat = statsDoc?.stat || {};
|
|
|
|
|
|
|
|
|
|
const totalCount = Object.values(stat).reduce((a, b) => a + b, 0);
|
|
|
|
@@ -198,7 +207,7 @@ async function nutsStats(interaction) {
|
|
|
|
|
|
|
|
|
|
const nutAvg = totalCount ? totalNuts / totalCount : 0;
|
|
|
|
|
|
|
|
|
|
const fields = Array.from({ length: 10 }, (_, i) => ({
|
|
|
|
|
const fields = Array.from({ length: 11 }, (_, i) => ({
|
|
|
|
|
name: `[${i}]`,
|
|
|
|
|
value: `x${stat[i] ?? 0}`,
|
|
|
|
|
inline: true
|
|
|
|
@@ -210,8 +219,8 @@ async function nutsStats(interaction) {
|
|
|
|
|
`Total Nut Actions: **${totalCount}**\r\n` +
|
|
|
|
|
`Total Nuts nutted: **${totalNuts}**\r\n` +
|
|
|
|
|
`Nut Average: **${nutAvg.toFixed(3)}**\r\n` +
|
|
|
|
|
`Best Nut: **${nutMax.number} (x${nutMax.count})**\r\n` +
|
|
|
|
|
`Worst Nut: **${nutMin.number} (x${nutMin.count})**`
|
|
|
|
|
`Most Common Nut: **${nutMax.number} (x${nutMax.count})**\r\n` +
|
|
|
|
|
`Least Common Nut: **${nutMin.number} (x${nutMin.count})**`
|
|
|
|
|
)
|
|
|
|
|
.addFields(fields)
|
|
|
|
|
.setColor(0x51267)
|
|
|
|
@@ -220,7 +229,7 @@ async function nutsStats(interaction) {
|
|
|
|
|
|
|
|
|
|
await interaction.editReply({
|
|
|
|
|
embeds: [embed],
|
|
|
|
|
files: [`${ASSETS}nuts_main.png`]
|
|
|
|
|
files: [`${asset_path}nuts_main.png`]
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -231,14 +240,14 @@ async function nutsCooldown(interaction) {
|
|
|
|
|
|
|
|
|
|
let content = `Du kannst wieder nussen! :)`
|
|
|
|
|
let thumbnail = 'attachment://nuts_main.png'
|
|
|
|
|
let file = `${ASSETS}nuts_main.png`
|
|
|
|
|
let file = `${asset_path}nuts_main.png`
|
|
|
|
|
let title = 'Go Nuts!'
|
|
|
|
|
|
|
|
|
|
let date = (Date.now() / 1000)
|
|
|
|
|
if (cooldown.cooldown > date) {
|
|
|
|
|
content = `<t:${cooldown.cooldown}:R> kannst du wieder nussen! ;)`
|
|
|
|
|
thumbnail = 'attachment://nuts_onCD.avif'
|
|
|
|
|
file = `${ASSETS}nuts_onCD.avif`
|
|
|
|
|
file = `${asset_path}nuts_onCD.avif`
|
|
|
|
|
title = 'To Nut or Not to Nut...'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -262,26 +271,58 @@ async function nutsNut(interaction, quickMode) {
|
|
|
|
|
const cdData = await cdColl.findOne({ userID: interaction.user.id })
|
|
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
|
|
|
|
|
|
const images = {
|
|
|
|
|
const assets = {
|
|
|
|
|
high: 'attachment://nuts_high.jpg',
|
|
|
|
|
normal: 'attachment://nuts_normal.jpg',
|
|
|
|
|
low: 'attachment://nuts_low.jpg',
|
|
|
|
|
none: 'attachment://nuts_none.avif',
|
|
|
|
|
onCD: 'attachment://nuts_onCD.avif'
|
|
|
|
|
onCD: 'attachment://nuts_onCD.avif',
|
|
|
|
|
box: 'attachment://nuts_box.png',
|
|
|
|
|
explosion: 'attachment://nuts_explosion.gif'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Helper for singular/plural
|
|
|
|
|
const formatNut = (amount) => `${amount} ${amount === 1 ? 'Nuss' : 'Nüsse'}`
|
|
|
|
|
|
|
|
|
|
// check cooldown
|
|
|
|
|
if (!cdData || cdData.cooldown < Date.now() / 1000) {
|
|
|
|
|
if (cdData || cdData?.cooldown > Date.now() / 1000) {
|
|
|
|
|
// on cooldown
|
|
|
|
|
embed.setTitle('To Nut or Not to Nut...')
|
|
|
|
|
embed.setDescription(`<t:${Math.floor(cdData.cooldown)}:R> kannst du wieder nussen! ;)`)
|
|
|
|
|
embed.setThumbnail(assets.onCD)
|
|
|
|
|
|
|
|
|
|
return interaction.editReply({
|
|
|
|
|
embeds: [embed],
|
|
|
|
|
files: [`${asset_path}nuts_onCD.avif`]
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
embed.setDescription('\u200B')
|
|
|
|
|
// pseudo animation
|
|
|
|
|
embed.setThumbnail(assets.box)
|
|
|
|
|
await interaction.editReply({
|
|
|
|
|
embeds: [embed],
|
|
|
|
|
files: [`${asset_path}nuts_box.png`]
|
|
|
|
|
})
|
|
|
|
|
await delay(1337)
|
|
|
|
|
embed.setThumbnail(assets.explosion)
|
|
|
|
|
await interaction.editReply({
|
|
|
|
|
embeds: [embed],
|
|
|
|
|
files: [`${asset_path}nuts_explosion.gif`]
|
|
|
|
|
})
|
|
|
|
|
await delay(1337)
|
|
|
|
|
|
|
|
|
|
// set 1 hour cooldown
|
|
|
|
|
const cd = Math.floor((Date.now() + 3600000) / 1000)
|
|
|
|
|
await cdColl.findOneAndUpdate(
|
|
|
|
|
{ userID: interaction.user.id },
|
|
|
|
|
{ $set: { cooldown: cd } },
|
|
|
|
|
{ upsert: true }
|
|
|
|
|
)
|
|
|
|
|
await cdColl.findOneAndUpdate({
|
|
|
|
|
userID: interaction.user.id
|
|
|
|
|
}, {
|
|
|
|
|
$set: {
|
|
|
|
|
cooldown: cd,
|
|
|
|
|
application: 'nuts'
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
upsert: true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// generate nut amount
|
|
|
|
|
const amount = Math.floor(Math.random() * 10)
|
|
|
|
@@ -299,14 +340,20 @@ async function nutsNut(interaction, quickMode) {
|
|
|
|
|
{ upsert: true }
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
let imageFile
|
|
|
|
|
if (amount === 0) imageFile = images.none
|
|
|
|
|
else if (amount > 8) imageFile = images.high
|
|
|
|
|
else if (amount > 4) imageFile = images.normal
|
|
|
|
|
else imageFile = images.low
|
|
|
|
|
await nutsStatsColl.findOneAndUpdate(
|
|
|
|
|
{ userID: "__global" },
|
|
|
|
|
{ $inc: { [`stat.${amount}`]: 1 } },
|
|
|
|
|
{ upsert: true }
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
let assetFile
|
|
|
|
|
if (amount === 0) assetFile = assets.none
|
|
|
|
|
else if (amount > 8) assetFile = assets.high
|
|
|
|
|
else if (amount > 4) assetFile = assets.normal
|
|
|
|
|
else assetFile = assets.low
|
|
|
|
|
|
|
|
|
|
embed.setTitle(`Du hast ${formatNut(amount)} bekommen!`)
|
|
|
|
|
embed.setThumbnail(imageFile)
|
|
|
|
|
embed.setThumbnail(assetFile)
|
|
|
|
|
|
|
|
|
|
if (quickMode) {
|
|
|
|
|
return interaction.editReply({ content: `Du hast ${formatNut(amount)} bekommen! :chestnut:` })
|
|
|
|
@@ -314,19 +361,8 @@ async function nutsNut(interaction, quickMode) {
|
|
|
|
|
|
|
|
|
|
return interaction.editReply({
|
|
|
|
|
embeds: [embed],
|
|
|
|
|
files: [`${ASSETS}${imageFile.split('://')[1]}`]
|
|
|
|
|
files: [`${asset_path}${assetFile.split('://')[1]}`]
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
// on cooldown
|
|
|
|
|
embed.setTitle('To Nut or Not to Nut...')
|
|
|
|
|
embed.setDescription(`<t:${Math.floor(cdData.cooldown)}:R> kannst du wieder nussen! ;)`)
|
|
|
|
|
embed.setThumbnail(images.onCD)
|
|
|
|
|
|
|
|
|
|
return interaction.editReply({
|
|
|
|
|
embeds: [embed],
|
|
|
|
|
files: [`${ASSETS}nuts_onCD.avif`]
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
module.exports = {
|
|
|
|
|
data: new SlashCommandBuilder()
|
|
|
|
@@ -350,7 +386,20 @@ module.exports = {
|
|
|
|
|
.addSubcommand(s =>
|
|
|
|
|
s
|
|
|
|
|
.setName('stats')
|
|
|
|
|
.setDescription('wie viele Nüsse wurden genusst, Genosse?'))
|
|
|
|
|
.setDescription('wie viele Nüsse wurden genusst, Genosse?')
|
|
|
|
|
.addStringOption(o =>
|
|
|
|
|
o.setName('type')
|
|
|
|
|
.setDescription('set type to global or user')
|
|
|
|
|
.addChoices(
|
|
|
|
|
{ name: 'global', value: 'global' },
|
|
|
|
|
{ name: 'user', value: 'user' }
|
|
|
|
|
),)
|
|
|
|
|
.addUserOption(o =>
|
|
|
|
|
o.setName('lookup')
|
|
|
|
|
.setDescription('look up specific user nut statistic')
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
.addSubcommand(s =>
|
|
|
|
|
s
|
|
|
|
|
.setName('cooldown')
|
|
|
|
|