Přídán komand "najditext"

This commit is contained in:
Histmy 2024-01-06 23:53:48 +01:00
parent bb9c7af9d4
commit 399945ae8a
5 changed files with 101 additions and 41 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "denim_3001",
"version": "3001.55.0",
"version": "3001.56.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "denim_3001",
"version": "3001.55.0",
"version": "3001.56.0",
"license": "ISC",
"dependencies": {
"@discordjs/voice": "^0.16.1",

View File

@ -1,6 +1,6 @@
{
"name": "denim_3001",
"version": "3001.55.0",
"version": "3001.56.0",
"description": "Toto je velmi kvalitní bot.",
"repository": {
"url": "https://github.com/Histmy/Denim-Bot/"

View File

@ -7,9 +7,12 @@ 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 { array, record, safeParse, string } from "valibot";
const guildy = new Map<string, { kju: { name: string; url: string; }[]; loop: boolean; }>();
const searchScema = array(record(string(), string()));
async function playNext(guildId: string, seek?: number) {
try {
const guilda = guildy.get(guildId)!;
@ -164,6 +167,43 @@ const exp: Modul = {
return `lup je ${guilda.loop ? "zapnutej" : "ukoncen"}`;
}
},
najditext: {
DMUnsafe: true,
run: async mes => {
const kju = guildy.get(mes.guildId!)?.kju;
if (!kju?.length) return "nehraje nic";
const query = kju[0].name.split("-")[1] ?? kju[0].name;
const res = await fetch(`https://search.karaoketexty.cz/index.php?q=${query}`)
.then(res => res.text())
.catch(log);
const json = res ? JSON.parse(res.slice(1, -1)) : [];
const vyhledavani = safeParse(searchScema, json);
if (!vyhledavani.success) return "KaraokeTexty se na mi visarly";
const vysledek = vyhledavani.output[0];
if (!vysledek) return "KaraokeTexty nic nenasli";
const res2 = await fetch(`https://www.karaoketexty.cz/texty-pisni/h/h-${vysledek.id}`)
.then(res => res.text())
.catch(log);
if (!res2) return "KaraokeTexty mi tekst nedali";
let text = "";
for (const radek of res2.matchAll(/<span class="para_1.+?">(.+?)<\/span>/gs)) {
text += `${radek[1].replace(/<br \/>/g, "")}\n`;
}
return text;
},
}
}
};

View File

@ -71,12 +71,6 @@ const sendGmMessage = async (user: User, rictCas?: boolean) => {
return `${zacatek}\nspal sy ${formatedCas}\n${zpr}`;
};
function hmsToCislo(reg: RegExpExecArray | null) {
if (!reg || reg.input == "") return NaN;
const g = reg.groups!;
return (Number(g.h) * 3600 || 0) + (Number(g.m) * 60 || 0) + (Number(g.s) || 0);
}
function handleSpink(stav: Spinky, uzivatel: User) {
for (const [, guild] of uzivatel.client.guilds.cache) {
const member = guild.members.cache.get(uzivatel.id);
@ -115,6 +109,35 @@ function handleSpink(stav: Spinky, uzivatel: User) {
}
}
function strToDate(str: string) {
const cas = new Date();
const dnes = new Date();
let neco: RegExpExecArray | null;
// Relativní čas
neco = /^(?:(?<h>\d+)h)?(?:(?<m>\d+)m)?(?:(?<s>\d+)s?)?$/.exec(str.toLowerCase());
if (neco) {
if (str == "") return [];
const g = neco.groups!;
return ["rel", ((Number(g.h) * 3600 || 0) + (Number(g.m) * 60 || 0) + (Number(g.s) || 0)) * 1000] as const;
}
// Absolutní čas
neco = /^((?<d>\d+)\. ?((?<mo>\d+)\.)? ?)?(?<h>\d+)(:(?<m>\d+)(:(?<s>\d+))?)? ?(?<p>am|pm)?$/.exec(str.toLowerCase());
if (neco) {
const g = neco.groups!;
if (g.d) cas.setDate(Number(g.d));
if (g.mo) cas.setMonth(Number(g.mo) - 1);
const h = Number(g.h);
cas.setHours(g.p == "pm" && h < 12 ? h + 12 : h);
cas.setMinutes(Number(g.m) || 0);
cas.setSeconds(Number(g.s) || 0);
if (Number(cas) < Number(dnes)) cas.setDate(dnes.getDate() + 1);
return ["abs", Number(cas) - Number(dnes)] as const;
}
return [];
}
const exp: Modul = {
more_komandy: {
@ -146,42 +169,35 @@ const exp: Modul = {
run: (mes, kdy) => {
if (mes.author.bot) return emouty.sjeta;
const ted = new Date();
const tedT = Number(ted);
const spink = new Date();
// Random výplod GitHub Copilota
if (kdy == "fejk") {
mes.react(emouty.lukiw);
return "fejk spinkacek";
}
let druh = "";
let spinkZa: number;
let random = false;
if (kdy.startsWith("random")) {
random = true;
let rozdil = 540;
let min = 60;
let rozdil = 540_000;
let min = 60_000;
if (kdy.length > 7) {
const zadani = kdy.slice(7).replace(/ /g, "").split("-");
if (zadani.length != 2) return "cos to napsal kkte";
const regex = /^(?:(?<h>\d+)h)?(?:(?<m>\d+)m)?(?:(?<s>\d+)s?)?$/;
const [from, to] = [regex.exec(zadani[0]), regex.exec(zadani[1])].map(v => hmsToCislo(v));
if (Number.isNaN(from) || Number.isNaN(to)) return "cislo musy bit v formate xh xm xs";
if (to <= from) return "ja teda nevim jestli ti vys jak funguje cas ael vym ze tam mas chibu";
const str = kdy.toLowerCase().slice(7).replace(/ /g, "").split("-");
if (str.length != 2) return "cos to napsal kkte";
const [from, to] = [strToDate(str[0]), strToDate(str[1])];
if (!from.length || !to.length) return "cos to napsal kkte";
if (to[1] <= from[1]) return "ja teda nevim jestli ti vys jak funguje cas ael vym ze tam mas chibu";
rozdil = to - from;
min = from;
rozdil = to[1] - from[1];
min = from[1];
}
spink.setTime(tedT + (Math.random() * rozdil + min) * 1000);
log(`random spink pro ${oddiakritikovat(mes.member?.displayName || "neznamejmeno")} byl nastaven na ${formatter(spink)}`);
} else if (/^\d+$/.test(kdy) || !kdy)
spink.setTime(tedT + Number(kdy || 7200) * 1000);
else {
const cojavim = /^((?<d>\d+)\. ?((?<mo>\d+)\.)? ?)?(?<h>\d+)(:(?<m>\d+)(:(?<s>\d+))?)? ?(?<p>am|pm)?$/.exec(kdy.toLowerCase());
if (!cojavim) return `cos to tam napsal ty kokote?`;
const g = cojavim.groups!;
if (g.d) spink.setDate(Number(g.d));
if (g.mo) spink.setMonth(Number(g.mo) - 1);
const h = Number(g.h);
spink.setHours(g.p == "pm" && h < 12 ? h + 12 : h);
spink.setMinutes(Number(g.m) || 0);
spink.setSeconds(Number(g.s) || 0);
if (Number(spink) < tedT) spink.setDate(ted.getDate() + 1);
spinkZa = (Math.random() * rozdil + min);
log(`random spink pro ${oddiakritikovat(mes.member?.displayName || "neznamejmeno")} byl nastaven na ${formatter(Date.now() + spinkZa)}`);
} else {
[druh, spinkZa] = strToDate(kdy);
if (typeof spinkZa != "number") return "cos to napsal kkte";
}
ifUzRemove(mes.author.id);
@ -189,8 +205,11 @@ const exp: Modul = {
budouciSpinky[mes.author.id] = setTimeout(() => {
contactSpinkServer(Spinky.spinkacek, mes.author);
mes.react(emouty.spinkacek);
}, Number(spink) - tedT);
if (!random) return `tvuj spinkacek byl naplanovan na ${formatter(spink)}`;
}, spinkZa);
if (!random) {
if (druh == "abs") return `tvuj spinkacek byl naplanovan na za ${formatCas(spinkZa / 1000)}`;
else return `tvuj spinkacek byl naplanovan na ${formatter(Date.now() + spinkZa)}`;
}
mes.react(emouty.lajk);
}
},

View File

@ -144,7 +144,8 @@ const exp: Modul = {
try {
await zpracovatZpravu(mes);
} catch (e) {
log(e);
if (!(e instanceof Error && e.message.includes("ER_DUP_ENTRY")))
log(e);
log("general sync ukoncen");
return;
}