Brutální ordinace sjeta
This commit is contained in:
parent
d70abc5092
commit
bc706930b8
@ -1,24 +1,162 @@
|
|||||||
import { GuildScheduledEventEntityType, GuildScheduledEventPrivacyLevel, TextChannel } from "discord.js";
|
import { GuildScheduledEventEntityType, GuildScheduledEventPrivacyLevel, TextChannel } from "discord.js";
|
||||||
import { CClient, Modul } from "../utils/types";
|
import { CClient, Modul } from "../utils/types";
|
||||||
import { log } from "../utils/utils";
|
import { log } from "../utils/utils";
|
||||||
|
import { RawData, WebSocket } from "ws";
|
||||||
|
|
||||||
let client: CClient;
|
let client: CClient;
|
||||||
|
|
||||||
async function ziskatNazev() {
|
const logg = (...cokoli: any[]) => log("[OnePlayTest]: ", ...cokoli);
|
||||||
const stranka = await fetch("https://voyo.nova.cz/api/v1/show/content?showId=1&type=episodes&season=6947&count=1&offset=0&url=%2Fserialy%2F1-ordinace-v-ruzove-zahrade-2")
|
|
||||||
.then(r => r.text())
|
|
||||||
.catch(e => log("chyba pri accessovani VOYO stránky", e));
|
|
||||||
|
|
||||||
const nazevFull = /h3 class=\"title\">.+?>(.+?)<\//s.exec(stranka || "");
|
const token = process.env.OnePlayToken;
|
||||||
|
|
||||||
if (!nazevFull) {
|
let clientId: string | undefined = undefined;
|
||||||
log(new Error("neni nazev"));
|
let sessionId: string | undefined = undefined;
|
||||||
return "Vordinačka";
|
let serverId: string | undefined = undefined;
|
||||||
|
|
||||||
|
function createOneplayBody(payload: Record<string, any>, customData: string) {
|
||||||
|
|
||||||
|
if (typeof clientId == "undefined" || typeof sessionId == "undefined" || typeof serverId == "undefined") {
|
||||||
|
throw new Error("není všechnno nastaveno");
|
||||||
}
|
}
|
||||||
|
|
||||||
const nazevCasti = /(?<cislo>\d+). díl - (?<nazev>.+)/.exec(nazevFull[1]);
|
const vec = {
|
||||||
|
"deviceInfo": {
|
||||||
|
"deviceType": "web",
|
||||||
|
"appVersion": "1.0.18",
|
||||||
|
"deviceManufacturer": "Unknown",
|
||||||
|
"deviceOs": "Windows"
|
||||||
|
},
|
||||||
|
"capabilities": {
|
||||||
|
"async": "websockets"
|
||||||
|
},
|
||||||
|
"payload": payload,
|
||||||
|
"context": {
|
||||||
|
"customData": customData,
|
||||||
|
"requestId": crypto.randomUUID(),
|
||||||
|
"clientId": clientId,
|
||||||
|
"sessionId": sessionId,
|
||||||
|
"serverId": serverId
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return nazevCasti ? `${nazevCasti.groups!.cislo}. ${nazevCasti.groups!.nazev}` : nazevFull[1];
|
return JSON.stringify(vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function udelejOneplayRquest(cesta: string, body: string) {
|
||||||
|
if (!token) {
|
||||||
|
throw new Error("token more");
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await fetch(`https://http.cms.jyxo.cz/api/v3/${cesta}`, {
|
||||||
|
method: "POST",
|
||||||
|
body,
|
||||||
|
headers: { Authorization: token }
|
||||||
|
}).then(res => res.json())
|
||||||
|
.catch(e => { throw new Error(`chyba pri udelejoneplayrequest fetch ${e}`); });
|
||||||
|
|
||||||
|
logg("nejspis uspesna odpoved", res);
|
||||||
|
}
|
||||||
|
|
||||||
|
const sleep = (time: number) => new Promise(res => setTimeout(res, time));
|
||||||
|
|
||||||
|
async function executeOrdinaceFlow() {
|
||||||
|
|
||||||
|
// Inicializace
|
||||||
|
await udelejOneplayRquest("app.init", createOneplayBody({
|
||||||
|
"reason": "start",
|
||||||
|
"route": {
|
||||||
|
"url": "https://www.oneplay.cz/porad/1-ordinace-v-ruzove-zahrade-2"
|
||||||
|
}
|
||||||
|
}, `{"requireStartAction":true}`));
|
||||||
|
|
||||||
|
await sleep(500);
|
||||||
|
|
||||||
|
// Navigace na stránku Ordinace
|
||||||
|
await udelejOneplayRquest("page.content.display", createOneplayBody({
|
||||||
|
contentId: "show.1"
|
||||||
|
}, `{"shouldBeInModal":true}`));
|
||||||
|
|
||||||
|
await sleep(500);
|
||||||
|
|
||||||
|
// Otevření 24. řady
|
||||||
|
await udelejOneplayRquest("carousel.display", createOneplayBody({
|
||||||
|
carouselId: "show:1;tab:65;parent:64;carousel:65",
|
||||||
|
criteria: {
|
||||||
|
filterCriterias: "season:6947",
|
||||||
|
sortOption: "DESC"
|
||||||
|
}
|
||||||
|
}, `{"blockId":"show:1;tab:65;parent:64;block:65"}`));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleMessageAndGetNazev = (socket: WebSocket) => new Promise<string | void>((res, rej) => {
|
||||||
|
const listener = (m: RawData) => {
|
||||||
|
//const mes = m.toString();
|
||||||
|
//logg("data:", mes);
|
||||||
|
|
||||||
|
const json = JSON.parse(m.toString());
|
||||||
|
|
||||||
|
logg("celyjson je", json);
|
||||||
|
|
||||||
|
// if (mes.includes("\"schema\":\"Ping\"")) {
|
||||||
|
// logg("pingec, odpovidam");
|
||||||
|
|
||||||
|
// socket.send(`{"schema":"Pong"}`);
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (json.result?.schema == "ConnectionInitData") {
|
||||||
|
logg("jojo,slysim a jdu na to");
|
||||||
|
serverId = json.data.serverId;
|
||||||
|
sessionId = json.data.sessionId;
|
||||||
|
logg("serverid", serverId, "sessionid", sessionId);
|
||||||
|
executeOrdinaceFlow().catch(rej);
|
||||||
|
}
|
||||||
|
else if (json?.schema == "ApiCall" && json?.command == "carousel.display") {
|
||||||
|
logg("máme tady názvy epizod zvolené série");
|
||||||
|
|
||||||
|
const nazev = json?.response?.data?.carousel?.tiles?.[0]?.title;
|
||||||
|
|
||||||
|
//logg(typeof json, typeof json?.response, typeof json?.response?.data, typeof json?.response?.data?.carousel, typeof json?.response?.data?.carousel?.titles);
|
||||||
|
|
||||||
|
if (!nazev) {
|
||||||
|
return rej("nazev neexistuje");
|
||||||
|
}
|
||||||
|
|
||||||
|
clearTimeout(timeout);
|
||||||
|
socket.off("message", listener);
|
||||||
|
res(nazev);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
socket.off("message", listener); // Odstraníme posluchač
|
||||||
|
rej(new Error("Časový limit vypršel, jméno nebylo přijato."));
|
||||||
|
}, 10000); // Timeout 10 sekund
|
||||||
|
|
||||||
|
|
||||||
|
socket.on("message", listener);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function ziskatNazev() {
|
||||||
|
// Tak tohle stojí fakt za hovno oproti voyu :sjeta:
|
||||||
|
|
||||||
|
clientId = crypto.randomUUID();
|
||||||
|
|
||||||
|
logg("moje Ws id je", clientId);
|
||||||
|
|
||||||
|
let socket: WebSocket | null = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
socket = new WebSocket(`wss://ws.cms.jyxo.cz/websocket/${clientId}`);
|
||||||
|
|
||||||
|
return await handleMessageAndGetNazev(socket);
|
||||||
|
} catch (e) {
|
||||||
|
logg("nazev ordinace se nepodarilo ziskat", e);
|
||||||
|
throw new Error("nazev neni");
|
||||||
|
} finally {
|
||||||
|
socket?.close();
|
||||||
|
logg("zavrel jsem soket");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function naplanovat() {
|
async function naplanovat() {
|
||||||
@ -45,7 +183,7 @@ async function urobit() {
|
|||||||
kdyToBude.setSeconds(0);
|
kdyToBude.setSeconds(0);
|
||||||
|
|
||||||
const event = await guilda.scheduledEvents.create({
|
const event = await guilda.scheduledEvents.create({
|
||||||
name: await ziskatNazev(),
|
name: (await ziskatNazev()) || "Vordinačka",
|
||||||
scheduledStartTime: kdyToBude,
|
scheduledStartTime: kdyToBude,
|
||||||
entityType: GuildScheduledEventEntityType.Voice,
|
entityType: GuildScheduledEventEntityType.Voice,
|
||||||
privacyLevel: GuildScheduledEventPrivacyLevel.GuildOnly,
|
privacyLevel: GuildScheduledEventPrivacyLevel.GuildOnly,
|
||||||
@ -69,7 +207,10 @@ const exp: Modul = {
|
|||||||
on_ready: () => {
|
on_ready: () => {
|
||||||
client = module.exports.client;
|
client = module.exports.client;
|
||||||
|
|
||||||
naplanovat();
|
if (token) {
|
||||||
|
naplanovat();
|
||||||
|
//logg("nazev ordinace je:", await ziskatNazev());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ if (!existsSync("config.json")) throw new Error("config.json neexistuje");
|
|||||||
const konfig = require("../../config.json");
|
const konfig = require("../../config.json");
|
||||||
if (!konfig.ignoreUnknownKeys)
|
if (!konfig.ignoreUnknownKeys)
|
||||||
for (const klic of Object.keys(konfig)) {
|
for (const klic of Object.keys(konfig)) {
|
||||||
if (!["adminChannel", "adminID", "DBPwd", "DBUser", "dieOnError", "ignoreMess", "ignorePresence", "ignoreSpink", "ignoreUnknownKeys", "noGeneralSync", "prefix", "sachyDomena", "statPass", "token"].includes(klic)) throw new Error(`config.json obsahuje neznámý klíč: ${klic}`);
|
if (!["adminChannel", "adminID", "DBPwd", "DBUser", "dieOnError", "ignoreMess", "ignorePresence", "ignoreSpink", "ignoreUnknownKeys", "noGeneralSync", "OnePlayToken", "prefix", "sachyDomena", "statPass", "token"].includes(klic)) throw new Error(`config.json obsahuje neznámý klíč: ${klic}`);
|
||||||
}
|
}
|
||||||
process.env = { ...process.env, ...konfig };
|
process.env = { ...process.env, ...konfig };
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user