From 7ca353fc7f7bbe50f1318cbd9e114960911678de Mon Sep 17 00:00:00 2001 From: Histmy Date: Fri, 4 Nov 2022 16:57:06 +0100 Subject: [PATCH] =?UTF-8?q?NEODPOSLOUCHAVEJ!!-=C2=A7=C2=A7-=C2=A7=C2=A7!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 4 ++-- package.json | 2 +- src/modules/vojs.ts | 24 +++++++++++++++++++++++- src/utils/utils.ts | 8 +++----- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 36f521c..02a1c96 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "denim_3001", - "version": "3001.42.4", + "version": "3001.43.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "denim_3001", - "version": "3001.42.4", + "version": "3001.43.0", "license": "ISC", "dependencies": { "@discordjs/voice": "^0.11.0", diff --git a/package.json b/package.json index 01ab0b1..a89c4c2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "denim_3001", - "version": "3001.42.4", + "version": "3001.43.0", "description": "Toto je velmi kvalitní bot.", "repository": { "url": "https://github.com/Histmy/Denim-Bot/" diff --git a/src/modules/vojs.ts b/src/modules/vojs.ts index 0e57abd..bc2368b 100644 --- a/src/modules/vojs.ts +++ b/src/modules/vojs.ts @@ -1,12 +1,13 @@ // Cokoliv co má něco společnýho s vojsem import { getVoiceConnection, VoiceConnection, VoiceConnectionStatus } from "@discordjs/voice"; -import { ChannelType, GuildMember, VoiceChannel } from "discord.js"; +import { ChannelType, GuildMember, 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"; const timeouty: SRecord = {}; +const muty: string[] = []; const vypocitatCas = (guild: string, conn: VoiceConnection) => { const c = new Date(); @@ -179,6 +180,27 @@ const exp: Modul = { handlePrevVoice(mes.guild!, prev); } } + }, + + // Neodposlouchávej + on_voiceStateUpdate: (bef: VoiceState, aft: VoiceState) => { + const conn = getVoiceConnection(aft.guild.id); + if (!aft.channel || !conn || aft.member?.user.id == aft.client.user?.id) return; + + if (aft.selfMute && !aft.deaf) { + play(conn, { name: "./zvuky/neodposlouchavej.ogg", volume: 0.38 }) + .then(() => { + if (!aft.selfMute) return; + aft.setDeaf(true, "otposlouchávala ta gadza"); + if (!muty.includes(aft.member!.id)) muty.push(aft.member!.id); + }); + } + + if (!bef.channel) return; + if (bef.mute && bef.deaf && !aft.mute && aft.serverDeaf && muty.includes(aft.member!.id)) { + aft.setDeaf(false, "us muze poslouchat gadza"); + muty.splice(muty.indexOf(aft.member!.id), 1); + } } }; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index b251c2a..5337905 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -125,11 +125,7 @@ export const play = (conn: VoiceConnection, co: string | string[] | MuzikaFace | if (!Array.isArray(co)) { const aud = makeAudioPlayer(co); player.play(aud); - const funkce = () => { - res(); - player.removeListener(AudioPlayerStatus.Idle, funkce); - }; - player.on(AudioPlayerStatus.Idle, funkce); + player.once(AudioPlayerStatus.Idle, () => res()); return; } @@ -241,3 +237,5 @@ export const statusOnFoun = (bef: FakePresence | null, aft: FakePresence) => { return predAPo; }; + +export const getGuildConnection = (guildId: string) => pripojeni[guildId]?.connection;