Compare commits

...

5 Commits

Author SHA1 Message Date
admin_rb bb90ca792c removed debug 2026-04-08 11:42:16 +02:00
admin_rb 0c84c85b62 changed order for quickmode 2026-04-08 11:38:39 +02:00
admin_rb 0218583d24 migrated 2026-04-08 11:37:01 +02:00
admin_rb e2cc63e6c9 renamed db column 2026-04-07 22:01:21 +02:00
admin_rb ad32efb156 added nut context to cooldown 2026-04-07 22:01:03 +02:00
8 changed files with 166 additions and 101 deletions
+2 -2
View File
@@ -15,7 +15,7 @@ module.exports = {
const db = mClient.db(process.env.M_DB) const db = mClient.db(process.env.M_DB)
const quotesColl = db.collection('items_quotes') const quotesColl = db.collection('items_quotes')
const quotes = await quotesColl.find({ by: target.id }).toArray() const quotes = await quotesColl.find({ userID: target.id }).toArray()
var index = Number((await interaction.message.embeds[0].data.title).split(' ')[2].slice(1)) var index = Number((await interaction.message.embeds[0].data.title).split(' ')[2].slice(1))
if (!index) { index = 0 } if (!index) { index = 0 }
@@ -64,7 +64,7 @@ module.exports = {
.setURL(messageLink) .setURL(messageLink)
.setTitle(`- Quote #${index + 1} -`) .setTitle(`- Quote #${index + 1} -`)
.setDescription(description) .setDescription(description)
.setFooter({ text: (`${footer} #${found.messageID} <@${found.by}>`) }) .setFooter({ text: (`${footer} #${found.messageID} <@${found.userID}>`) })
const select = new ActionRowBuilder() const select = new ActionRowBuilder()
.addComponents( .addComponents(
new UserSelectMenuBuilder() new UserSelectMenuBuilder()
+2 -2
View File
@@ -15,7 +15,7 @@ module.exports = {
const db = mClient.db(process.env.M_DB) const db = mClient.db(process.env.M_DB)
const quotesColl = db.collection('items_quotes') const quotesColl = db.collection('items_quotes')
const quotes = await quotesColl.find({ by: target.id }).toArray() const quotes = await quotesColl.find({ userID: target.id }).toArray()
var index = Number((await interaction.message.embeds[0].data.title).split(' ')[2].slice(1)) var index = Number((await interaction.message.embeds[0].data.title).split(' ')[2].slice(1))
if (!index) { index = 0 } if (!index) { index = 0 }
@@ -64,7 +64,7 @@ module.exports = {
.setURL(messageLink) .setURL(messageLink)
.setTitle(`- Quote #${index + 1} -`) .setTitle(`- Quote #${index + 1} -`)
.setDescription(description) .setDescription(description)
.setFooter({ text: (`${footer} #${found.messageID} <@${found.by}>`) }) .setFooter({ text: (`${footer} #${found.messageID} <@${found.userID}>`) })
const select = new ActionRowBuilder() const select = new ActionRowBuilder()
.addComponents( .addComponents(
new UserSelectMenuBuilder() new UserSelectMenuBuilder()
+45 -31
View File
@@ -7,41 +7,55 @@ module.exports = {
async execute(message, args) { async execute(message, args) {
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')
const nutsStatsColl = db.collection('stats_nuts')
const cdColl = db.collection('items_cooldowns') const cdColl = db.collection('items_cooldowns')
const cdData = await cdColl.findOne({ userID: message.author.id }) const cdData = await cdColl.findOne({ userID: message.author.id })
if (!cdData || cdData.cooldown < (Date.now() / 1000)) { if (cdData?.cooldown > (Date.now() / 1000)) {
let cd = Math.floor((Date.now() + 3600000) / 1000)
await cdColl.findOneAndUpdate({
userID: message.author.id
}, {
$set: { cooldown: cd }
}, {
upsert: true
})
const amount = Math.floor(Math.random() * 10)
await nutsColl.findOneAndUpdate({
userID: message.author.id
}, {
$inc: { nuts: amount }
}, {
upsert: true
})
let content = `Du hast ${amount} Nüsse bekommen! :chestnut:`
if (!amount) {
content = `Du hast leider keine Nüsse bekommen :(`
}
return await message.reply({
content: content
})
} else {
return await message.reply({ return await message.reply({
content: `Du kannst erst <t:${Math.floor(cdData?.cooldown)}:R> wieder nussen :(`, content: `Du kannst erst <t:${Math.floor(cdData?.cooldown)}:R> wieder nussen :(`,
}) })
} }
},
}; let cd = Math.floor((Date.now() + 3600000) / 1000)
await cdColl.findOneAndUpdate({
userID: message.author.id
}, {
$set: {
cooldown: cd,
application: 'nuts'
}
}, {
upsert: true
})
const amount = Math.floor(Math.random() * 10)
await nutsColl.findOneAndUpdate({
userID: message.author.id
}, {
$inc: { nuts: amount }
}, {
upsert: true
})
await nutsStatsColl.findOneAndUpdate(
{ userID: message.author.id },
{ $inc: { [`stat.${amount}`]: 1 } },
{ upsert: true }
)
await nutsStatsColl.findOneAndUpdate(
{ userID: "__global" },
{ $inc: { [`stat.${amount}`]: 1 } },
{ upsert: true }
)
let content = `Du hast ${amount} Nüsse bekommen! :chestnut:`
if (!amount) {
content = `Du hast leider keine Nüsse bekommen :(`
}
return await message.reply({
content: content
})
}
}
+1 -1
View File
@@ -45,7 +45,7 @@ module.exports = {
messageID: quoteMessage.id, messageID: quoteMessage.id,
channelID: quoteChannel.id, channelID: quoteChannel.id,
guildID: quoteGuild.id, guildID: quoteGuild.id,
by: msgData.author.id, userID: msgData.author.id,
count: 0 count: 0
} }
}, { upsert: true }) }, { upsert: true })
+109 -58
View File
@@ -4,7 +4,7 @@ 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/' const asset_path = './assets/Command_Nuts/'
async function nutsGive(interaction) { async function nutsGive(interaction) {
async function tradeWindow(buttonID1, buttonID2) { async function tradeWindow(buttonID1, buttonID2) {
@@ -109,7 +109,7 @@ async function nutsCheck(interaction) {
await interaction.editReply({ await interaction.editReply({
embeds: [embed], embeds: [embed],
files: [`${ASSETS}nuts_main.png`] files: [`${asset_path}nuts_main.png`]
}) })
} }
@@ -158,15 +158,23 @@ async function nutsLeaderboard(interaction) {
await interaction.editReply({ await interaction.editReply({
embeds: [embed], embeds: [embed],
components: [row], components: [row],
files: [`${ASSETS}nuts_main.png`] files: [`${asset_path}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');
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
}
const statsDoc = await nStatsColl.findOne({ userID: target.id });
const stat = statsDoc?.stat || {}; const stat = statsDoc?.stat || {};
const totalCount = Object.values(stat).reduce((a, b) => a + b, 0); const totalCount = Object.values(stat).reduce((a, b) => a + b, 0);
@@ -198,7 +206,7 @@ async function nutsStats(interaction) {
const nutAvg = totalCount ? totalNuts / totalCount : 0; const nutAvg = totalCount ? totalNuts / totalCount : 0;
const fields = Array.from({ length: 10 }, (_, i) => ({ const fields = Array.from({ length: 11 }, (_, i) => ({
name: `[${i}]`, name: `[${i}]`,
value: `x${stat[i] ?? 0}`, value: `x${stat[i] ?? 0}`,
inline: true inline: true
@@ -210,8 +218,8 @@ async function nutsStats(interaction) {
`Total Nut Actions: **${totalCount}**\r\n` + `Total Nut Actions: **${totalCount}**\r\n` +
`Total Nuts nutted: **${totalNuts}**\r\n` + `Total Nuts nutted: **${totalNuts}**\r\n` +
`Nut Average: **${nutAvg.toFixed(3)}**\r\n` + `Nut Average: **${nutAvg.toFixed(3)}**\r\n` +
`Best Nut: **${nutMax.number} (x${nutMax.count})**\r\n` + `Most Common Nut: **${nutMax.number} (x${nutMax.count})**\r\n` +
`Worst Nut: **${nutMin.number} (x${nutMin.count})**` `Least Common Nut: **${nutMin.number} (x${nutMin.count})**`
) )
.addFields(fields) .addFields(fields)
.setColor(0x51267) .setColor(0x51267)
@@ -220,7 +228,7 @@ async function nutsStats(interaction) {
await interaction.editReply({ await interaction.editReply({
embeds: [embed], embeds: [embed],
files: [`${ASSETS}nuts_main.png`] files: [`${asset_path}nuts_main.png`]
}); });
} }
@@ -231,14 +239,14 @@ async function nutsCooldown(interaction) {
let content = `Du kannst wieder nussen! :)` let content = `Du kannst wieder nussen! :)`
let thumbnail = 'attachment://nuts_main.png' let thumbnail = 'attachment://nuts_main.png'
let file = `${ASSETS}nuts_main.png` let file = `${asset_path}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 = 'attachment://nuts_onCD.avif' thumbnail = 'attachment://nuts_onCD.avif'
file = `${ASSETS}nuts_onCD.avif` file = `${asset_path}nuts_onCD.avif`
title = 'To Nut or Not to Nut...' title = 'To Nut or Not to Nut...'
} }
@@ -262,71 +270,101 @@ 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()
const images = { const assets = {
high: 'attachment://nuts_high.jpg', high: 'attachment://nuts_high.jpg',
normal: 'attachment://nuts_normal.jpg', normal: 'attachment://nuts_normal.jpg',
low: 'attachment://nuts_low.jpg', low: 'attachment://nuts_low.jpg',
none: 'attachment://nuts_none.avif', 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 // Helper for singular/plural
const formatNut = (amount) => `${amount} ${amount === 1 ? 'Nuss' : 'Nüsse'}` const formatNut = (amount) => `${amount} ${amount === 1 ? 'Nuss' : 'Nüsse'}`
// check cooldown // check cooldown
if (!cdData || cdData.cooldown < Date.now() / 1000) { if (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)
// update nuts and stats
await nutsColl.findOneAndUpdate(
{ userID: interaction.user.id },
{ $inc: { nuts: amount } },
{ upsert: true }
)
await nutsStatsColl.findOneAndUpdate(
{ userID: interaction.user.id },
{ $inc: { [`stat.${amount}`]: 1 } },
{ 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
embed.setTitle(`Du hast ${formatNut(amount)} bekommen!`)
embed.setThumbnail(imageFile)
if (quickMode) {
return interaction.editReply({ content: `Du hast ${formatNut(amount)} bekommen! :chestnut:` })
}
return interaction.editReply({
embeds: [embed],
files: [`${ASSETS}${imageFile.split('://')[1]}`]
})
} else {
// on cooldown // on cooldown
embed.setTitle('To Nut or Not to Nut...') embed.setTitle('To Nut or Not to Nut...')
embed.setDescription(`<t:${Math.floor(cdData.cooldown)}:R> kannst du wieder nussen! ;)`) embed.setDescription(`<t:${Math.floor(cdData.cooldown)}:R> kannst du wieder nussen! ;)`)
embed.setThumbnail(images.onCD) embed.setThumbnail(assets.onCD)
return interaction.editReply({ return interaction.editReply({
embeds: [embed], embeds: [embed],
files: [`${ASSETS}nuts_onCD.avif`] files: [`${asset_path}nuts_onCD.avif`]
}) })
} }
// set 1 hour cooldown
const cd = Math.floor((Date.now() + 3600000) / 1000)
await cdColl.findOneAndUpdate({
userID: interaction.user.id
}, {
$set: {
cooldown: cd,
application: 'nuts'
}
}, {
upsert: true
})
// generate nut amount
const amount = Math.floor(Math.random() * 10)
// update nuts and stats
await nutsColl.findOneAndUpdate(
{ userID: interaction.user.id },
{ $inc: { nuts: amount } },
{ upsert: true }
)
await nutsStatsColl.findOneAndUpdate(
{ userID: interaction.user.id },
{ $inc: { [`stat.${amount}`]: 1 } },
{ upsert: true }
)
await nutsStatsColl.findOneAndUpdate(
{ userID: "__global" },
{ $inc: { [`stat.${amount}`]: 1 } },
{ upsert: true }
)
if (quickMode) {
return interaction.editReply({ content: `Du hast ${formatNut(amount)} bekommen! :chestnut:` })
}
// pseudo animation
embed.setImage(assets.box)
await interaction.editReply({
embeds: [embed],
files: [`${asset_path}nuts_box.png`]
})
await delay(1337)
embed.setImage(assets.explosion)
await interaction.editReply({
embeds: [embed],
files: [`${asset_path}nuts_explosion.gif`]
})
await delay(1337)
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(assetFile)
embed.setImage(null)
return interaction.editReply({
embeds: [embed],
files: [`${asset_path}${assetFile.split('://')[1]}`]
})
} }
module.exports = { module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
@@ -350,7 +388,20 @@ module.exports = {
.addSubcommand(s => .addSubcommand(s =>
s s
.setName('stats') .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 => .addSubcommand(s =>
s s
.setName('cooldown') .setName('cooldown')
+3 -3
View File
@@ -57,7 +57,7 @@ async function quotesAdd(interaction) {
messageID: messageID, messageID: messageID,
channelID: channelID, channelID: channelID,
guildID: guildID, guildID: guildID,
by: msgData.author.id, userID: msgData.author.id,
count: 0 count: 0
} }
}, { upsert: true }) }, { upsert: true })
@@ -164,7 +164,7 @@ async function quotesRandom(interaction) {
if (user) { if (user) {
rdm = await quotesColl.aggregate([ rdm = await quotesColl.aggregate([
{ {
$match: { by: user.id }, $match: { userID: user.id },
}, { }, {
$sample: { size: 1 } $sample: { size: 1 }
} }
@@ -310,7 +310,7 @@ async function quotesLeaderboard(interaction, page = 1, limit = 5) {
return { return {
name: `${skip + index + 1}.`, name: `${skip + index + 1}.`,
value: `[#${data.messageID}](https://discord.com/channels/${data.guildID}/${data.channelID}/${data.messageID})\n**by** <@${data.by}> • ⭐ ${data.count}\n_Posted on **${timestamp}**_\n${message.content}` value: `[#${data.messageID}](https://discord.com/channels/${data.guildID}/${data.channelID}/${data.messageID})\n**by** <@${data.userID}> • ⭐ ${data.count}\n_Posted on **${timestamp}**_\n${message.content}`
}; };
} catch { } catch {
return { return {
+2 -2
View File
@@ -35,7 +35,7 @@ module.exports = {
// Fetch birthday role // Fetch birthday role
const bdayRoleColl = db.collection('config_roles'); const bdayRoleColl = db.collection('config_roles');
const bdayRoleEntry = await bdayRoleColl.findOne({ guildID: guild.id }); const bdayRoleEntry = await bdayRoleColl.findOne({ guildID: guild.id });
const birthdayRoleID = bdayRoleEntry.roleID; const birthdayRoleID = bdayRoleEntry?.roleID;
if (!birthdayRoleID) { if (!birthdayRoleID) {
console.warn("No birthday role configured in DB"); console.warn("No birthday role configured in DB");
@@ -54,7 +54,7 @@ module.exports = {
console.error(`Failed to add birthday role to ${member.user.tag}:`, err) console.error(`Failed to add birthday role to ${member.user.tag}:`, err)
); );
console.log(`Added birthday role to ${member.user.tag}`); console.log(`Added birthday role to ${member.user.tag}`);
client.emit('Birthday', member); //client.emit('Birthday', member);
} else { } else {
// Default fallback: remove birthday role if present // Default fallback: remove birthday role if present
if (member.roles.cache.has(birthdayRoleID)) { if (member.roles.cache.has(birthdayRoleID)) {
@@ -16,7 +16,7 @@ module.exports = {
const target = await interaction.guild.members.fetch(interaction.members.keys().next().value) const target = await interaction.guild.members.fetch(interaction.members.keys().next().value)
const db = mClient.db(process.env.M_DB) const db = mClient.db(process.env.M_DB)
const quotesColl = db.collection('items_quotes') const quotesColl = db.collection('items_quotes')
const quotes = await quotesColl.find({ by: target.id }).toArray() const quotes = await quotesColl.find({ userID: target.id }).toArray()
const member = interaction.message.guild.members.cache.get(target.user.id) const member = interaction.message.guild.members.cache.get(target.user.id)
const memberRoles = member.roles.cache const memberRoles = member.roles.cache
.filter((roles) => roles.id !== interaction.message.guild.id) .filter((roles) => roles.id !== interaction.message.guild.id)