const { token } = require('./config.json'); const { Client, Events, GatewayIntentBits, Collection, EmbedBuilder } = require('discord.js'); const fs = require('fs'); const path = require('path'); const cron = require('node-cron'); const axios = require('axios'); // Set your channel ID here const channelId = '979663671536009227'; const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.DirectMessages, GatewayIntentBits.GuildMessageTyping ] }); client.commands = getCommands(path.join(__dirname, 'commands')); client.once(Events.ClientReady, () => { console.log('The bot has started successfully!'); // Set up the cron job for weather report cron.schedule('0 2 * * *', async () => { console.log('Sending weather report...'); try { const weatherData = await fetchWeatherData(); const channel = await client.channels.fetch(channelId); if (channel) { await channel.send({ embeds: [weatherData.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" } } ]; const houses = { Gryffindor: ["A", "A", "A", "A"], Slytherin: ["B", "B", "B", "B"], Ravenclaw: ["C", "C", "C", "C"], Hufflepuff: ["D", "D", "D", "D"] }; client.on(Events.MessageCreate, async (message) => { if (message.content.toLowerCase() === '!startquiz') { if (message.guild) { 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]; let 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) => ["A", "B", "C", "D"].includes(response.content.toUpperCase()) && response.author.id === message.author.id; const collected = await message.author.dmChannel.awaitMessages({ filter, max: 1, time: 60000, errors: ['time'] }).catch(() => { message.author.send("Időtúllépés történt. Kérlek, indítsd újra a kérdőívet a `!startquiz` paranccsal."); }); if (collected && collected.first()) { const answer = collected.first().content.toUpperCase(); answers.push(answer); index++; askQuestion(); // Ask the next question } else { message.author.send("Hiba történt a válaszadás során. Kérlek, válaszolj a megadott opciók közül (A, B, C, D)."); } } else { const house = evaluateHouse(answers); message.author.send(`Gratulálok! A válaszaid alapján a(z) ${house} házba kerülsz!`); } }; askQuestion(); } } }); // House evaluation function evaluateHouse(answers) { for (const [house, answerSet] of Object.entries(houses)) { if (JSON.stringify(answers) === JSON.stringify(answerSet)) { return house; } } return "Vegyes házba"; // Default response if not clear } // Weather functionality 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 ''; // Default emoji if no match } async function fetchWeatherData() { const apiKey = ''; // Your API key here const cities = ['Budapest', 'Debrecen', 'Szeged', 'Miskolc', 'Pécs', 'Győr']; const weatherData = []; for (const city of cities) { const url = `http://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}&units=metric&lang=hu`; try { const response = await axios.get(url); const data = response.data; const sunriseTime = new Date(data.sys.sunrise * 1000).toLocaleTimeString('hu-HU', { hour: '2-digit', minute: '2-digit' }); const sunsetTime = new Date(data.sys.sunset * 1000).toLocaleTimeString('hu-HU', { hour: '2-digit', minute: '2-digit' }); weatherData.push({ name: city, temperature: data.main.temp, minTemp: data.main.temp_min, maxTemp: data.main.temp_max, description: getWeatherEmoji(data.weather[0].description) + ' ' + data.weather[0].description, humidity: data.main.humidity, windSpeed: data.wind.speed, sunrise: sunriseTime, sunset: sunsetTime }); } catch (error) { console.error(`Error fetching weather for ${city}:`, error.message); } } const embed = new EmbedBuilder() .setTitle('Időjárás Jelentés') .setDescription('Itt van a legfrissebb időjárás-jelentés városainkra:') .setColor('BLUE') .setTimestamp(); weatherData.forEach(city => { embed.addFields( { name: city.name, value: `Hőmérséklet: ${city.temperature}°C\nMin: ${city.minTemp}°C, Max: ${city.maxTemp}°C\nLeírás: ${city.description}\nPáratartalom: ${city.humidity}%\nSzélsebesség: ${city.windSpeed} m/s\nNapfelkelte: ${city.sunrise}\nNaplemente: ${city.sunset}`, inline: true } ); }); return { embed }; }