Denim-Bot/modules/spink.js

96 lines
3.0 KiB
JavaScript

// Modul dedikovaný funkci spinkáček
const fetch = require('node-fetch');
const { formatCas } = require("../addons/utils.js");
const spinkacky = [];
const contactSpinkServer = async (akce, id, nick, avatar) => {
const options = `heslo=${process.env.SPINK_PASS}&akce=${akce}&id=${id}&nick=${encodeURIComponent(nick)}&avatar=${encodeURIComponent(avatar)}`;
return await fetch(`https://spinkacek.ga/extapi.php?${options}`)
.then(r => r.text())
.then(text => text);
};
const syncSpink = async () => {
await fetch('https://spinkacek.ga/api/spinkacky')
.then(r => r.json())
.then(d => {
const data = d.spinkacky;
const keys = Object.keys(data);
const values = Object.values(data);
spinkacky.splice(0);
for (let i = 0; i < keys.length; i++) {
if (!values[i].spinkacek || keys[i][0] === 'i') continue;
spinkacky.push(keys[i].slice(8));
}
});
};
syncSpink();
module.exports = {
more_komandy: {
spinkacek: {
als: ["spinkáček"],
run: (_, mes) => {
if (mes.author.bot) return "až někdy<:kapp:677916836418813953>";
(async () => {
if (await contactSpinkServer('spinkacek', mes.author.id, mes.author.username, mes.author.avatarURL()) === "OK")
mes.react("761652251966046208");
else mes.channel.send('nespis uz?????');
})();
}
},
vstavacek: {
als: ["vstáváček"],
run: (_, mes) => {
if (mes.author.bot) return "<:sjeta:623216247953424426>";
(async () => {
const odpoved = await contactSpinkServer('vstavacek', mes.author.id);
const [ok, cas] = odpoved.split(" ");
if (ok !== "OK") {
mes.channel.send("uz jsi vzhuru ty hajzle");
return;
}
const formatedCas = formatCas(cas);
let zpr = "";
if (cas < 3600) zpr = "dobrej fake spink debile";
else if (cas > 35999 && cas < 43200) zpr = "fakt bídák";
else if (cas > 43199 && cas < 57600) zpr = "extrémní bídák";
else if (cas > 57599) zpr = "mas dat more vstavacek uz kdyz vstanes retarde";
mes.channel.send(`dobry rano hajzle\nspal sy ${formatedCas}\n${zpr}`);
})();
}
}
},
on_voiceStateUpdate: (bef, aft) => {
if (!aft.channel || bef.channel) return;
if (spinkacky.includes(aft.id)) aft.kick()
.catch(() => { });
},
on_message: mes => {
if (mes.author.id === '831318260493844494') {
syncSpink();
if (mes.content[0] !== 's') return;
const uzivatel = mes.content.match(/(?<=discord_)\d+/)?.[0];
if (!uzivatel) return;
for (const [_, guild] of mes.client.guilds.cache) {
for (const [_, channel] of guild.channels.cache) {
if (channel.type !== "voice") continue;
for (const [_, member] of channel.members) {
if (member.id !== uzivatel) continue;
member.voice.kick("spinkacek");
return;
}
}
}
}
}
};