Muzika z internetu a souboru, yoyoyo

This commit is contained in:
Histmy 2024-01-11 16:29:55 +01:00
parent 7d59b73064
commit fb352dbe91
Signed by: Histmy
GPG Key ID: AC2E43C463D8F329
4 changed files with 53 additions and 31 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ res/customAliasy.json
zaznamy.dlog
zvuky/priVstupu
logs
.data

4
package-lock.json generated
View File

@ -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",

View File

@ -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/"

View File

@ -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<string, { kju: { name: string; url: string; }[]; loop: boolean; }>();
type QueueItem = {
name: string;
url: string;
special?: true;
};
const guildy = new Map<string, { kju: QueueItem[]; loop: boolean; }>();
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 });