absolute pgn
This commit is contained in:
parent
52e159ad34
commit
a56efb1442
@ -7,6 +7,7 @@ import { Spinkackar } from "../utils/types";
|
|||||||
import { formatCas } from "../utils/utils";
|
import { formatCas } from "../utils/utils";
|
||||||
|
|
||||||
const spinkacky: string[] = [];
|
const spinkacky: string[] = [];
|
||||||
|
const budouciSpinky: Record<string, NodeJS.Timeout> = {};
|
||||||
|
|
||||||
const contactSpinkServer = async (akce: string, id: string, nick: string = "", avatar: string | null = "") => {
|
const contactSpinkServer = async (akce: string, id: string, nick: string = "", avatar: string | null = "") => {
|
||||||
const options = `heslo=${process.env.spinkPass}&akce=${akce}&id=${id}&nick=${encodeURIComponent(nick)}&avatar=${encodeURIComponent(avatar ?? "")}`;
|
const options = `heslo=${process.env.spinkPass}&akce=${akce}&id=${id}&nick=${encodeURIComponent(nick)}&avatar=${encodeURIComponent(avatar ?? "")}`;
|
||||||
@ -40,8 +41,14 @@ module.exports = {
|
|||||||
als: ["spink", "spoink", "spinkake", "spoinkacek", "gn"],
|
als: ["spink", "spoink", "spinkake", "spoinkacek", "gn"],
|
||||||
run: async (_: any, mes: Message) => {
|
run: async (_: any, mes: Message) => {
|
||||||
if (mes.author.bot) return `až někdy${emouty.kapp}`;
|
if (mes.author.bot) return `až někdy${emouty.kapp}`;
|
||||||
if (await contactSpinkServer('spinkacek', mes.author.id, mes.author.username, mes.author.avatarURL()) === "OK")
|
if (await contactSpinkServer('spinkacek', mes.author.id, mes.author.username, mes.author.avatarURL()) === "OK") {
|
||||||
mes.react(emouty.spinkacek);
|
mes.react(emouty.spinkacek);
|
||||||
|
const uz = budouciSpinky[mes.author.id];
|
||||||
|
if (uz) {
|
||||||
|
clearTimeout(uz);
|
||||||
|
delete budouciSpinky[mes.author.id];
|
||||||
|
}
|
||||||
|
}
|
||||||
else return 'nespis uz?????';
|
else return 'nespis uz?????';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -69,12 +76,34 @@ module.exports = {
|
|||||||
pgn: (kdy: string, mes: Message) => {
|
pgn: (kdy: string, mes: Message) => {
|
||||||
if (mes.author.bot) return emouty.sjeta;
|
if (mes.author.bot) return emouty.sjeta;
|
||||||
|
|
||||||
const zaJakDlouho = Number(kdy) * 1000 || 7_200_000;
|
const ted = new Date();
|
||||||
const datum = new Date(Number(new Date()) + zaJakDlouho);
|
const tedT = Number(ted);
|
||||||
|
const spink = new Date();
|
||||||
const formatter = new Intl.DateTimeFormat("cs", { day: "numeric", month: "short", hour: "numeric", minute: "numeric", second: "numeric" });
|
const formatter = new Intl.DateTimeFormat("cs", { day: "numeric", month: "short", hour: "numeric", minute: "numeric", second: "numeric" });
|
||||||
|
|
||||||
setTimeout(() => contactSpinkServer("spinkacek", mes.author.id, mes.author.username, mes.author.avatarURL()), zaJakDlouho);
|
if (/^\d+$/.test(kdy) || !kdy)
|
||||||
return `Tvuj spinkacek byl naplanovan na ${formatter.format(datum)}`;
|
spink.setTime(tedT + Number(kdy || 7200) * 1000);
|
||||||
|
else {
|
||||||
|
const cojavim = /^((?<d>\d+)\. ?((?<mo>\d+)\.)? ?)?(?<h>\d+):(?<m>\d+)(:(?<s>\d+))?$/.exec(kdy);
|
||||||
|
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);
|
||||||
|
spink.setHours(Number(g.h));
|
||||||
|
spink.setMinutes(Number(g.m));
|
||||||
|
spink.setSeconds(Number(g.s) || 0);
|
||||||
|
if (Number(spink) < tedT) return "to uz bylo ty magore";
|
||||||
|
}
|
||||||
|
|
||||||
|
const uzPgn = budouciSpinky[mes.author.id];
|
||||||
|
if (uzPgn) {
|
||||||
|
clearTimeout(uzPgn);
|
||||||
|
delete budouciSpinky[mes.author.id];
|
||||||
|
}
|
||||||
|
|
||||||
|
budouciSpinky[mes.author.id] = setTimeout(() => contactSpinkServer("spinkacek", mes.author.id, mes.author.username, mes.author.avatarURL()), Number(spink) - tedT);
|
||||||
|
return `tvuj spinkacek byl naplanovan na ${formatter.format(spink)}`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user