72 lines
1.8 KiB
JavaScript
72 lines
1.8 KiB
JavaScript
const { SlashCommandBuilder, AttachmentBuilder, EmbedBuilder } = require('discord.js');
|
|
const fs = require('fs/promises');
|
|
const path = require('path');
|
|
|
|
async function makeDay() {
|
|
const date = new Date();
|
|
|
|
const tage = [
|
|
'sonntag',
|
|
'montag',
|
|
'dienstag',
|
|
'mittwoch',
|
|
'donnerstag',
|
|
'freitag',
|
|
'samstag'
|
|
];
|
|
|
|
const text = {
|
|
montag: 'Es ist Montag meine Münmler!',
|
|
mittwoch: 'Es ist Mittwoch meine Kerle!',
|
|
donnerstag: 'Es ist nicht mehr Mittwoch meine Kerle!',
|
|
freitag: 'Es ist Freitag meine Kerl*innen!',
|
|
default: 'Es ist nicht Mittwoch, meine Kerle...'
|
|
};
|
|
|
|
const today = tage[date.getDay()];
|
|
|
|
let files;
|
|
try {
|
|
files = await fs.readdir('assets/Command_Mittwoch');
|
|
} catch (err) {
|
|
console.error(err);
|
|
return { filename: 'nicht_mittwoch', content: text.default };
|
|
}
|
|
|
|
const available = files.map(f => path.parse(f).name);
|
|
|
|
if (available.includes(today)) {
|
|
return {
|
|
filename: today,
|
|
content: text[today] || text.default
|
|
};
|
|
}
|
|
|
|
return {
|
|
filename: 'nicht_mittwoch',
|
|
content: text.default
|
|
};
|
|
}
|
|
module.exports = {
|
|
data: new SlashCommandBuilder()
|
|
.setName('mittwoch')
|
|
.setDescription('mittwoch vibes'),
|
|
|
|
async execute(interaction) {
|
|
const { filename, content } = await makeDay();
|
|
|
|
const filePath = `assets/Command_Mittwoch/${filename}.jpg`;
|
|
|
|
const attachment = new AttachmentBuilder(filePath);
|
|
const embed = new EmbedBuilder()
|
|
.setTitle(content)
|
|
.setColor(0x51267)
|
|
.setTimestamp()
|
|
.setImage(`attachment://${filename}.jpg`);
|
|
|
|
await interaction.reply({
|
|
embeds: [embed],
|
|
files: [attachment]
|
|
});
|
|
}
|
|
}; |