Denim-Bot/modules/vojs.js
2021-07-28 17:58:43 +02:00

194 lines
5.1 KiB
JavaScript

// Cokoliv co má něco společnýho s vojsem
const fs = require('fs');
const { formatCas } = require("../addons/utils.js");
let vojsKuldan = 0;
function vypocitatCas(vojsl) {
let c = new Date();
let d = new Date();
let hod = d.getHours();
let min = d.getMinutes();
if (min >= 30) {
min = 0;
if (hod == 23) {
hod = 0;
d.setDate(c.getDate() + 1);
} else {
hod++;
}
} else {
min = 30;
}
d.setHours(hod);
d.setMinutes(min);
d.setSeconds(0);
timeouty[vojsl.channel.guild.id] = setTimeout(function () {
rekniCas(vojsl, `${nula(hod)}${nula(min)}`);
}, d - c + 3000);
}
function rekniCas(vojsl, cas) {
if (!vojsl) return;
const d1 = vojsl.play(`./zvuky/intro.mp3`, { volume: 0.8 });
d1.on('finish', function () {
const d2 = vojsl.play(`./zvuky/${cas}.mp3`, { volume: 1.5 });
d2.on('finish', function () {
vojsl.play(`./zvuky/grg.mp3`, { volume: 0.5 });
});
});
vypocitatCas(vojsl);
}
function nula(a) {
return a < 10 ? "0" + a : a;
}
const vytahnout = (clen, patro) => {
const vojs = clen.voice.channel;
if (!vojs) return;
const aktPatro = Number(vojs.name) || 0;
let dalsiPatro = aktPatro;
if (patro < aktPatro) dalsiPatro--; else if (patro > aktPatro) dalsiPatro++; else return;
if (dalsiPatro === 0) dalsiPatro = 'P';
const dalsiVojsy = [...clen.guild.channels.cache.values()].filter(channel => channel.type === 'voice' && channel.name === String(dalsiPatro));
if (!dalsiVojsy) return;
clen.voice.setChannel(dalsiVojsy[0]);
setTimeout(() => vytahnout(clen, patro), 1000);
};
const timeouty = {};
module.exports = {
more_komand: (mes, komand, celArgs) => {
switch (komand) {
case 'wojs':
mes.channel.send(`vojs se pise s normalnim v ti kriple ${mes.author}`);
break;
case 'vojs':
const channel = mes.member.voice.channel;
if (!channel) {
mes.channel.send(`di si tam sam ne ty gadzo ${mes.author}`);
break;
}
const rozdil = (Date.now() - vojsKuldan) / 1000;
if (rozdil < 14_400) {
mes.channel.send(`\`${process.env.PREFIX} vojs\` muzes pouzit jyz zua ${formatCas(14_400 - rozdil)}`);
break;
}
vojsKuldan = Date.now();
if (celArgs !== 'potichu') mes.channel.send('<@&591306633196339261> vojs');
if (mes.guild.voice) {
if (mes.guild.voice.channel === channel && mes.guild.voice.connection) break;
}
channel.join()
.then(con => {
if (!timeouty[mes.guild.id]) {
vypocitatCas(con);
con.on('disconnect', () => {
if (timeouty[mes.guild.id]) {
clearTimeout(timeouty[mes.guild.id]);
delete timeouty[mes.guild.id];
}
});
}
setTimeout(() => con.play('./zvuky/nazdar.ogg'), 500);
});
break;
case "odejdi":
case "disconnect":
case "leave":
case "odpoj":
case "votpoj":
case "vodpoj":
case "vodprejskni":
case "tahni":
case "táhni":
case "vypadni":
let vojs = mes.guild.voice;
if (!vojs) vojs = {};
if (!vojs.channel) {
mes.channel.send('nejsem ve vojsu');
break;
}
vojs.channel.leave();
mes.react('855120055632134155');
break;
case 'vitah':
case 'vytah':
if (!mes.member) {
mes.channel.send('kokot');
break;
}
if (!mes.member.voice.channel) {
mes.channel.send(`nejsi ve vojsu ty gadzo ${mes.author}`);
break;
}
if (!celArgs) {
mes.channel.send(`napis do jakiho patra ${mes.author}`);
break;
}
vytahnout(mes.member, Number(celArgs) || 0);
break;
case "krkacek":
case "krkáček":
case "krkácek":
case "krkaček":
case "krk":
case "grg":
case "grgnisi":
case "krknisi":
case "grgacek":
case "grgáček":
case "grgácek":
case "grgaček":
(async _ => {
let vojs = mes.guild.voice?.connection;
let odpojit = false;
if (!vojs) {
const chanel = mes.member.voice.channel;
if (!chanel) return mes.channel.send("***grrrrrrrrg***");
vojs = await chanel.join();
odpojit = true;
}
vojs.play(`./zvuky/grg.mp3`, { volume: 0.5 }).on("finish", _ => { if (odpojit) vojs.channel.leave(); });
})();
break;
default:
return false;
}
return true;
},
// Neodposlouchávej
on_voiceStateUpdate: (bef, aft) => {
if (!aft.channel || !aft.guild.voice?.connection || aft.member.user === aft.guild.client.user) return;
if (aft.selfMute && !aft.deaf) {
aft.guild.voice.connection.play('./zvuky/neodposlouchavej.ogg', { volume: 0.38 })
.on('finish', () => { if (aft.selfMute) aft.setDeaf(true, 'otposlouchávala ta gadza'); });
}
if (!bef.channel) return;
if (bef.mute && bef.deaf && !aft.mute && aft.deaf) aft.setDeaf(false, 'us muze poslouchat gadza');
}
};