moved to subdir

This commit is contained in:
2026-04-06 20:07:58 +02:00
parent f1f9d95685
commit 5e8fb7e729
28 changed files with 83 additions and 77 deletions
+274
View File
@@ -0,0 +1,274 @@
const { SlashCommandBuilder, EmbedBuilder, MessageFlags } = require('discord.js')
const { mClient } = require('../../../index')
const { configDotenv } = require('dotenv')
configDotenv()
function isValidDate(day, month) {
// Define the number of days in each month
const daysInMonth = {
1: 31, // January
2: 28, // February (ignore leap years)
3: 31, // March
4: 30, // April
5: 31, // May
6: 30, // June
7: 31, // July
8: 31, // August
9: 30, // September
10: 31, // October
11: 30, // November
12: 31 // December
};
// Check if month is valid
if (month < 1 || month > 12) {
return false;
}
// Check if day is valid for the given month
if (day < 1 || day > daysInMonth[month]) {
return false;
}
return true;
}
async function birthdayAdd(interaction) {
let target = await interaction.options.getUser('user')
let day = await interaction.options.getNumber('day')
let month = await interaction.options.getNumber('month')
if (!isValidDate(day, month)) {
return interaction.reply({ content: "Invalid Date", flags: MessageFlags.Ephemeral })
}
const db = mClient.db(process.env.M_DB)
const bdayColl = db.collection('items_birthdays')
const found = await bdayColl.findOne({ userID: target.id })
if (found) {
return interaction.reply({ content: "Already in Database", flags: MessageFlags.Ephemeral })
}
const data = {
guildID: interaction.guild.id,
userID: target.id,
day: day,
month: month
}
const res = await bdayColl.insertOne(data)
if (res.acknowledged) {
return interaction.reply({ content: "Birthday added successfully!" })
} else {
return interaction.reply({ content: "There was an issue!" })
}
}
async function birthdayDelete(interaction) {
var target = await interaction.options.getUser('user')
const guild = await interaction.client.guilds.cache.get(interaction.guild.id)
if (!target) {
target = await guild.members.cache.get(await interaction.options.getString('id'))
}
if (!target) {
return interaction.reply({ content: "Invalid or No User specified!" })
}
const db = mClient.db(process.env.M_DB)
const bdayColl = db.collection('items_birthdays')
const found = await bdayColl.findOne({ userID: target.id })
if (!found) {
return interaction.reply({ content: "Not yet in Database", flags: MessageFlags.Ephemeral })
}
const res = await bdayColl.deleteOne({ userID: target.id })
if (res.acknowledged) {
return interaction.reply({ content: "Birthday removed successfully!" })
} else {
return interaction.reply({ content: "There was an issue!" })
}
}
async function birthdayEdit(interaction) {
let target = await interaction.options.getUser('user')
let day = await interaction.options.getNumber('day')
let month = await interaction.options.getNumber('month')
if (!isValidDate(day, month)) {
return interaction.reply({ content: "Invalid Date", flags: MessageFlags.Ephemeral })
}
const db = mClient.db(process.env.M_DB)
const bdayColl = db.collection('items_birthdays')
const found = await bdayColl.findOne({ userID: target.id })
if (!found) {
return interaction.reply({ content: "Not yet in Database", flags: MessageFlags.Ephemeral })
}
const data = {
guildID: interaction.guild.id,
userID: target.id,
day: day,
month: month
}
const res = await bdayColl.findOneAndUpdate({ userID: target.id }, { $set: data }, { upsert: true })
return interaction.reply({ content: "Birthday edited successfully!" })
}
async function makeTimestamp(day, month, year) {
const date = new Date(year, month - 1, day);
const unixTimestamp = Math.floor(date.getTime() / 1000);
return unixTimestamp
}
function isToday(day, month) {
const currentYear = new Date().getFullYear();
const inputDate = new Date(currentYear, month - 1, day);
const today = new Date();
return (
inputDate.getDate() === today.getDate() &&
inputDate.getMonth() === today.getMonth() &&
inputDate.getFullYear() === today.getFullYear()
);
}
async function birthdayGet(interaction) {
const target = await interaction.options.getUser('user');
const db = mClient.db(process.env.M_DB);
const bdayColl = db.collection('items_birthdays');
const found = await bdayColl.findOne({ userID: target.id });
if (!found) {
return interaction.reply({
content: "Not in Database!",
flags: MessageFlags.Ephemeral
});
}
const now = new Date();
const isToday =
now.getDate() === found.day &&
now.getMonth() === (found.month - 1);
let description;
if (isToday) {
description = `IS TODAY! 🥳🎉`;
} else {
const unix = getNextBirthdayTimestamp(found.day, found.month);
description = `is on the <t:${unix}:d>\n<t:${unix}:R>`;
}
const embed = new EmbedBuilder()
.setThumbnail(target.displayAvatarURL())
.setTitle(`${target.globalName ?? target.username}'s Birthday...`)
.setDescription(description);
await interaction.reply({ embeds: [embed] });
}
function getNextBirthdayTimestamp(day, month) {
const now = new Date();
now.setHours(0, 0, 0, 0);
const currentYear = now.getFullYear();
let nextBirthday = new Date(currentYear, month - 1, day);
// If birthday already passed this year → next year
if (nextBirthday < now) {
nextBirthday.setFullYear(currentYear + 1);
}
return Math.floor(nextBirthday.getTime() / 1000); // Unix timestamp
}
module.exports = {
data: new SlashCommandBuilder()
.setName('birthday')
.setDescription('manage birthdays')
.addSubcommand(s =>
s
.setName('add')
.setDescription('adds a birthday')
.addUserOption((option) =>
option
.setName('user')
.setDescription('user')
.setRequired(true))
.addNumberOption((option) =>
option
.setName('day')
.setDescription('day')
.setMinValue(1)
.setMaxValue(31)
.setRequired(true))
.addNumberOption((option) =>
option
.setName('month')
.setDescription('month')
.setMinValue(1)
.setMaxValue(12)
.setRequired(true))
)
.addSubcommand(s =>
s
.setName('delete')
.setDescription('deletes a birthday')
.addUserOption((option) =>
option.setName('user').setDescription('user'))
.addStringOption((option) =>
option.setName('id').setDescription('ID')))
.addSubcommand(s =>
s
.setName('edit')
.setDescription('edits a birthday')
.addUserOption((option) =>
option.setName('user').setDescription('user').setRequired(true))
.addNumberOption((option) =>
option.setName('day').setDescription('day').setRequired(true))
.addNumberOption((option) =>
option.setName('month').setDescription('month').setRequired(true)))
.addSubcommand(s =>
s
.setName('get')
.setDescription('gets a birthday')
.addUserOption((option) =>
option.setName('user').setDescription('user').setRequired(true))),
async execute(interaction) {
switch (interaction.options._subcommand) {
case 'add':
if (!interaction.member.permissions.has("ADMINISTRATOR")) {
return await interaction.reply({
content: "Unprivileged Access!",
flags: MessageFlags.Ephemeral
})
}
birthdayAdd(interaction)
break;
case 'delete':
if (!interaction.member.permissions.has("ADMINISTRATOR")) {
return await interaction.reply({
content: "Unprivileged Access!",
flags: MessageFlags.Ephemeral
})
}
birthdayDelete(interaction)
break;
case 'edit':
if (!interaction.member.permissions.has("ADMINISTRATOR")) {
return await interaction.reply({
content: "Unprivileged Access!",
flags: MessageFlags.Ephemeral
})
}
birthdayEdit(interaction)
break;
case 'get':
birthdayGet(interaction)
break;
default:
break;
}
}
}
+171
View File
@@ -0,0 +1,171 @@
const { SlashCommandBuilder, Events, MessageFlags } = require('discord.js')
const { mClient } = require('../../../index')
require('dotenv').config()
async function channelSet(interaction) {
const channel = interaction.options.getChannel('channel')
const purpose = interaction.options.getString('purpose')
const db = mClient.db(process.env.M_DB)
const channelColl = db.collection('config_channels')
await channelColl.findOneAndUpdate({
$and: [{ guildID: channel.guild.id }, { purpose: purpose }]
}, {
$set: {
guildID: channel.guild.id,
purpose: purpose,
channelID: channel.id
}
}, {
upsert: true
})
return await interaction.editReply({
content: `Set <#${channel.id}> as ${purpose} channel!`, flags: MessageFlags.Ephemeral
})
}
async function channelSimulate(interaction) {
const purpose = interaction.options.getString('purpose')
switch (purpose) {
case 'birthday':
await interaction.client.emit('Birthday', interaction.member)
break;
case 'wge':
// For Future WGE Use
break;
case 'welcome':
await interaction.client.emit(Events.GuildMemberAdd, interaction.member)
break;
case 'logs':
// For Future Log Use
break;
default:
break;
}
return interaction.reply({ content: 'Done.', flags: MessageFlags.Ephemeral })
}
async function roleSet(interaction) {
const guild = interaction.guild
const purpose = interaction.options.getString('purpose')
const role = interaction.options.getRole('role')
const db = mClient.db(process.env.M_DB)
const roleColl = db.collection('config_roles')
switch (purpose) {
case 'birthday':
await roleColl.findOneAndUpdate({
$and: [{ guildID: guild.id }, { purpose: purpose }]
}, {
$set: {
guildID: guild.id,
purpose: purpose,
roleID: role.id
}
}, {
upsert: true
})
break;
default:
break;
}
return await interaction.editReply({
content: `Set ${role} as default role for ${purpose} in ${guild} `
})
}
module.exports = {
data: new SlashCommandBuilder()
.setName('config')
.setDescription('configurations for admins')
.addSubcommandGroup(sg =>
sg
.setName('channels')
.setDescription('configure channels for certain events')
.addSubcommand(s =>
s.setName('set')
.setDescription('sets channel')
.addStringOption(o =>
o.setName('purpose').setDescription('set the purpose').setRequired(true).addChoices({
name: 'birthday',
value: 'birthday'
}, {
name: 'welcome',
value: 'welcome'
}, {
name: 'logs',
value: 'logs'
}, {
name: 'wge',
value: 'wge'
}))
.addChannelOption(c =>
c.setName('channel').setDescription('choose a channel').setRequired(true)
)
)
.addSubcommand(s =>
s
.setName('simulate')
.setDescription('simulate a specific channel event')
.addStringOption(o =>
o.setName('purpose').setDescription('set the purpose').setRequired(true).addChoices({
name: 'birthday',
value: 'birthday'
}, {
name: 'welcome',
value: 'welcome'
}, {
name: 'logs',
value: 'logs'
}, {
name: 'wge',
value: 'wge'
}))
)
)
.addSubcommandGroup(sg =>
sg.setName('roles')
.setDescription('configure roles for certain events')
.addSubcommand(s =>
s.setName('set')
.setDescription('sets roles')
.addStringOption(o =>
o.setName('purpose').setDescription('set the purpose').setRequired(true).addChoices({
name: 'birthday',
value: 'birthday'
}))
.addRoleOption(c =>
c.setName('role').setDescription('choose a role').setRequired(true)
)
)
),
async execute(interaction) {
switch (interaction.options._group) {
case 'channels':
switch (interaction.options._subcommand) {
case 'set':
await interaction.deferReply()
channelSet(interaction)
break;
case 'simulate':
channelSimulate(interaction)
break;
default:
break;
}
case 'roles':
switch (interaction.options._subcommand) {
case 'set':
await interaction.deferReply()
roleSet(interaction)
break;
default:
break;
}
default:
break;
}
}
}
+277
View File
@@ -0,0 +1,277 @@
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, UserSelectMenuBuilder, MessageFlags } = require('discord.js')
const { mClient } = require('../../../index')
require('dotenv').config()
function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
async function honorHoner(interaction) {
const db = mClient.db(process.env.M_DB)
const honorsColl = db.collection('items_honors')
const target = await interaction.options.getUser('target')
const reason = `[+] ${await interaction.options.getString('reason') ?? 'No reason provided'}`
const theirHonorLevel = await honorsColl.findOne({ userID: target.id })
const embed = new EmbedBuilder()
.setTitle('- Honor Up! -')
.setDescription(`Willst du wirklich <@${target.id}> einen **Honor** geben?\r\n[Grund: ${reason}]`)
.addFields({
name: 'Current Honor Level', value: `${theirHonorLevel?.honors ?? 0} (**+1**)`
})
.setThumbnail(target.displayAvatarURL())
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel('✔')
.setCustomId('honor_multi_confirm')
.setStyle(ButtonStyle.Success)
)
.addComponents(
new ButtonBuilder()
.setLabel('✖')
.setCustomId('abort')
.setStyle(ButtonStyle.Danger)
)
await interaction.reply({
embeds: [embed],
components: [row],
flags: MessageFlags.Ephemeral
})
}
async function honerDishonor(interaction) {
const db = mClient.db(process.env.M_DB)
const honorsColl = db.collection('items_honors')
const target = await interaction.options.getUser('target')
const reason = `[-] ${await interaction.options.getString('reason') ?? 'No reason provided'}`
const theirHonorLevel = await honorsColl.findOne({ userID: target.id })
const embed = new EmbedBuilder()
.setTitle('- Honor Down! -')
.setDescription(`Willst du wirklich <@${target.id}> einen **Dishonor** geben?\r\n[Grund: ${reason}]`)
.addFields({
name: 'Current Honor Level', value: `${theirHonorLevel?.honors ?? 0} (**-1**)`
})
.setThumbnail(target.displayAvatarURL())
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel('✔')
.setCustomId('honor_multi_confirm')
.setStyle(ButtonStyle.Success)
)
.addComponents(
new ButtonBuilder()
.setLabel('✖')
.setCustomId('abort')
.setStyle(ButtonStyle.Danger)
)
await interaction.reply({
embeds: [embed],
components: [row],
flags: MessageFlags.Ephemeral
})
}
async function honorLeaderboard(interaction) {
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel('◄')
.setStyle(ButtonStyle.Primary)
.setCustomId('honors_leaderboard_left')
)
.addComponents(
new ButtonBuilder()
.setLabel('🧑')
.setStyle(ButtonStyle.Primary)
.setCustomId('honors_leaderboard_self')
)
.addComponents(
new ButtonBuilder()
.setLabel('►')
.setStyle(ButtonStyle.Primary)
.setCustomId('honors_leaderboard_right')
)
const db = mClient.db(process.env.M_DB)
const honorsColl = db.collection('items_honors')
let skip = 0
const honorsData = await honorsColl.find({}).sort({ honors: -1 }).skip(skip).limit(5).toArray()
let fields
let placements = skip + 1
honorsData.forEach((data) => {
fields = (fields ? fields : '') + (`${placements}. <@${data.userID}> : ${data.honors} Honors\r\n`)
})
const embed = new EmbedBuilder()
.setTitle('- Honors Leaderboard -')
.setThumbnail('https://cdn.discordapp.com/attachments/1152723542836772914/1152940755539722240/pngwing.com.png')
.setDescription(fields.toString())
.setColor('#5865F2') // Discord's blurple color
.setFooter({ text: 'Use ◄ ► to navigate' });
await interaction.editReply({
embeds: [embed],
components: [row]
})
}
async function honorHistory(interaction) {
var target = interaction.options.getUser('target')
if (!target) { target = interaction.user }
const db = mClient.db(process.env.M_DB)
const reasonsColl = db.collection('history_honors')
var history = await reasonsColl.findOne({ userID: target.id })
const embed = new EmbedBuilder()
.setTitle('- Honor History -')
.setThumbnail(target.displayAvatarURL())
if (history) {
let temp = ''
history.reasons.forEach(reason => {
temp += reason + '\r\n'
})
embed.setDescription(temp)
}
await interaction.editReply({ embeds: [embed] })
}
async function honorCheck(interaction) {
var target = interaction.options.getUser('target')
if (!target) { target = interaction.user }
const db = mClient.db(process.env.M_DB)
const honorsColl = db.collection('items_honors')
var honors = await honorsColl.findOne({ userID: target.id })
honors = honors?.honors ?? 0
if (!honors) {
content = 'Choose a goddamn side!'
} else {
if (honors === -20) {
content = 'They are is at max Dishonor Level! <:lowhonor:748176295132790786> <:lowhonor:748176295132790786> <:lowhonor:748176295132790786>\n```' + `You don't get to live a bad life and have good things happen to you. - Arthur M.` + '```'
} else if (honors === 20) {
content = 'They are at max Honor Level! <:highhonor:748176295535443968> <:highhonor:748176295535443968> <:highhonor:748176295535443968>'
} else if (honors > 0) {
content = 'real good, boah, REAL GOOD! <:highhonor:748176295535443968>'
} else if (honors < 0) {
content = 'What happened to Loyalty?! <:lowhonor:748176295132790786>'
}
}
const embed = new EmbedBuilder()
.setTitle('- Honor Check -')
.setDescription(`${target} has an Honor Level of **${honors}**!`)
.setThumbnail(target.displayAvatarURL())
.addFields({ name: '\u200B', value: `*${content}*` })
await interaction.editReply({
embeds: [embed]
})
}
async function honorMenu(interaction) {
const embed = new EmbedBuilder()
.setTitle('- Honor Menu! -')
.setDescription('- Choose someone from the Select Menu below\r\n- Choose Honor Dishonor, or History\r\n- Confirm your Selection')
.setThumbnail(interaction.guild.iconURL())
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setEmoji(`<:honorhigh:748176295535443968>`)
.setCustomId('honor_menu_honor')
.setStyle(ButtonStyle.Success)
)
.addComponents(
new ButtonBuilder()
.setEmoji(`<:honorlow:748176295132790786>`)
.setCustomId('honor_menu_dishonor')
.setStyle(ButtonStyle.Danger)
)
.addComponents(
new ButtonBuilder()
.setEmoji(``)
.setCustomId('abort')
.setStyle(ButtonStyle.Secondary)
)
.addComponents(
new ButtonBuilder()
.setEmoji('📜')
.setCustomId('honor_menu_history')
.setStyle(ButtonStyle.Secondary)
)
const select = new ActionRowBuilder()
.addComponents(
new UserSelectMenuBuilder()
.setCustomId('honor_menu_mentionable')
.setPlaceholder('Select a User')
)
await interaction.reply({
embeds: [embed],
components: [select, row],
flags: MessageFlags.Ephemeral
})
}
module.exports = {
data: new SlashCommandBuilder()
.setName('honors')
.setDescription('rund um den honor')
.addSubcommand(s =>
s
.setName('honor')
.setDescription('honor someone')
.addUserOption(o => o.setName('target').setDescription('wer wird gehonored?').setRequired(true))
.addStringOption(o => o.setName('reason').setDescription('reason?'))
)
.addSubcommand(s =>
s
.setName('dishonor')
.setDescription('dishonor someone')
.addUserOption(o => o.setName('target').setDescription('wer wird gehonored?').setRequired(true))
.addStringOption(o => o.setName('reason').setDescription('reason?'))
)
.addSubcommand(s =>
s
.setName('check')
.setDescription("check someone's honor level")
.addUserOption(o => o.setName('target').setDescription('wer wird gehonored?'))
)
.addSubcommand(s =>
s
.setName('history')
.setDescription("check someone's honor history")
.addUserOption(o => o.setName('target').setDescription('von wem?'))
)
.addSubcommand(s =>
s
.setName('leaderboard')
.setDescription("check who's got the most honor")
)
.addSubcommand(s =>
s
.setName('menu')
.setDescription('WIP universal honor menu'))
,
async execute(interaction) {
switch (interaction.options._subcommand) {
case 'honor':
honorHoner(interaction)
break;
case 'dishonor':
honerDishonor(interaction)
break;
case 'leaderboard':
await interaction.deferReply()
honorLeaderboard(interaction)
break;
case 'history':
await interaction.deferReply()
honorHistory(interaction)
break;
case 'check':
await interaction.deferReply()
honorCheck(interaction)
break;
case 'menu':
honorMenu(interaction)
break;
default:
break;
}
}
}
+381
View File
@@ -0,0 +1,381 @@
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, MessageFlags } = require('discord.js')
const { mClient } = require('../../../index')
require('dotenv').config()
function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
async function nutsGive(interaction) {
async function tradeWindow(buttonID1, buttonID2) {
const embed = new EmbedBuilder()
.setTitle('Gib Nuss!')
.setDescription(`Willst du wirklich **${amount}** Nüsse an <@${to.id}> senden?`)
.addFields(
{ name: `Your Current Balance`, value: `${yourBalance.nuts} (**-${amount}**)`, inline: true },
{ name: `Your New Balance`, value: `${yourBalance.nuts - amount}`, inline: true },
{ name: '\u200B', value: '\u200B' },
{ name: `Their Current Balance`, value: `${theirBalance.nuts} (**+${amount}**)`, inline: true },
{ name: `Their New Balance`, value: `${theirBalance.nuts + amount}`, inline: true }
)
.setThumbnail(to.displayAvatarURL())
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel('✔')
.setCustomId(buttonID1)
.setStyle(ButtonStyle.Success)
)
.addComponents(
new ButtonBuilder()
.setLabel('✖')
.setCustomId(buttonID2)
.setStyle(ButtonStyle.Danger)
)
await interaction.reply({
embeds: [embed],
components: [row],
flags: MessageFlags.Ephemeral
})
}
const from = interaction.user
const to = await interaction.options.getUser('target')
var amount = await interaction.options.getNumber('amount')
const db = mClient.db(process.env.M_DB)
const nutsColl = db.collection('items_nuts')
const yourBalance = await nutsColl.findOne({ userID: from.id })
const theirBalance = await nutsColl.findOne({ userID: to.id })
if (amount <= 0) {
amount = yourBalance.nuts
return tradeWindow('nuts_give_fake', 'abort')
}
if (yourBalance.nuts < amount) {
return await interaction.reply({
content: 'Du kannst nicht mehr geben als du hast!',
flags: MessageFlags.Ephemeral
})
}
return tradeWindow('nuts_give_confirm', 'abort')
}
async function nutsCheck(interaction) {
let target = interaction.options.getUser('target')
let addressing
if (!target) {
target = interaction.user
addressing = `Du hast`
}
if (!target.globalName) {
addressing = `${target.username} hat`
} else {
addressing = `${target.globalName} hat`
}
const db = mClient.db(process.env.M_DB)
const nutsColl = db.collection('items_nuts')
const nutsData = await nutsColl.findOne({ userID: target.id })
let content
if (!nutsData) {
content = `${addressing} noch keine Nüsse gesammelt :(`
} else {
content = `${addressing} bereits **${nutsData.nuts}** Nüsse gesammelt!`
}
let title = 'Zähle Nüsse'
const embed = new EmbedBuilder()
for (let i = 0; i < 4; i++) {
embed.setTitle(title)
await interaction.editReply({
embeds: [embed]
})
title = title + ' .'
await delay(500);
}
embed
.setTitle(content)
.setThumbnail('https://cdn-icons-png.flaticon.com/512/628/628206.png')
await interaction.editReply({
embeds: [embed]
})
}
async function nutsLeaderboard(interaction) {
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel('◄')
.setStyle(ButtonStyle.Primary)
.setCustomId('nuts_leaderboard_left')
)
.addComponents(
new ButtonBuilder()
.setLabel('🧑')
.setStyle(ButtonStyle.Primary)
.setCustomId('nuts_leaderboard_self')
)
.addComponents(
new ButtonBuilder()
.setLabel('►')
.setStyle(ButtonStyle.Primary)
.setCustomId('nuts_leaderboard_right')
)
const db = mClient.db(process.env.M_DB)
const nutsColl = db.collection('items_nuts')
let skip = 0
const nutsData = await nutsColl.find({ nuts: { $gt: 0 } }).sort({ nuts: -1 }).skip(skip).limit(5).toArray()
let fields
let placements = skip + 1
nutsData.forEach((data) => {
fields = (fields ? fields : '') + (`${placements}. <@${data.userID}> : ${data.nuts} Nuts\r\n`)
})
const embed = new EmbedBuilder()
.setTitle('Nuts Leaderboard')
.setThumbnail(interaction.guild.iconURL({ dynamic: true }))
.setDescription(fields.toString())
.setColor('#5865F2') // Discord's blurple color
.setFooter({ text: 'Use ◄ ► to navigate' });
await interaction.editReply({
embeds: [embed],
components: [row]
})
}
async function nutsStats(interaction) {
const db = mClient.db(process.env.M_DB);
const nStatsColl = db.collection('stats_nuts');
// fetch user stats
const statsDoc = await nStatsColl.findOne({ userID: interaction.user.id });
const stat = statsDoc?.stat || {}; // fallback to empty object
// compute totals
const totalCount = Object.values(stat).reduce((a, b) => a + b, 0);
const totalNuts = Object.entries(stat).reduce(
(sum, [num, count]) => sum + Number(num) * count,
0
);
const rolledNumbers = Object.entries(stat).filter(([_, count]) => count > 0);
let nutMin = { number: 0, count: 0 };
let nutMax = { number: 0, count: 0 };
if (rolledNumbers.length > 0) {
// initialize to first rolled number
nutMin = nutMax = { number: Number(rolledNumbers[0][0]), count: rolledNumbers[0][1] };
for (const [numStr, count] of rolledNumbers) {
const num = Number(numStr);
// best nut: prefer higher number if counts tie
if (count > nutMax.count || (count === nutMax.count && num > nutMax.number)) {
nutMax = { number: num, count };
}
// worst nut: prefer lower number if counts tie
if (count < nutMin.count || (count === nutMin.count && num < nutMin.number)) {
nutMin = { number: num, count };
}
}
}
const nutAvg = totalCount ? totalNuts / totalCount : 0;
// dynamically create fields for numbers 0-9
const fields = Array.from({ length: 10 }, (_, i) => ({
name: `[${i}]`,
value: `x${stat[i] ?? 0}`,
inline: true
}));
const embed = new EmbedBuilder()
.setTitle("Nut Statistic")
.setDescription(
`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})**`
)
.addFields(fields)
.setColor(0x51267)
.setTimestamp()
.setThumbnail(interaction.guild.iconURL());
await interaction.editReply({ embeds: [embed] });
}
async function nutsCooldown(interaction) {
const db = mClient.db(process.env.M_DB)
const nutsColl = db.collection('items_cooldowns')
const cooldown = await nutsColl.findOne({ userID: interaction.user.id })
let content = `Du kannst wieder nussen! :)`
let thumbnail = 'https://cdn-icons-png.flaticon.com/512/7451/7451659.png'
let title = 'Go Nuts!'
let date = (Date.now() / 1000)
if (cooldown.cooldown > date) {
content = `<t:${cooldown.cooldown}:R> kannst du wieder nussen! ;)`
thumbnail = 'https://cdn.discordapp.com/attachments/1152723542836772914/1152987472788193361/No-nuts-PhotoRoom.png-PhotoRoom.png'
title = 'To Nut or Not to Nut...'
}
const embed = new EmbedBuilder()
.setThumbnail(thumbnail)
.setTitle(title)
.setDescription(content)
await interaction.editReply({
embeds: [embed]
})
}
async function nutsNut(interaction) {
const db = mClient.db(process.env.M_DB)
const nutsColl = db.collection('items_nuts')
const cdColl = db.collection('items_cooldowns')
const nutsStatsColl = db.collection('stats_nuts')
const cdData = await cdColl.findOne({ userID: interaction.user.id })
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 = {
"high": "https://as2.ftcdn.net/v2/jpg/02/24/65/39/1000_F_224653943_r3xltiwJsK6am0mGZE5DTWk1yocUwHLd.jpg",
"normal": 'https://c8.alamy.com/comp/PPPBXK/surprised-pecan-nuts-pile-on-plate-cartoon-PPPBXK.jpg',
"low": 'https://as2.ftcdn.net/v2/jpg/02/24/65/37/1000_F_224653769_ceJk0tq9UT1hSu5FIVUi7BeaN4ucSZGv.jpg',
"none": 'https://cdn4.vectorstock.com/i/1000x1000/87/08/afraid-pecan-nuts-pile-on-plate-cartoon-vector-22028708.jpg',
"onCD": 'https://cdn.discordapp.com/attachments/1152723542836772914/1152987472788193361/No-nuts-PhotoRoom.png-PhotoRoom.png'
}
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
})
const amount = Math.floor(Math.random() * 10)
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
}
);
if (amount) {
content = `Du hast **${amount}** Nüsse bekommen!`
if (amount > 8) {
image = images["high"]
} else if (amount > 4) {
image = images["normal"]
} else {
image = images["low"]
}
} else {
content = `Du hast leider keine Nüsse bekommen :(`
image = images["none"]
}
} else {
content = `Du kannst erst <t:${Math.floor(cdData?.cooldown)}:R> wieder nussen :(`
image = images["onCD"]
await delay(1000)
embed.setDescription(content)
embed.setThumbnail(image)
return await interaction.editReply({
embeds: [embed]
})
}
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 = {
data: new SlashCommandBuilder()
.setName('nuts')
.setDescription('rund um die nuss')
.addSubcommand(s =>
s
.setName('give')
.setDescription('gib nuss!!')
.addUserOption(o => o.setName('target').setDescription('wer bekommt da nuts?').setRequired(true))
.addNumberOption(o => o.setName('amount').setDescription('wie viele?').setRequired(true)))
.addSubcommand(s =>
s
.setName('check')
.setDescription('check out deez nuts')
.addUserOption(o => o.setName('target').setDescription('check out those nuts!')))
.addSubcommand(s =>
s
.setName('leaderboard')
.setDescription('wer hat die dicksten Nüsse?'))
.addSubcommand(s =>
s
.setName('stats')
.setDescription('wie viele Nüsse wurden genusst, Genosse?'))
.addSubcommand(s =>
s
.setName('cooldown')
.setDescription('wie lange bis ich nussen kann?'))
.addSubcommand(s =>
s
.setName('nut')
.setDescription('willst du nuss?')),
async execute(interaction) {
switch (interaction.options._subcommand) {
case 'give':
nutsGive(interaction)
break;
case 'check':
await interaction.deferReply()
nutsCheck(interaction)
break;
case 'leaderboard':
await interaction.deferReply()
nutsLeaderboard(interaction)
break;
case 'stats':
await interaction.deferReply()
nutsStats(interaction)
break;
case 'cooldown':
await interaction.deferReply()
nutsCooldown(interaction)
break;
case 'nut':
await interaction.deferReply()
nutsNut(interaction)
break;
default:
break;
}
}
}
+395
View File
@@ -0,0 +1,395 @@
/*
Random By Year?
Counter (Leaderboard)
*/
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, UserSelectMenuBuilder, MessageFlags } = require('discord.js')
const { mClient } = require('../../../index')
require('dotenv').config()
function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
async function quotesAdd(interaction) {
const messageLink = await interaction.options.getString('link')
//regex for message link
const regex = /^https:\/\/discord\.com\/channels\/\d+\/\d+\/\d+$/
if (!messageLink.match(regex)) {
return await interaction.editReply({
content: `Invalid URL`,
flags: MessageFlags.Ephemeral
})
}
let temp = messageLink.split('/')
let messageID = temp[temp.length - 1]
let channelID = temp[temp.length - 2]
let guildID = temp[temp.length - 3]
const guild = await interaction.client.guilds.fetch(guildID)
const channel = await guild.channels.fetch(channelID)
const message = await channel.messages.fetch(messageID)
var msgData = {
content: message.content,
author: await message.author,
reference: await message.reference,
embed: await message.embeds ? 'embed' : null
} // debug
if (msgData.reference) {
let refGuild = await interaction.client.guilds.fetch(msgData.reference.guildId)
let refChannel = await refGuild.channels.fetch(msgData.reference.channelId)
let refMessage = await refChannel.messages.fetch(msgData.reference.messageId)
var refData = {
content: refMessage.content,
author: await refMessage.author,
embed: await refMessage.embeds.length > 0 ? 'embed' : null
}
}
const db = mClient.db(process.env.M_DB)
const quotesColl = db.collection('items_quotes')
const found = await quotesColl.findOne({ messageID: messageID })
if (found) { return await interaction.editReply({ content: 'Quote Already in Database', flags: MessageFlags.Ephemeral }) }
await quotesColl.findOneAndUpdate({ messageID: messageID }, {
$set: {
messageID: messageID,
channelID: channelID,
guildID: guildID,
by: msgData.author.id,
count: 0
}
}, { upsert: true })
var description = ''
if (refData) {
description += `> ${refData.author}`
if (refData.embed) {
description += '*an embed / a command* '
} else {
description += refData.content
}
description += `\r\n`
}
description += `${msgData.author} ${msgData.content}\r\n\r\n${messageLink}`
let timestamp = new Date(message.createdTimestamp)
let footer = timestamp.toDateString().toString()
const embed = new EmbedBuilder()
.setThumbnail(msgData.author.displayAvatarURL())
.setURL(messageLink)
.setTitle(`- Quote Added! -`)
.setDescription(description)
.setFooter({ text: (footer + ' #' + messageID) })
await interaction.editReply({ embeds: [embed] })
}
async function quotesRemove(interaction) {
const id = await interaction.options.getString('id')
const db = mClient.db(process.env.M_DB)
const quotesColl = db.collection('items_quotes')
const found = await quotesColl.findOne({ messageID: id })
if (!found) { return await interaction.reply({ content: 'ID not found!', flags: MessageFlags.Ephemeral }) }
await quotesColl.deleteOne({ messageID: id })
return interaction.reply({ content: 'Quote successfully removed!', flags: MessageFlags.Ephemeral })
}
async function quotesSearch(interaction) {
const id = interaction.options.getString("id")
const db = mClient.db(process.env.M_DB)
const quotesColl = db.collection('items_quotes')
const found = await quotesColl.findOne({ messageID: id })
if (!found) { return await interaction.reply({ content: 'ID not found!', flags: MessageFlags.Ephemeral }) }
const guild = await interaction.client.guilds.fetch(found.guildID)
const channel = await guild.channels.fetch(found.channelID)
const message = await channel.messages.fetch(found.messageID)
var msgData = {
content: message.content,
author: await message.author,
reference: await message.reference,
embed: await message.embeds ? 'embed' : null
} // debug
quotesColl.findOneAndUpdate({
messageID: found.messageID
}, {
$inc: { count: 1 }
}, {
upsert: true
})
if (msgData.reference) {
let refMessage = await channel.messages.fetch(msgData.reference.messageId)
var refData = {
content: refMessage.content,
author: await refMessage.author,
embed: await refMessage.embeds.length > 0 ? 'embed' : null
}
}
var description = ''
if (refData) {
description += `> ${refData.author}`
if (refData.embed) {
description += '*an embed / a command* '
} else {
description += refData.content
}
description += `\r\n`
}
let messageLink = `https://discord.com/channels/${found.guildID}/${found.channelID}/${found.messageID}`
description += `${msgData.author} ${msgData.content}\r\n\r\n${messageLink}`
let timestamp = new Date(message.createdTimestamp)
let footer = timestamp.toDateString().toString()
const embed = new EmbedBuilder()
.setThumbnail(msgData.author.displayAvatarURL())
.setURL(messageLink)
.setTitle(`- Quote Found! -`)
.setDescription(description)
.setFooter({ text: (footer + ' #' + found.messageID) })
await interaction.reply({ embeds: [embed] })
}
async function quotesRandom(interaction) {
var user = interaction.options.getUser("by")
const db = mClient.db(process.env.M_DB)
const quotesColl = db.collection('items_quotes')
var rdm
if (user) {
rdm = await quotesColl.aggregate([
{
$match: { by: user.id },
}, {
$sample: { size: 1 }
}
]).toArray()
} else {
rdm = await quotesColl.aggregate([
{
$sample: { size: 1 }
}
]).toArray()
}
const found = rdm[0]
if (!found) { return await interaction.reply({ content: 'Database Empty', flags: MessageFlags.Ephemeral }) }
const guild = await interaction.client.guilds.fetch(found.guildID)
const channel = await guild.channels.fetch(found.channelID)
const message = await channel.messages.fetch(found.messageID)
var msgData = {
content: message.content,
author: await message.author,
reference: await message.reference,
embed: await message.embeds ? 'embed' : null
} // debug
quotesColl.findOneAndUpdate({
messageID: found.messageID
}, {
$inc: { count: 1 }
}, {
upsert: true
})
if (msgData.reference) {
let refMessage = await channel.messages.fetch(msgData.reference.messageId)
var refData = {
content: refMessage.content,
author: await refMessage.author,
embed: await refMessage.embeds.length > 0 ? 'embed' : null
}
}
var description = ''
if (refData) {
description += `> ${refData.author}`
if (refData.embed) {
description += '*an embed / a command* '
} else {
description += refData.content
}
description += `\r\n`
}
let messageLink = `https://discord.com/channels/${found.guildID}/${found.channelID}/${found.messageID}`
description += `${msgData.author} ${msgData.content}\r\n\r\n${messageLink}`
let timestamp = new Date(message.createdTimestamp)
let footer = timestamp.toDateString().toString()
const embed = new EmbedBuilder()
.setThumbnail(msgData.author.displayAvatarURL())
.setURL(messageLink)
.setTitle(`- Quote Found! -`)
.setDescription(description)
.setFooter({ text: (footer + ' #' + found.messageID) })
await interaction.reply({ embeds: [embed] })
}
async function quotesList(interaction) {
const embed = new EmbedBuilder()
.setTitle('- Quotes List! -')
.setDescription('- Choose someone below to filter by User')
.setThumbnail(interaction.guild.iconURL())
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setEmoji(``)
.setCustomId('quotes_list_left')
.setStyle(ButtonStyle.Primary)
)
.addComponents(
new ButtonBuilder()
.setEmoji(``)
.setCustomId('abort')
.setStyle(ButtonStyle.Primary)
)
.addComponents(
new ButtonBuilder()
.setEmoji(``)
.setCustomId('quotes_list_right')
.setStyle(ButtonStyle.Primary)
)
const select = new ActionRowBuilder()
.addComponents(
new UserSelectMenuBuilder()
.setCustomId('quotes_list_mentionable')
.setPlaceholder('Filter by User')
)
await interaction.reply({
embeds: [embed],
components: [select, row],
flags: MessageFlags.Ephemeral
})
}
async function quotesLeaderboard(interaction) {
const db = mClient.db(process.env.M_DB)
const quotesColl = db.collection('items_quotes')
let skip = 0
const minValue = 0
const maxValue = await quotesColl.countDocuments({ $and: [{ guildID: interaction.guild.id }, { count: { $gt: 0 } }] })
const quotesData = await quotesColl.find({}).sort({ count: -1, messageID: -1 }).skip(skip).limit(5).toArray()
const fields = []
const guild = await interaction.client.guilds.fetch(interaction.guild.id)
quotesData.forEach(async (data, index) => {
let channel = await guild.channels.fetch(data.channelID)
let message = await channel.messages.fetch(data.messageID)
await delay(500)
let timestamp = new Date(message.createdTimestamp)
fields.push({
name: `${index + 1}.`,//`\u200b` ,
value: `[#${data.messageID}](https://discord.com/channels/${data.guildID}/${data.channelID}/${data.messageID})\r\n**by** <@${data.by}> • ⭐ ${data.count}\r\n_Posted on **${timestamp}**_\r\n${message.content}`
})
})
await delay(5000)
console.log(fields)
quotesData.sort((a,b) => {
const numA = parseInt(a.name);
const numB = parseInt(b.name);
return numA - numB;
})
console.log(fields)
const embed = new EmbedBuilder()
.setTitle('- Quotes Leaderboard -')
.setThumbnail('https://cdn.discordapp.com/attachments/1152723542836772914/1152940755539722240/pngwing.com.png')
.setFields(fields)
.setColor('#5865F2') // Discord's blurple color
.setFooter({ text: `Use ◄ ► to navigate\r\n${skip}` });
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setLabel('◄')
.setStyle(ButtonStyle.Primary)
.setCustomId('quotes_leaderboard_left')
)
.addComponents(
new ButtonBuilder()
.setLabel('X')
.setStyle(ButtonStyle.Danger)
.setCustomId('abort')
)
.addComponents(
new ButtonBuilder()
.setLabel('►')
.setStyle(ButtonStyle.Primary)
.setCustomId('quotes_leaderboard_right')
)
await interaction.editReply({
embeds: [embed],
components: [row]
})
}
module.exports = {
data: new SlashCommandBuilder()
.setName('quotes')
.setDescription('quoten pfoten')
.addSubcommand(s =>
s
.setName('add')
.setDescription('add a new quote')
.addStringOption(o => o.setName('link').setDescription('insert message link').setRequired(true)))
.addSubcommand(s =>
s
.setName('remove')
.setDescription('remove a quote')
.addStringOption(o => o.setName('id').setDescription('insert message ID').setRequired(true)))
.addSubcommand(s =>
s
.setName('search')
.setDescription('search by ID')
.addStringOption(o => o.setName('id').setDescription('insert message ID').setRequired(true)))
.addSubcommand(s =>
s
.setName('random')
.setDescription('get a random quote')
.addUserOption(o => o.setName('by').setDescription('by user')))
.addSubcommand(s =>
s
.setName('leaderboard')
.setDescription('see the most used quotes'))
.addSubcommand(s =>
s
.setName('list')
.setDescription('[ADMIN] list all quotes')),
async execute(interaction) {
switch (interaction.options._subcommand) {
case 'add':
await interaction.deferReply()
quotesAdd(interaction)
break;
case 'remove':
quotesRemove(interaction)
break;
case 'search':
quotesSearch(interaction)
break;
case 'random':
quotesRandom(interaction)
break;
case 'leaderboard':
await interaction.deferReply()
quotesLeaderboard(interaction)
break;
case 'list':
quotesList(interaction)
break;
default:
break;
}
}
}
View File
View File
View File
View File
View File
View File