From e50656706482ebb89b760a2c8cad06897aeb9a40 Mon Sep 17 00:00:00 2001 From: Histmy Date: Sun, 5 Mar 2023 21:39:07 +0100 Subject: [PATCH] better voice pt1 --- src/modules/vojs.ts | 52 +++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/src/modules/vojs.ts b/src/modules/vojs.ts index f244466..910eccf 100644 --- a/src/modules/vojs.ts +++ b/src/modules/vojs.ts @@ -1,7 +1,7 @@ // Cokoliv co má něco společnýho s vojsem import { getVoiceConnection, VoiceConnection, VoiceConnectionStatus } from "@discordjs/voice"; -import { ChannelType, GuildMember, VoiceChannel, VoiceState } from "discord.js"; +import { ChannelType, GuildMember, Message, VoiceChannel, VoiceState } from "discord.js"; import { emouty } from "../utils/emotes"; import { Modul, MuzikaFace, SRecord } from "../utils/types"; import { canAnounceTime, handlePrevVoice, joinVoice, log, play } from "../utils/utils"; @@ -60,6 +60,20 @@ const vytahnout = (member: GuildMember, patro: number) => { setTimeout(() => vytahnout(member, patro), 1e3); }; +async function playAndFukOff(mes: Message, jinak: string, zvuk: string) { + const channel = mes.member?.voice.channel; + if (!channel) return jinak; + + const { conn, prev } = await joinVoice(channel); + + await play(conn, zvuk) + .catch(e => { + log("Pičo chyba při fukofování", e); + }); + + handlePrevVoice(channel.guild, prev); +} + const exp: Modul = { more_komandy: { @@ -117,14 +131,9 @@ const exp: Modul = { krkacek: { als: ["krk", "grg", "grgnisi", "krknisi", "grgacek"], - run: async mes => { - const channel = mes.member?.voice.channel; - if (!channel) return "***grrrrrrrrg***"; + run: async mes => + playAndFukOff(mes, "***grrrrrrrrg***", "zvuky/grg.mp3") - const { conn, prev } = await joinVoice(channel); - await play(conn, "zvuky/grg.mp3"); - handlePrevVoice(mes.guild!, prev); - } }, cas: { @@ -164,33 +173,27 @@ const exp: Modul = { } const { conn, prev } = await joinVoice(channel); - await play(conn, zvuky); + await play(conn, zvuky) + .catch(e => { + log("chyba tady, si to najdi", e); + }); handlePrevVoice(mes.guild!, prev); } }, outro: { hidden: true, - run: async mes => { - const channel = mes.member?.voice.channel; - if (!channel) return "co to znamena ti gadzovko"; + run: async mes => + playAndFukOff(mes, "co to znamena ti gadzovko", "zvuky/pocasi/outro.mp3") - const { conn, prev } = await joinVoice(channel); - await play(conn, { name: "zvuky/pocasi/outro.mp3", volume: 30 }); - handlePrevVoice(mes.guild!, prev); - } }, auto: { - run: async mes => { - const channel = mes.member?.voice.channel; - if (!channel) return "vžum"; + run: async mes => + playAndFukOff(mes, "vžum", "zvuky/auto.ogg") - const { conn, prev } = await joinVoice(channel); - await play(conn, "zvuky/auto.ogg"); - handlePrevVoice(mes.guild!, prev); - } } + }, // Neodposlouchávej @@ -204,6 +207,9 @@ const exp: Modul = { if (!aft.selfMute) return; aft.setDeaf(true, "otposlouchávala ta gadza"); if (!muty.includes(aft.member!.id)) muty.push(aft.member!.id); + }) + .catch(e => { + log("chyb při neodposlouchavej", e); }); }