pgn random with range
This commit is contained in:
parent
e5aa5847e8
commit
24d25403c0
@ -69,6 +69,12 @@ const tovjemamvolepreceroliky = async (roliky: User) => {
|
|||||||
return `dobry rano hajzle ${roliky}\nspal sy ${formatedCas}\n${zpr}`;
|
return `dobry rano hajzle ${roliky}\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);
|
||||||
|
}
|
||||||
|
|
||||||
const exp: Modul = {
|
const exp: Modul = {
|
||||||
more_komandy: {
|
more_komandy: {
|
||||||
|
|
||||||
@ -103,9 +109,24 @@ const exp: Modul = {
|
|||||||
const spink = new Date();
|
const spink = new Date();
|
||||||
let random = false;
|
let random = false;
|
||||||
|
|
||||||
if (kdy == "random") {
|
if (kdy.startsWith("random")) {
|
||||||
random = true;
|
random = true;
|
||||||
spink.setSeconds(Math.random() * 540 + 60);
|
let rozdil = 540;
|
||||||
|
let min = 60;
|
||||||
|
if (kdy.length > 7) {
|
||||||
|
const t = kdy.slice(7).replace(/ /g, "").split("-");
|
||||||
|
if (t.length != 2) return "cos to napsal kkte";
|
||||||
|
const regex = /^(?:(?<h>\d+)h)?(?:(?<m>\d+)m)?(?:(?<s>\d+)s?)?$/;
|
||||||
|
const [from, to] = [regex.exec(t[0]), regex.exec(t[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";
|
||||||
|
|
||||||
|
console.log("vybiram mezi", from, "a", to);
|
||||||
|
|
||||||
|
rozdil = to - from;
|
||||||
|
min = from;
|
||||||
|
}
|
||||||
|
spink.setTime(tedT + (Math.random() * rozdil + min) * 1000);
|
||||||
log(`random spink pro ${oddiakritikovat(mes.member?.displayName || "neznamejmeno")} byl nastaven na ${formatter(spink)}`);
|
log(`random spink pro ${oddiakritikovat(mes.member?.displayName || "neznamejmeno")} byl nastaven na ${formatter(spink)}`);
|
||||||
} else if (/^\d+$/.test(kdy) || !kdy)
|
} else if (/^\d+$/.test(kdy) || !kdy)
|
||||||
spink.setTime(tedT + Number(kdy || 7200) * 1000);
|
spink.setTime(tedT + Number(kdy || 7200) * 1000);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user