Added Local Nut Assets, Restructured Nut Handler
|
Before Width: | Height: | Size: 254 KiB After Width: | Height: | Size: 254 KiB |
|
After Width: | Height: | Size: 176 KiB |
|
After Width: | Height: | Size: 167 KiB |
|
After Width: | Height: | Size: 158 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 11 KiB |
@@ -1,7 +1,11 @@
|
|||||||
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, MessageFlags } = require('discord.js')
|
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, MessageFlags, AttachmentBuilder } = require('discord.js')
|
||||||
const { mClient } = require('../../../index')
|
const { mClient } = require('../../../index')
|
||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
|
|
||||||
function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
|
function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
|
||||||
|
|
||||||
|
const ASSETS = './assets/Command_Nuts/'
|
||||||
|
|
||||||
async function nutsGive(interaction) {
|
async function nutsGive(interaction) {
|
||||||
async function tradeWindow(buttonID1, buttonID2) {
|
async function tradeWindow(buttonID1, buttonID2) {
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
@@ -14,7 +18,8 @@ async function nutsGive(interaction) {
|
|||||||
{ name: `Their Current Balance`, value: `${theirBalance.nuts} (**+${amount}**)`, inline: true },
|
{ name: `Their Current Balance`, value: `${theirBalance.nuts} (**+${amount}**)`, inline: true },
|
||||||
{ name: `Their New Balance`, value: `${theirBalance.nuts + amount}`, inline: true }
|
{ name: `Their New Balance`, value: `${theirBalance.nuts + amount}`, inline: true }
|
||||||
)
|
)
|
||||||
.setThumbnail(to.displayAvatarURL())
|
.setThumbnail('attachment://nuts_main.png')
|
||||||
|
|
||||||
const row = new ActionRowBuilder()
|
const row = new ActionRowBuilder()
|
||||||
.addComponents(
|
.addComponents(
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
@@ -28,12 +33,14 @@ async function nutsGive(interaction) {
|
|||||||
.setCustomId(buttonID2)
|
.setCustomId(buttonID2)
|
||||||
.setStyle(ButtonStyle.Danger)
|
.setStyle(ButtonStyle.Danger)
|
||||||
)
|
)
|
||||||
|
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
embeds: [embed],
|
embeds: [embed],
|
||||||
components: [row],
|
components: [row],
|
||||||
flags: MessageFlags.Ephemeral
|
flags: MessageFlags.Ephemeral
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const from = interaction.user
|
const from = interaction.user
|
||||||
const to = await interaction.options.getUser('target')
|
const to = await interaction.options.getUser('target')
|
||||||
var amount = await interaction.options.getNumber('amount')
|
var amount = await interaction.options.getNumber('amount')
|
||||||
@@ -42,21 +49,26 @@ async function nutsGive(interaction) {
|
|||||||
const nutsColl = db.collection('items_nuts')
|
const nutsColl = db.collection('items_nuts')
|
||||||
const yourBalance = await nutsColl.findOne({ userID: from.id })
|
const yourBalance = await nutsColl.findOne({ userID: from.id })
|
||||||
const theirBalance = await nutsColl.findOne({ userID: to.id })
|
const theirBalance = await nutsColl.findOne({ userID: to.id })
|
||||||
|
|
||||||
if (amount <= 0) {
|
if (amount <= 0) {
|
||||||
amount = yourBalance.nuts
|
amount = yourBalance.nuts
|
||||||
return tradeWindow('nuts_give_fake', 'abort')
|
return tradeWindow('nuts_give_fake', 'abort')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (yourBalance.nuts < amount) {
|
if (yourBalance.nuts < amount) {
|
||||||
return await interaction.reply({
|
return await interaction.reply({
|
||||||
content: 'Du kannst nicht mehr geben als du hast!',
|
content: 'Du kannst nicht mehr geben als du hast!',
|
||||||
flags: MessageFlags.Ephemeral
|
flags: MessageFlags.Ephemeral
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return tradeWindow('nuts_give_confirm', 'abort')
|
return tradeWindow('nuts_give_confirm', 'abort')
|
||||||
}
|
}
|
||||||
|
|
||||||
async function nutsCheck(interaction) {
|
async function nutsCheck(interaction) {
|
||||||
let target = interaction.options.getUser('target')
|
let target = interaction.options.getUser('target')
|
||||||
let addressing
|
let addressing
|
||||||
|
|
||||||
if (!target) {
|
if (!target) {
|
||||||
target = interaction.user
|
target = interaction.user
|
||||||
addressing = `Du hast`
|
addressing = `Du hast`
|
||||||
@@ -81,6 +93,7 @@ async function nutsCheck(interaction) {
|
|||||||
|
|
||||||
let title = 'Zähle Nüsse'
|
let title = 'Zähle Nüsse'
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
|
|
||||||
for (let i = 0; i < 4; i++) {
|
for (let i = 0; i < 4; i++) {
|
||||||
embed.setTitle(title)
|
embed.setTitle(title)
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
@@ -89,14 +102,17 @@ async function nutsCheck(interaction) {
|
|||||||
title = title + ' .'
|
title = title + ' .'
|
||||||
await delay(500);
|
await delay(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
embed
|
embed
|
||||||
.setTitle(content)
|
.setTitle(content)
|
||||||
.setThumbnail('https://cdn-icons-png.flaticon.com/512/628/628206.png')
|
.setThumbnail('attachment://nuts_main.png')
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [embed]
|
embeds: [embed],
|
||||||
|
files: [`${ASSETS}nuts_main.png`]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function nutsLeaderboard(interaction) {
|
async function nutsLeaderboard(interaction) {
|
||||||
const row = new ActionRowBuilder()
|
const row = new ActionRowBuilder()
|
||||||
.addComponents(
|
.addComponents(
|
||||||
@@ -117,35 +133,42 @@ async function nutsLeaderboard(interaction) {
|
|||||||
.setStyle(ButtonStyle.Primary)
|
.setStyle(ButtonStyle.Primary)
|
||||||
.setCustomId('nuts_leaderboard_right')
|
.setCustomId('nuts_leaderboard_right')
|
||||||
)
|
)
|
||||||
|
|
||||||
const db = mClient.db(process.env.M_DB)
|
const db = mClient.db(process.env.M_DB)
|
||||||
const nutsColl = db.collection('items_nuts')
|
const nutsColl = db.collection('items_nuts')
|
||||||
let skip = 0
|
let skip = 0
|
||||||
|
|
||||||
const nutsData = await nutsColl.find({ nuts: { $gt: 0 } }).sort({ nuts: -1 }).skip(skip).limit(5).toArray()
|
const nutsData = await nutsColl.find({ nuts: { $gt: 0 } }).sort({ nuts: -1 }).skip(skip).limit(5).toArray()
|
||||||
|
|
||||||
let fields
|
let fields
|
||||||
let placements = skip + 1
|
let placements = skip + 1
|
||||||
|
|
||||||
nutsData.forEach((data) => {
|
nutsData.forEach((data) => {
|
||||||
fields = (fields ? fields : '') + (`${placements}. <@${data.userID}> : ${data.nuts} Nuts\r\n`)
|
fields = (fields ? fields : '') + (`${placements}. <@${data.userID}> : ${data.nuts} Nuts\r\n`)
|
||||||
|
placements++
|
||||||
})
|
})
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle('Nuts Leaderboard')
|
.setTitle('Nuts Leaderboard')
|
||||||
.setThumbnail(interaction.guild.iconURL({ dynamic: true }))
|
.setThumbnail('attachment://nuts_main.png')
|
||||||
.setDescription(fields.toString())
|
.setDescription(fields.toString())
|
||||||
.setColor('#5865F2') // Discord's blurple color
|
.setColor('#5865F2')
|
||||||
.setFooter({ text: 'Use ◄ ► to navigate' });
|
.setFooter({ text: 'Use ◄ ► to navigate' })
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [embed],
|
embeds: [embed],
|
||||||
components: [row]
|
components: [row],
|
||||||
|
files: [`${ASSETS}nuts_main.png`]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function nutsStats(interaction) {
|
async function nutsStats(interaction) {
|
||||||
const db = mClient.db(process.env.M_DB);
|
const db = mClient.db(process.env.M_DB);
|
||||||
const nStatsColl = db.collection('stats_nuts');
|
const nStatsColl = db.collection('stats_nuts');
|
||||||
|
|
||||||
// fetch user stats
|
|
||||||
const statsDoc = await nStatsColl.findOne({ userID: interaction.user.id });
|
const statsDoc = await nStatsColl.findOne({ userID: interaction.user.id });
|
||||||
const stat = statsDoc?.stat || {}; // fallback to empty object
|
const stat = statsDoc?.stat || {};
|
||||||
|
|
||||||
// compute totals
|
|
||||||
const totalCount = Object.values(stat).reduce((a, b) => a + b, 0);
|
const totalCount = Object.values(stat).reduce((a, b) => a + b, 0);
|
||||||
const totalNuts = Object.entries(stat).reduce(
|
const totalNuts = Object.entries(stat).reduce(
|
||||||
(sum, [num, count]) => sum + Number(num) * count,
|
(sum, [num, count]) => sum + Number(num) * count,
|
||||||
@@ -158,18 +181,15 @@ async function nutsStats(interaction) {
|
|||||||
let nutMax = { number: 0, count: 0 };
|
let nutMax = { number: 0, count: 0 };
|
||||||
|
|
||||||
if (rolledNumbers.length > 0) {
|
if (rolledNumbers.length > 0) {
|
||||||
// initialize to first rolled number
|
|
||||||
nutMin = nutMax = { number: Number(rolledNumbers[0][0]), count: rolledNumbers[0][1] };
|
nutMin = nutMax = { number: Number(rolledNumbers[0][0]), count: rolledNumbers[0][1] };
|
||||||
|
|
||||||
for (const [numStr, count] of rolledNumbers) {
|
for (const [numStr, count] of rolledNumbers) {
|
||||||
const num = Number(numStr);
|
const num = Number(numStr);
|
||||||
|
|
||||||
// best nut: prefer higher number if counts tie
|
|
||||||
if (count > nutMax.count || (count === nutMax.count && num > nutMax.number)) {
|
if (count > nutMax.count || (count === nutMax.count && num > nutMax.number)) {
|
||||||
nutMax = { number: num, count };
|
nutMax = { number: num, count };
|
||||||
}
|
}
|
||||||
|
|
||||||
// worst nut: prefer lower number if counts tie
|
|
||||||
if (count < nutMin.count || (count === nutMin.count && num < nutMin.number)) {
|
if (count < nutMin.count || (count === nutMin.count && num < nutMin.number)) {
|
||||||
nutMin = { number: num, count };
|
nutMin = { number: num, count };
|
||||||
}
|
}
|
||||||
@@ -178,7 +198,6 @@ async function nutsStats(interaction) {
|
|||||||
|
|
||||||
const nutAvg = totalCount ? totalNuts / totalCount : 0;
|
const nutAvg = totalCount ? totalNuts / totalCount : 0;
|
||||||
|
|
||||||
// dynamically create fields for numbers 0-9
|
|
||||||
const fields = Array.from({ length: 10 }, (_, i) => ({
|
const fields = Array.from({ length: 10 }, (_, i) => ({
|
||||||
name: `[${i}]`,
|
name: `[${i}]`,
|
||||||
value: `x${stat[i] ?? 0}`,
|
value: `x${stat[i] ?? 0}`,
|
||||||
@@ -197,9 +216,12 @@ async function nutsStats(interaction) {
|
|||||||
.addFields(fields)
|
.addFields(fields)
|
||||||
.setColor(0x51267)
|
.setColor(0x51267)
|
||||||
.setTimestamp()
|
.setTimestamp()
|
||||||
.setThumbnail(interaction.guild.iconURL());
|
.setThumbnail('attachment://nuts_main.png')
|
||||||
|
|
||||||
await interaction.editReply({ embeds: [embed] });
|
await interaction.editReply({
|
||||||
|
embeds: [embed],
|
||||||
|
files: [`${ASSETS}nuts_main.png`]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function nutsCooldown(interaction) {
|
async function nutsCooldown(interaction) {
|
||||||
@@ -208,13 +230,15 @@ async function nutsCooldown(interaction) {
|
|||||||
const cooldown = await nutsColl.findOne({ userID: interaction.user.id })
|
const cooldown = await nutsColl.findOne({ userID: interaction.user.id })
|
||||||
|
|
||||||
let content = `Du kannst wieder nussen! :)`
|
let content = `Du kannst wieder nussen! :)`
|
||||||
let thumbnail = 'https://cdn-icons-png.flaticon.com/512/7451/7451659.png'
|
let thumbnail = 'attachment://nuts_main.png'
|
||||||
|
let file = `${ASSETS}nuts_main.png`
|
||||||
let title = 'Go Nuts!'
|
let title = 'Go Nuts!'
|
||||||
|
|
||||||
let date = (Date.now() / 1000)
|
let date = (Date.now() / 1000)
|
||||||
if (cooldown.cooldown > date) {
|
if (cooldown.cooldown > date) {
|
||||||
content = `<t:${cooldown.cooldown}:R> kannst du wieder nussen! ;)`
|
content = `<t:${cooldown.cooldown}:R> kannst du wieder nussen! ;)`
|
||||||
thumbnail = 'https://img.freepik.com/free-vector/no-nut-november-cartoon-illustration-premium-cartoon-vector-icon-illustration-food-object-isolated_138676-6549.jpg'
|
thumbnail = 'attachment://nuts_onCD.avif'
|
||||||
|
file = `${ASSETS}nuts_onCD.avif`
|
||||||
title = 'To Nut or Not to Nut...'
|
title = 'To Nut or Not to Nut...'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,9 +248,11 @@ async function nutsCooldown(interaction) {
|
|||||||
.setDescription(content)
|
.setDescription(content)
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [embed]
|
embeds: [embed],
|
||||||
|
files: [file]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function nutsNut(interaction, quickMode) {
|
async function nutsNut(interaction, quickMode) {
|
||||||
const db = mClient.db(process.env.M_DB)
|
const db = mClient.db(process.env.M_DB)
|
||||||
const nutsColl = db.collection('items_nuts')
|
const nutsColl = db.collection('items_nuts')
|
||||||
@@ -235,97 +261,72 @@ async function nutsNut(interaction, quickMode) {
|
|||||||
|
|
||||||
const cdData = await cdColl.findOne({ userID: interaction.user.id })
|
const cdData = await cdColl.findOne({ userID: interaction.user.id })
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setImage('https://e7.pngegg.com/pngimages/1011/894/png-clipart-gift-christmas-box-mystery-gift-box-holidays-box-thumbnail.png')
|
|
||||||
|
|
||||||
let content
|
|
||||||
const images = {
|
const images = {
|
||||||
"high": "https://as2.ftcdn.net/v2/jpg/02/24/65/39/1000_F_224653943_r3xltiwJsK6am0mGZE5DTWk1yocUwHLd.jpg",
|
high: 'attachment://nuts_high.jpg',
|
||||||
"normal": 'https://c8.alamy.com/comp/PPPBXK/surprised-pecan-nuts-pile-on-plate-cartoon-PPPBXK.jpg',
|
normal: 'attachment://nuts_normal.jpg',
|
||||||
"low": 'https://as2.ftcdn.net/v2/jpg/02/24/65/37/1000_F_224653769_ceJk0tq9UT1hSu5FIVUi7BeaN4ucSZGv.jpg',
|
low: 'attachment://nuts_low.jpg',
|
||||||
"none": 'https://cdn4.vectorstock.com/i/1000x1000/87/08/afraid-pecan-nuts-pile-on-plate-cartoon-vector-22028708.jpg',
|
none: 'attachment://nuts_none.avif',
|
||||||
"onCD": 'https://img.freepik.com/free-vector/no-nut-november-cartoon-illustration-premium-cartoon-vector-icon-illustration-food-object-isolated_138676-6549.jpg'
|
onCD: 'attachment://nuts_onCD.avif'
|
||||||
}
|
}
|
||||||
let image
|
|
||||||
if (!cdData || cdData.cooldown < (Date.now() / 1000)) {
|
|
||||||
let cd = Math.floor((Date.now() + 3600000) / 1000)
|
|
||||||
await cdColl.findOneAndUpdate({
|
|
||||||
userID: interaction.user.id
|
|
||||||
}, {
|
|
||||||
$set: { cooldown: cd }
|
|
||||||
}, {
|
|
||||||
upsert: true
|
|
||||||
})
|
|
||||||
|
|
||||||
|
// Helper for singular/plural
|
||||||
|
const formatNut = (amount) => `${amount} ${amount === 1 ? 'Nuss' : 'Nüsse'}`
|
||||||
|
|
||||||
|
// check cooldown
|
||||||
|
if (!cdData || cdData.cooldown < Date.now() / 1000) {
|
||||||
|
// set 1 hour cooldown
|
||||||
|
const cd = Math.floor((Date.now() + 3600000) / 1000)
|
||||||
|
await cdColl.findOneAndUpdate(
|
||||||
|
{ userID: interaction.user.id },
|
||||||
|
{ $set: { cooldown: cd } },
|
||||||
|
{ upsert: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
// generate nut amount
|
||||||
const amount = Math.floor(Math.random() * 10)
|
const amount = Math.floor(Math.random() * 10)
|
||||||
|
|
||||||
await nutsColl.findOneAndUpdate({
|
// update nuts and stats
|
||||||
userID: interaction.user.id
|
await nutsColl.findOneAndUpdate(
|
||||||
}, {
|
{ userID: interaction.user.id },
|
||||||
$inc: { nuts: amount }
|
{ $inc: { nuts: amount } },
|
||||||
}, {
|
{ upsert: true }
|
||||||
upsert: true
|
)
|
||||||
})
|
|
||||||
|
|
||||||
await nutsStatsColl.findOneAndUpdate({
|
await nutsStatsColl.findOneAndUpdate(
|
||||||
userID: interaction.user.id
|
{ userID: interaction.user.id },
|
||||||
}, {
|
{ $inc: { [`stat.${amount}`]: 1 } },
|
||||||
$inc: { [`stat.${amount}`]: 1 }
|
{ upsert: true }
|
||||||
}, {
|
)
|
||||||
upsert: true
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (amount) {
|
let imageFile
|
||||||
content = `Du hast **${amount}** Nüsse bekommen!`
|
if (amount === 0) imageFile = images.none
|
||||||
if (amount > 8) {
|
else if (amount > 8) imageFile = images.high
|
||||||
image = images["high"]
|
else if (amount > 4) imageFile = images.normal
|
||||||
} else if (amount > 4) {
|
else imageFile = images.low
|
||||||
image = images["normal"]
|
|
||||||
} else {
|
embed.setTitle(`Du hast ${formatNut(amount)} bekommen!`)
|
||||||
image = images["low"]
|
embed.setThumbnail(imageFile)
|
||||||
}
|
|
||||||
} else {
|
|
||||||
content = `Du hast leider keine Nüsse bekommen :(`
|
|
||||||
image = images["none"]
|
|
||||||
}
|
|
||||||
|
|
||||||
if (quickMode) {
|
if (quickMode) {
|
||||||
|
return interaction.editReply({ content: `Du hast ${formatNut(amount)} bekommen! :chestnut:` })
|
||||||
|
}
|
||||||
|
|
||||||
return interaction.editReply({
|
return interaction.editReply({
|
||||||
content: `Du hast ${amount} Nüsse bekommen! :chestnut:`,
|
embeds: [embed],
|
||||||
|
files: [`${ASSETS}${imageFile.split('://')[1]}`]
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
content = `Du kannst erst <t:${Math.floor(cdData?.cooldown)}:R> wieder nussen :(`
|
// on cooldown
|
||||||
image = images["onCD"]
|
embed.setTitle('To Nut or Not to Nut...')
|
||||||
await delay(1000)
|
embed.setDescription(`<t:${Math.floor(cdData.cooldown)}:R> kannst du wieder nussen! ;)`)
|
||||||
embed.setDescription(content)
|
embed.setThumbnail(images.onCD)
|
||||||
embed.setThumbnail(image)
|
|
||||||
embed.setImage(null)
|
return interaction.editReply({
|
||||||
return await interaction.editReply({
|
embeds: [embed],
|
||||||
embeds: [embed]
|
files: [`${ASSETS}nuts_onCD.avif`]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
await interaction.editReply({
|
|
||||||
embeds: [embed]
|
|
||||||
})
|
|
||||||
await delay(1000)
|
|
||||||
embed.setImage('https://i.pinimg.com/originals/9d/58/37/9d5837c6f0cb8b18be6ddd1e2742472a.gif')
|
|
||||||
await interaction.editReply({
|
|
||||||
embeds: [embed]
|
|
||||||
})
|
|
||||||
|
|
||||||
await delay(1000)
|
|
||||||
embed.setDescription(content)
|
|
||||||
embed.setImage(image)
|
|
||||||
await interaction.editReply({
|
|
||||||
embeds: [embed]
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
|
|||||||