const { token } = require('./config.json'); const { Client, Events, GatewayIntentBits, Collection, EmbedBuilder, Partials } = require('discord.js'); const fs = require('fs'); const path = require('path'); const cron = require('node-cron'); const axios = require('axios'); // Set your channel IDs here const channelId = '979663671536009227'; const resultsChannelId = '1268988748604113052'; // Add your desired channel ID const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.DirectMessages, GatewayIntentBits.GuildMessageTyping ], partials: [Partials.Message, Partials.Channel, Partials.Reaction] }); // Weather Report Cron Job client.commands = getCommands(path.join(__dirname, 'commands')); client.once(Events.ClientReady, () => { console.log('The bot has started successfully!'); cron.schedule('0 2 * * *', async () => { try { const weatherData = await fetchWeatherData(); const channel = await client.channels.fetch(channelId); if (channel) { for (const data of weatherData) { await channel.send({ embeds: [data.embed] }); } } else { console.error('Channel not found!'); } } catch (error) { console.error('Error fetching weather data:', error); } }); }); // Harry Potter quiz logic const questions = [ { question: "Melyik helyzetben éreznéd magad leginkább bátornak?", options: { A: "Megvédeni egy barátot", B: "Kiállni a véleményed mellett", C: "Új kihívások elé nézni", D: "Segíteni másoknak" } }, { question: "Milyen szerepet játszol a baráti kapcsolataidban?", options: { A: "Mindig támogatom őket, függetlenül a helyzettől", B: "Megosztom velük a véleményem, még ha az néha nehéz is", C: "Szívesen segítek, ha problémáik vannak", D: "Mindig bátorítom őket, hogy kövessék az álmaikat" } }, { question: "Mi a legfontosabb számodra a jövőben?", options: { A: "Céljaim elérése", B: "Mások segítése", C: "Felfedezni az új dolgokat", D: "Stabil és biztonságos élet" } }, { question: "Hogyan közelítesz meg egy nehéz feladatot?", options: { A: "Átgondolom a lehetőségeket", B: "Kérdezek másokat a tapasztalataikról", C: "Elkezdem, és közben tanulok", D: "Rendszerezetten elemzem a helyzetet" } } ]; client.on(Events.MessageCreate, async (message) => { if (message.partial) { try { message = await message.fetch(); } catch (error) { console.error('Could not fetch the message:', error); return; } } if (message.content.toLowerCase() === '!startquiz') { message.author.send(`Áhh... Mr | Ms ${message.author.username}! Lássuk, mely házba kerülsz pár rövid kérdéssel!`).catch(console.error); let index = 0; const answers = []; const askQuestion = async () => { if (index < questions.length) { const question = questions[index]; const embed = new EmbedBuilder() .setTitle(`Kérdés ${index + 1}`) .setDescription(question.question) .addFields( { name: "A", value: question.options.A }, { name: "B", value: question.options.B }, { name: "C", value: question.options.C }, { name: "D", value: question.options.D } ) .setColor("Random"); await message.author.send({ embeds: [embed] }); const filter = (response) => { return ["A", "B", "C", "D"].includes(response.content.toUpperCase()) && response.author.id === message.author.id; }; try { const collected = await message.author.dmChannel.awaitMessages({ filter, max: 1, time: 60000, errors: ['time'] }); const answer = collected.first().content.toUpperCase(); answers.push(answer); index++; await askQuestion(); // Ask the next question } catch (error) { // Time-related error handling if (error instanceof Collection) { await message.author.send("Időtúllépés történt. Kérlek, indítsd újra a kérdőívet a !startquiz paranccsal."); } else { // Log actual errors (if any) console.error("Unexpected error:", error); } return; } } else { const resultsChannel = await client.channels.fetch(resultsChannelId); if (resultsChannel) { const resultEmbed = new EmbedBuilder() .setTitle("Kérdőív Eredmény") .setDescription(`${message.author.username} válaszai a következőek voltak:`) .addField("Válaszok", answers.join(', ')) .addField("Idő", new Date().toLocaleString()) .setColor("Random"); resultsChannel.send({ embeds: [resultEmbed] }); await message.author.send("Gratulálok! A moderátoraink nemsokára megnézik, hogy milyen házban leszel!"); } else { console.error('Results channel not found!'); } } }; await askQuestion(); } }); // Weather functionality remains unchanged client.on(Events.InteractionCreate, async interaction => { if (!interaction.isCommand()) return; const command = client.commands.get(interaction.commandName); if (!command) return; try { await command.execute(interaction); } catch (error) { console.error(error); await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); } }); client.login(token); function getCommands(dir) { const commands = new Collection(); const commandFiles = getFiles(dir); for (const commandFile of commandFiles) { try { const command = require(commandFile); if (command.data && typeof command.data === 'object') { commands.set(command.data.name, command); } else { console.error(`Failed to load command ${commandFile}: No 'data' property found.`); } } catch (error) { console.error(`Failed to load command ${commandFile}:`, error); } } return commands; } function getFiles(dir) { const files = fs.readdirSync(dir, { withFileTypes: true }); let commandFiles = []; for (const file of files) { if (file.isDirectory()) { commandFiles = [ ...commandFiles, ...getFiles(path.join(dir, file.name)), ]; } else if (file.name.endsWith('.js')) { commandFiles.push(path.join(dir, file.name)); } } return commandFiles; } // Emoji assignment for weather descriptions function getWeatherEmoji(description) { if (description.includes('derült')) return '☀️'; if (description.includes('felhős')) return '⛅'; if (description.includes('borult')) return '☁️'; if (description.includes('eső')) return '🌧️'; if (description.includes('zápor')) return '🌦️'; if (description.includes('hó')) return '❄️'; if (description.includes('vihar')) return '🌩️'; if (description.includes('köd')) return '🌫️'; if (description.includes('szél')) return '🌬️'; return ''; } async function fetchWeatherData() { const apiKey = '3935757f8a8329766edb2ed5219a2e11'; const cities = ['Budapest', 'Debrecen', 'Szeged', 'Pécs', 'Miskolc']; const weatherReports = []; for (const city of cities) { try { const response = await axios.get(`http://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}&units=metric`); const data = response.data; const embed = new EmbedBuilder() .setTitle(`Időjárás ${data.name} városában`) .setDescription(`Jelenlegi időjárás: ${data.weather[0].description}`) .addFields( { name: 'Hőmérséklet', value: `${data.main.temp} °C` }, { name: 'Szélsebesség', value: `${data.wind.speed} m/s` }, { name: 'Páratartalom', value: `${data.main.humidity}%` } ) .setColor("Random") .setFooter({ text: `Adatok gyűjtve: ${new Date().toLocaleString()}` }); weatherReports.push({ city, embed }); } catch (error) { console.error(`Weather data fetch error for ${city}:`, error); } } return weatherReports; }