From 33204267ac182edf277d7fb898296d5c81058602 Mon Sep 17 00:00:00 2001 From: det-fys Date: Fri, 12 Mar 2021 23:25:18 +0100 Subject: [PATCH] Update app.js --- app.js | 69 +++++++++++++++++++++------------------------------------- 1 file changed, 25 insertions(+), 44 deletions(-) diff --git a/app.js b/app.js index d4a42df..a260e24 100644 --- a/app.js +++ b/app.js @@ -4,59 +4,40 @@ const client = new Client(); require('dotenv').config(); const prefix = process.env.PREFIX || 'more'; -const role = {online: '684443816383610916', idle: '684444083065978941', dnd: '684444020558135399', offline: '684443903759614049', onlinephone: '777989420728975390'}; -const spostece = ['mares', 'mareš', 'purfie', 'denim', '<@!639142938965704745>']; -const emouty = ['purfiek3:616026189269696512', 'purfiek3:616026189269696512', 'purfiek3:616026189269696512', 'purfieUchyl:576487602203525138', 'bafW:574646319696576532', 'purfiek4:616026180889477258']; -const modules = [require('./modules/help'), require('./modules/hovna'), require('./modules/normal'), require('./modules/status'), require('./modules/vojs')]; +const nazvyEventu = ["ready", "presenceUpdate", "voiceStateUpdate"]; +const modulFolder = "./moduly/"; -const rand = max => Math.floor(Math.random() * max); +const fs = require("fs"); -client.on('ready', () => console.log('A jedeš!')); +let moduly = []; -client.on('message', mes => { - if (process.env.IGNORE_MESS) return; - - const [mes_prefix, komand, ...args] = mes.content.toLowerCase().split(' '); - if (mes_prefix === prefix) { - const celArgs = args.join(' '); - for (let i = 0; i < modules.length; i++) { - if (modules[i](mes, komand, celArgs)) break; - if (i === modules.length - 1) mes.channel.send('co to znamena ti gadzovko'); +fs.readdirSync(modulFolder).forEach(function (soubor) { + if (soubor.endsWith(".js")) { + moduly.push(require(modulFolder + soubor)); } - } - - let sance = 0; - spostece.forEach(sp => { - if (mes.content.toLowerCase().includes(sp)) sance++; - }); - if (rand(3) < sance) mes.react(emouty[rand(emouty.length)]); }); -client.on('presenceUpdate', (bef, aft) => { - if (aft.guild.id !== '555779161067749446' || process.env.IGNORE_PRESENCE) return; +for (let i = 0; i < nazvyEventu.length; i++) { + discord.on(nazvyEventu[i], function (...args) { udelejEvent(nazvyEventu[i], ...args); }); +} - if (!bef) bef = {status: 'offline', clientStatus: {}}; - if (bef.clientStatus.mobile === 'online' && bef.clientStatus.desktop !== 'online') bef.status = 'onlinephone'; - if (aft.clientStatus.mobile === 'online' && aft.clientStatus.desktop !== 'online') aft.status = 'onlinephone'; - if (bef.status === aft.status) return; - - aft.member.roles.add(role[aft.status]); - aft.member.roles.remove(role[bef.status]); -}); - -client.on('voiceStateUpdate', (bef, aft) => { - if (!aft.channel || !aft.guild.voice || aft.member.user === client.user) return; - if (aft.mute && !aft.deaf) { - if (!aft.guild.voice.connection) aft.setDeaf(true, 'otposlouchávala ta gadza'); - else { - aft.guild.voice.connection.play('./zvuky/neodposlouchavej.ogg', { volume: 0.38 }) - .on('finish', () => {if (aft.mute) aft.setDeaf(true, 'otposlouchávala ta gadza')}); +discord.on("message", function (mes) { + udelejEvent("message", mes); + const [mes_prefix, komand, ...args] = mes.content.toLowerCase().split(' '); + if (mes_prefix === prefix) { + if (!udelejEvent("on_more_subkomand", komand, args)) mes.channel.send('co to znamena ti gadzovko'); } - } - - if (!bef.channel) return; - if (bef.mute && bef.deaf && !aft.mute && aft.deaf) aft.setDeaf(false, 'us muze poslouchat gadza'); }); +function udelejEvent(nazev, ...args) { + for (let i = 0; i < moduly.length; i++) { + const funkce = moduly[i]["on_" + nazev]; + if (funkce) { + if (funkce(...args)) return true; + } + } + return false; +} + client.login(process.env.TOKEN);