88 lines
2.5 KiB
JavaScript
88 lines
2.5 KiB
JavaScript
const { Client } = require('discord.js');
|
|
const fs = require("fs");
|
|
|
|
const client = new Client();
|
|
require('dotenv').config();
|
|
|
|
const prefix = process.env.PREFIX || 'more';
|
|
const modulFolder = "./modules/";
|
|
const eventy = { on_message: [] };
|
|
const komandy = {};
|
|
const aliasy = {};
|
|
let spink = false;
|
|
|
|
const runEvent = (name, args) => {
|
|
eventy[name].forEach(listener => {
|
|
listener(...args);
|
|
});
|
|
};
|
|
|
|
fs.readdirSync(modulFolder).forEach(function (soubor) {
|
|
if (soubor.endsWith(".js")) {
|
|
const modul = require(`${modulFolder}${soubor}`);
|
|
modul.client = client;
|
|
Object.keys(modul).forEach(name => {
|
|
if (name.startsWith('on_')) {
|
|
if (!eventy[name]) {
|
|
eventy[name] = [];
|
|
if (name !== 'on_message') client.on(name.substring(3), (...args) => runEvent(name, args));
|
|
}
|
|
eventy[name].push(modul[name]);
|
|
} else if (name === 'more_komandy') {
|
|
Object.keys(modul[name]).forEach(cmdName => {
|
|
const value = modul[name][cmdName];
|
|
if (typeof value !== "object") {
|
|
komandy[cmdName] = value;
|
|
return;
|
|
}
|
|
komandy[cmdName] = value.run;
|
|
value.als?.forEach(al => aliasy[al] = cmdName);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
const spim = mes => {
|
|
if (mes.content.toLowerCase() === `${prefix} zapni se`) {
|
|
if (spink) {
|
|
spink = false;
|
|
mes.client.user.setStatus("online");
|
|
mes.channel.send("dobré ráno magoří");
|
|
}
|
|
else mes.channel.send("tak jsi kokot?");
|
|
} else if (!spink) {
|
|
if (mes.content.toLowerCase() === `${prefix} vypni se`) {
|
|
mes.react("855120055632134155");
|
|
[...mes.client.voice?.connections.values()].forEach(con => con.disconnect());
|
|
mes.client.user.setStatus("invisible");
|
|
spink = true;
|
|
}
|
|
else return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
client.on("message", function (mes) {
|
|
if (process.env.IGNORE_MESS || spim(mes)) return;
|
|
|
|
runEvent('on_message', [mes]);
|
|
const [mes_prefix, komand, ...args] = mes.content.split(' ');
|
|
if (mes_prefix.toLowerCase() !== prefix) return;
|
|
if (!komand) return mes.channel.send("coe voe");
|
|
|
|
const celArgs = args.join(' ');
|
|
const cmd = aliasy[komand] ?? komand;
|
|
const akce = komandy[cmd];
|
|
if (!akce) return mes.channel.send("co to znamena ti gadzovko");
|
|
if (typeof akce === "string") return mes.channel.send(akce);
|
|
const result = akce(celArgs, mes);
|
|
if (!result || !result.then) mes.channel.send(result);
|
|
});
|
|
|
|
client.on("debug", console.log);
|
|
client.on("error", console.error);
|
|
client.on("warn", console.warn);
|
|
|
|
client.login(process.env.TOKEN);
|