From fb352dbe913df9f023e94e7974fa7e43cfdcb26b Mon Sep 17 00:00:00 2001 From: Histmy Date: Thu, 11 Jan 2024 16:29:55 +0100 Subject: [PATCH] Muzika z internetu a souboru, yoyoyo --- .gitignore | 1 + package-lock.json | 4 +-- package.json | 2 +- src/modules/muzika.ts | 77 +++++++++++++++++++++++++++---------------- 4 files changed, 53 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index eea6965..65bceaa 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ res/customAliasy.json zaznamy.dlog zvuky/priVstupu logs +.data diff --git a/package-lock.json b/package-lock.json index 61d9ac7..99101e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "denim_3001", - "version": "3001.57.0", + "version": "3001.58.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "denim_3001", - "version": "3001.57.0", + "version": "3001.58.0", "license": "ISC", "dependencies": { "@discordjs/voice": "^0.16.1", diff --git a/package.json b/package.json index a1c1489..30d27a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "denim_3001", - "version": "3001.57.0", + "version": "3001.58.0", "description": "Toto je velmi kvalitní bot.", "repository": { "url": "https://github.com/Histmy/Denim-Bot/" diff --git a/src/modules/muzika.ts b/src/modules/muzika.ts index bf90786..92d1af5 100644 --- a/src/modules/muzika.ts +++ b/src/modules/muzika.ts @@ -2,14 +2,20 @@ import { AudioPlayerStatus, VoiceConnectionStatus } from "@discordjs/voice"; import { Client } from "discord.js"; -import { search, soundcloud, stream, validate, video_basic_info } from "play-dl"; +import { search, spotify, stream, validate, video_basic_info } from "play-dl"; import { emouty } from "../utils/emotes"; import { Modul } from "../utils/types"; import { adminLog, log } from "../utils/utils"; -import { getConn, novejJoin, novejPlay, Priority, stopPlayer } from "../utils/voice"; +import { getConn, Hratelny, novejJoin, novejPlay, Priority, stopPlayer } from "../utils/voice"; import { array, record, safeParse, string } from "valibot"; -const guildy = new Map(); +type QueueItem = { + name: string; + url: string; + special?: true; +}; + +const guildy = new Map(); const searchScema = array(record(string(), string())); @@ -19,8 +25,15 @@ async function playNext(guildId: string, seek?: number) { const kju = guilda.kju; const item = kju[0]; - const src = await stream(item.url, { seek }); - novejPlay(guildId, { src: src.stream, volume: 1, type: src.type }, Priority.Music) + let coZahrat: Hratelny; + if (!item.special) { + const src = await stream(item.url, { seek }); + coZahrat = { src: src.stream, volume: 1, type: src.type }; + } else { + coZahrat = item.url; + } + + novejPlay(guildId, coZahrat, Priority.Music) .then(state => { if (state.status != AudioPlayerStatus.Idle) return; @@ -51,36 +64,44 @@ const exp: Modul = { if (!kanel) return "nejsi ve vojsu ty kkt"; const guildId = mes.guildId!; - const ajtem = { name: "", url: "" }; + const ajtem: QueueItem = { name: "", url: "" }; + const druh = await validate(txt); - if (druh && druh != "search") { - if (druh != "yt_video" && druh != "so_track") return "tuto neumim zahrat"; + const soubor = mes.attachments.first(); + if (soubor) { + ajtem.name = soubor.name; + ajtem.url = soubor.url; + ajtem.special = true; + mes.channel.send(`zahraju \`${soubor.name}\``); + } else if (txt == "") return "co mam zahrat??"; + else if (!druh) { + ajtem.name = `nejaka picovina ot ${mes.author}`; ajtem.url = txt; - if (druh == "yt_video") { - try { - const video = await video_basic_info(txt); - ajtem.name = video.video_details.title!; - } catch (e) { - return "sorka bracho ael tuto je ajdzreztrigtnuti"; - } - if (typeof ajtem.name == "undefined") { - const client: Client = module.exports.client; - adminLog(client, "video nemá název"); - } - mes.channel.send(`zahraju \`${ajtem.name}\``); - } else { - const sound = await soundcloud(txt); - ajtem.name = sound.name; - mes.channel.send(`zahraju \`${ajtem.name}\``); - } - } else { + ajtem.special = true; + mes.channel.send(`zkusim to zahrat`); + } + else if (druh == "search" || druh == "sp_track") { const msg = mes.channel.send("hledam"); - const hledani = await search(txt, { limit: 1 }); + const hledacek = druh == "search" ? txt : (await spotify(txt)).name; + const hledani = await search(hledacek, { limit: 1 }); if (!hledani[0]) return "nic sem nenašel"; ajtem.url = hledani[0].url; ajtem.name = hledani[0].title!; msg.then(m => void m.edit(`zahraju \`${ajtem.name}\``)); - } + } else if (druh == "yt_video") { + ajtem.url = txt; + try { + const video = await video_basic_info(txt); + ajtem.name = video.video_details.title!; + } catch (e) { + return "sorka bracho ael tuto je ajdzreztrigtnuti"; + } + if (typeof ajtem.name == "undefined") { + const client: Client = module.exports.client; + adminLog(client, "video nemá název"); + } + mes.channel.send(`zahraju \`${ajtem.name}\``); + } else return "tuto neumim zahrat"; if (!guildy.has(guildId)) { guildy.set(guildId, { kju: [], loop: false });