diff --git a/package-lock.json b/package-lock.json index 7532279..3255289 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "denim_3001", - "version": "3001.21.1", + "version": "3001.22.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "denim_3001", - "version": "3001.21.1", + "version": "3001.22.0", "license": "ISC", "dependencies": { "@discordjs/opus": "github:discordjs/opus", diff --git a/package.json b/package.json index 364b155..8079f0e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "denim_3001", - "version": "3001.21.1", + "version": "3001.22.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 63d4052..f48f44e 100644 --- a/src/modules/vojs.ts +++ b/src/modules/vojs.ts @@ -3,7 +3,8 @@ import { getVoiceConnection, VoiceConnection, VoiceConnectionStatus } from "@discordjs/voice"; import { GuildMember, Message, VoiceChannel } from "discord.js"; import { emouty } from "../utils/emotes"; -import { joinVoice, leave, play } from "../utils/utils"; +import { MuzikaFace } from "../utils/types"; +import { handlePrevVoice, joinVoice, play } from "../utils/utils"; const timeouty: Record = {}; @@ -115,9 +116,49 @@ module.exports = { const { conn, prev } = await joinVoice(channel); await play(conn, "zvuky/grg.mp3"); - if (prev === true) return; // Byl jsem v tomdle vojsu - if (prev === false) return leave(mes.guildId!); // Nebyl jsem ve vojsu vůbec - joinVoice(prev as string, mes.guild!); // Byl jsem jinde + handlePrevVoice(mes.guild!, prev); + } + }, + + cas: { + cd: 5, + run: async (_: any, mes: Message) => { + const date = new Date(); + const h = date.getHours(); + const m = date.getMinutes(); + const pre = "zvuky/cas/"; + + const addSuffix = (prefix: string, hodnota: number) => { + const koncovka = hodnota == 1 ? "a" : hodnota > 1 && hodnota < 5 ? "y" : ""; + return `${prefix}${koncovka}`; + }; + const rozdelAPridej = (cislo: number) => { + if (cislo == 2) return zvuky.push({ name: `${pre}dvě.mp3`, volume: 2.5 }); + if (cislo < 20) return zvuky.push({ name: `${pre}${cislo}.mp3`, volume: 2.5 }); + const text = String(cislo); + zvuky.push({ name: `${pre}${text[0]}0.mp3`, volume: 2.5 }); + if (text[1] != "0") zvuky.push({ name: `${pre}${text[1]}.mp3`, volume: 2.5 }); + }; + + const hod = addSuffix("hodin", h); + const min = addSuffix("minut", m); + const je = h > 1 && h < 5 ? "jsou" : "je"; + + const channel = mes.member?.voice.channel; + if (!channel) return mes.channel.send(`${je} ${h} ${hod} ${m} ${min}`); + + const zvuky: MuzikaFace[] = [{ name: `${pre}${je}.mp3`, volume: 2.5 }]; + + rozdelAPridej(h); + zvuky.push({ name: `${pre}${hod}.mp3`, volume: 2.5 }); + if (m > 0) { + rozdelAPridej(m); + zvuky.push({ name: `${pre}${min}.mp3`, volume: 2.5 }); + } + + const { conn, prev } = await joinVoice(channel); + await play(conn, zvuky); + handlePrevVoice(mes.guild!, prev); } } } diff --git a/src/utils/types.ts b/src/utils/types.ts index b22b6e3..74e72d2 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -46,5 +46,5 @@ export interface ZmenovejObjekt { export interface MuzikaFace { name: string, - volume?: number; + volume: number; } diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 43c891f..7ff9b30 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -47,7 +47,7 @@ export const oddiakritikovat = (a: string) => { .replace(/[Ŵ]/g, "W") .replace(/[ÝŶŸ]/g, "Y") .replace(/[ŹŻŽ]/g, "Z"); -} +}; export const formatCas = (cas: number) => { const h = Math.floor(cas / 3600); @@ -63,9 +63,16 @@ export const joinVoice = async (channel: VoiceChannel | StageChannel | string, g const guilda = typeof channel === "string" ? guild! : channel.guild; let conn = getVoiceConnection(guildId); - let prev: Boolean | string = false; + let prev: boolean | string = false; if (conn) { - if (conn.joinConfig.channelId === channelId) return { conn, prev: true }; + if (conn.joinConfig.channelId === channelId) { + await entersState(conn, VoiceConnectionStatus.Ready, 3e4) + .catch(err => { + conn!.destroy(); + throw err; + }); + return { conn, prev: true }; + } prev = conn.joinConfig.channelId!; } @@ -91,53 +98,57 @@ export const joinVoice = async (channel: VoiceChannel | StageChannel | string, g const makeAudioPlayer = (co: string | MuzikaFace) => { if (typeof co === "string") return createAudioResource(co); - const res = createAudioResource(co.name, { inlineVolume: !!co.volume }); - if (co.volume) res.volume?.setVolume(co.volume); + const res = createAudioResource(co.name, { inlineVolume: true }); + res.volume?.setVolume(co.volume); return res; }; -export const play = (conn: VoiceConnection, co: string | MuzikaFace | MuzikaFace[]) => { - return new Promise(async (res, rej) => { - if (conn.state.status !== VoiceConnectionStatus.Ready) return rej("conn není ready"); +export const play = (conn: VoiceConnection, co: string | string[] | MuzikaFace | MuzikaFace[]) => new Promise(async (res, rej) => { + if (conn.state.status !== VoiceConnectionStatus.Ready) return rej("conn není ready"); - const player = pripojeni[conn.joinConfig.guildId].player; - if (!Array.isArray(co)) { - let aud = makeAudioPlayer(co); - player.play(aud); - const funkce = () => { - res(); - player.removeListener(AudioPlayerStatus.Idle, funkce); - }; - player.on(AudioPlayerStatus.Idle, funkce); - return; - } - - const resources: AudioResource[] = []; - co.forEach(c => { - const res = makeAudioPlayer(c); - resources.push(res); - }); - for (const res of resources) { - await once(res.playStream, "readable"); - } - player.play(resources[0]); - - let i = 1; + const player = pripojeni[conn.joinConfig.guildId].player; + if (!Array.isArray(co)) { + let aud = makeAudioPlayer(co); + player.play(aud); const funkce = () => { - player.play(resources[i]); - i++; - if (i === resources.length) { - res(); - player.removeListener(AudioPlayerStatus.Idle, funkce); - } + res(); + player.removeListener(AudioPlayerStatus.Idle, funkce); }; player.on(AudioPlayerStatus.Idle, funkce); - }); -}; + return; + } -export const leave = (guildId: string) => { + const resources: AudioResource[] = []; + co.forEach(c => { + const res = makeAudioPlayer(c); + resources.push(res); + }); + for (const res of resources) { + await once(res.playStream, "readable"); + } + player.play(resources[0]); + + let i = 0; + const funkce = () => { + i++; + if (i === resources.length) { + res(); + player.removeListener(AudioPlayerStatus.Idle, funkce); + } + else player.play(resources[i]); + }; + player.on(AudioPlayerStatus.Idle, funkce); +}); + +const leave = (guildId: string) => { const conn = getVoiceConnection(guildId); if (!conn) return; conn.destroy(); delete pripojeni[guildId]; }; + +export const handlePrevVoice = (guild: Guild, prev: boolean | string) => { + if (prev === true) return; // Byl jsem v tomdle vojsu + if (prev === false) return leave(guild.id); // Nebyl jsem ve vojsu vůbec + joinVoice(prev, guild); // Byl jsem jinde +}; diff --git a/zvuky/bez_se_zabit.mp3 b/zvuky/bez_se_zabit.mp3 new file mode 100644 index 0000000..9da330c Binary files /dev/null and b/zvuky/bez_se_zabit.mp3 differ diff --git a/zvuky/cas/0.mp3 b/zvuky/cas/0.mp3 new file mode 100644 index 0000000..db20e5b Binary files /dev/null and b/zvuky/cas/0.mp3 differ diff --git a/zvuky/cas/1.mp3 b/zvuky/cas/1.mp3 new file mode 100644 index 0000000..c666f31 Binary files /dev/null and b/zvuky/cas/1.mp3 differ diff --git a/zvuky/cas/10.mp3 b/zvuky/cas/10.mp3 new file mode 100644 index 0000000..0eb3922 Binary files /dev/null and b/zvuky/cas/10.mp3 differ diff --git a/zvuky/cas/11.mp3 b/zvuky/cas/11.mp3 new file mode 100644 index 0000000..27c1b93 Binary files /dev/null and b/zvuky/cas/11.mp3 differ diff --git a/zvuky/cas/12.mp3 b/zvuky/cas/12.mp3 new file mode 100644 index 0000000..7bac07a Binary files /dev/null and b/zvuky/cas/12.mp3 differ diff --git a/zvuky/cas/13.mp3 b/zvuky/cas/13.mp3 new file mode 100644 index 0000000..f851725 Binary files /dev/null and b/zvuky/cas/13.mp3 differ diff --git a/zvuky/cas/14.mp3 b/zvuky/cas/14.mp3 new file mode 100644 index 0000000..83cd415 Binary files /dev/null and b/zvuky/cas/14.mp3 differ diff --git a/zvuky/cas/15.mp3 b/zvuky/cas/15.mp3 new file mode 100644 index 0000000..5b5a177 Binary files /dev/null and b/zvuky/cas/15.mp3 differ diff --git a/zvuky/cas/16.mp3 b/zvuky/cas/16.mp3 new file mode 100644 index 0000000..d0e0533 Binary files /dev/null and b/zvuky/cas/16.mp3 differ diff --git a/zvuky/cas/17.mp3 b/zvuky/cas/17.mp3 new file mode 100644 index 0000000..2326eb8 Binary files /dev/null and b/zvuky/cas/17.mp3 differ diff --git a/zvuky/cas/18.mp3 b/zvuky/cas/18.mp3 new file mode 100644 index 0000000..772596d Binary files /dev/null and b/zvuky/cas/18.mp3 differ diff --git a/zvuky/cas/19.mp3 b/zvuky/cas/19.mp3 new file mode 100644 index 0000000..4ec6fc4 Binary files /dev/null and b/zvuky/cas/19.mp3 differ diff --git a/zvuky/cas/2.mp3 b/zvuky/cas/2.mp3 new file mode 100644 index 0000000..363a6ed Binary files /dev/null and b/zvuky/cas/2.mp3 differ diff --git a/zvuky/cas/20.mp3 b/zvuky/cas/20.mp3 new file mode 100644 index 0000000..041811f Binary files /dev/null and b/zvuky/cas/20.mp3 differ diff --git a/zvuky/cas/3.mp3 b/zvuky/cas/3.mp3 new file mode 100644 index 0000000..465ee74 Binary files /dev/null and b/zvuky/cas/3.mp3 differ diff --git a/zvuky/cas/30.mp3 b/zvuky/cas/30.mp3 new file mode 100644 index 0000000..99412e1 Binary files /dev/null and b/zvuky/cas/30.mp3 differ diff --git a/zvuky/cas/4.mp3 b/zvuky/cas/4.mp3 new file mode 100644 index 0000000..66366f0 Binary files /dev/null and b/zvuky/cas/4.mp3 differ diff --git a/zvuky/cas/40.mp3 b/zvuky/cas/40.mp3 new file mode 100644 index 0000000..6becb19 Binary files /dev/null and b/zvuky/cas/40.mp3 differ diff --git a/zvuky/cas/5.mp3 b/zvuky/cas/5.mp3 new file mode 100644 index 0000000..403af42 Binary files /dev/null and b/zvuky/cas/5.mp3 differ diff --git a/zvuky/cas/50.mp3 b/zvuky/cas/50.mp3 new file mode 100644 index 0000000..9ad54a0 Binary files /dev/null and b/zvuky/cas/50.mp3 differ diff --git a/zvuky/cas/6.mp3 b/zvuky/cas/6.mp3 new file mode 100644 index 0000000..3e350ce Binary files /dev/null and b/zvuky/cas/6.mp3 differ diff --git a/zvuky/cas/7.mp3 b/zvuky/cas/7.mp3 new file mode 100644 index 0000000..26d01dc Binary files /dev/null and b/zvuky/cas/7.mp3 differ diff --git a/zvuky/cas/8.mp3 b/zvuky/cas/8.mp3 new file mode 100644 index 0000000..4b8da62 Binary files /dev/null and b/zvuky/cas/8.mp3 differ diff --git a/zvuky/cas/9.mp3 b/zvuky/cas/9.mp3 new file mode 100644 index 0000000..bb3f932 Binary files /dev/null and b/zvuky/cas/9.mp3 differ diff --git a/zvuky/cas/dvě.mp3 b/zvuky/cas/dvě.mp3 new file mode 100644 index 0000000..7c5825d Binary files /dev/null and b/zvuky/cas/dvě.mp3 differ diff --git a/zvuky/cas/hodin.mp3 b/zvuky/cas/hodin.mp3 new file mode 100644 index 0000000..84b5b27 Binary files /dev/null and b/zvuky/cas/hodin.mp3 differ diff --git a/zvuky/cas/hodina.mp3 b/zvuky/cas/hodina.mp3 new file mode 100644 index 0000000..5093896 Binary files /dev/null and b/zvuky/cas/hodina.mp3 differ diff --git a/zvuky/cas/hodiny.mp3 b/zvuky/cas/hodiny.mp3 new file mode 100644 index 0000000..269effc Binary files /dev/null and b/zvuky/cas/hodiny.mp3 differ diff --git a/zvuky/cas/je.mp3 b/zvuky/cas/je.mp3 new file mode 100644 index 0000000..da15dc7 Binary files /dev/null and b/zvuky/cas/je.mp3 differ diff --git a/zvuky/cas/jsou.mp3 b/zvuky/cas/jsou.mp3 new file mode 100644 index 0000000..adb4a88 Binary files /dev/null and b/zvuky/cas/jsou.mp3 differ diff --git a/zvuky/cas/minut.mp3 b/zvuky/cas/minut.mp3 new file mode 100644 index 0000000..826f774 Binary files /dev/null and b/zvuky/cas/minut.mp3 differ diff --git a/zvuky/cas/minuta.mp3 b/zvuky/cas/minuta.mp3 new file mode 100644 index 0000000..90425bf Binary files /dev/null and b/zvuky/cas/minuta.mp3 differ diff --git a/zvuky/cas/minuty.mp3 b/zvuky/cas/minuty.mp3 new file mode 100644 index 0000000..f03751a Binary files /dev/null and b/zvuky/cas/minuty.mp3 differ