89 lines
2.6 KiB
TypeScript
89 lines
2.6 KiB
TypeScript
import { getVoiceConnection } from "@discordjs/voice";
|
|
import { Modul } from "../utils/types";
|
|
import { renameSync, rmSync, readdirSync, writeFileSync } from "fs";
|
|
import { join } from "path";
|
|
import { Priority, novejPlay } from "../utils/voice";
|
|
import { lidiCoMajDenimPremium } from "../utils/denim-Spravce";
|
|
import { exec } from "child_process";
|
|
import { log, send } from "../utils/utils";
|
|
|
|
const kmenovaCesta = join(__dirname, `../../zvuky/priVstupu`);
|
|
const formaty = ["mp3", "wav", "ogg"];
|
|
|
|
function vymaz(path: string) {
|
|
try {
|
|
rmSync(path);
|
|
} catch { }
|
|
}
|
|
|
|
const exp: Modul = {
|
|
more_komandy: {
|
|
|
|
zmenitvstupnizvuk: {
|
|
premium: true,
|
|
run: async mes => {
|
|
|
|
const soubor = mes.attachments.first();
|
|
|
|
if (!soubor) return "tak pico ael na co";
|
|
|
|
if (!formaty.includes(soubor.name.slice(-3))) return "tuten format nechcy";
|
|
if (soubor.size > 2_097_152) return "min nes dva mebagajyt pls";
|
|
|
|
// Stahnout dočasně
|
|
const typ = soubor.name.slice(-3);
|
|
const docasnaCesta = `${kmenovaCesta}/temp${Math.round(Math.random() * 1000)}.${typ}`;
|
|
|
|
const odpoved = await fetch(soubor.url).then(r => r.arrayBuffer());
|
|
writeFileSync(docasnaCesta, new DataView(odpoved));
|
|
|
|
// Zjistit running-time
|
|
exec(`ffprobe -i ${docasnaCesta} -show_entries format=duration -v quiet -of csv="p=0"`, (error, stdout) => {
|
|
if (error) {
|
|
log("chyba pri ffprobe", error);
|
|
|
|
send(mes, "bohuzel chiba");
|
|
vymaz(docasnaCesta);
|
|
return;
|
|
}
|
|
|
|
// Maximum
|
|
if (Number(stdout) > 13) {
|
|
send(mes, "13 se kund maks");
|
|
vymaz(docasnaCesta);
|
|
return;
|
|
}
|
|
|
|
// Smazat starej (nevíme formát, tak musíme zkusit všechny)
|
|
const zaklad = `${kmenovaCesta}/${mes.author.id}`;
|
|
for (const format of formaty) {
|
|
vymaz(`${zaklad}.${format}`);
|
|
}
|
|
|
|
renameSync(docasnaCesta, `${zaklad}.${typ}`);
|
|
|
|
send(mes, "ej tot am");
|
|
});
|
|
}
|
|
}
|
|
},
|
|
|
|
on_voiceStateUpdate: (bef, aft) => {
|
|
const conn = getVoiceConnection(aft.guild.id);
|
|
|
|
// Jestli vůbec zvuk zahrát
|
|
if (!conn || conn.joinConfig.channelId != aft.channelId || !lidiCoMajDenimPremium.includes(aft.id) || !aft.channelId || bef.channelId == aft.channelId) return;
|
|
|
|
// Najít zvuk k přehrání
|
|
for (const soubor of readdirSync(kmenovaCesta)) {
|
|
if (!soubor.startsWith(aft.id)) continue;
|
|
|
|
novejPlay(aft.guild.id, `${kmenovaCesta}/${soubor}`, Priority.Time);
|
|
return;
|
|
}
|
|
|
|
}
|
|
};
|
|
|
|
module.exports = exp;
|