added more ps

This commit is contained in:
Histmy 2021-09-29 21:53:40 +02:00
parent 370caa08d8
commit ce57c640a9
3 changed files with 23 additions and 13 deletions

View File

@ -4,9 +4,9 @@ import { Guild, GuildMember, Message, VoiceState } from "discord.js";
import fetch from "node-fetch";
import { emouty } from "../utils/emotes";
import { Spinkackar } from "../utils/types";
import { formatCas } from "../utils/utils";
import { formatCas, formatter } from "../utils/utils";
const spinkacky: string[] = [];
let spinkacky: Record<string, Spinkackar>;
const budouciSpinky: Record<string, NodeJS.Timeout> = {};
const contactSpinkServer = async (akce: string, id: string, nick: string = "", avatar: string | null = "") => {
@ -17,16 +17,17 @@ const contactSpinkServer = async (akce: string, id: string, nick: string = "", a
const syncSpink = () => {
fetch("https://spinkacek.ga/api/spinkacky")
.then(r => r.json() as Promise<Record<string, Spinkackar>>)
.then(r => r.json() as Promise<{ spinkacky: Record<string, Spinkackar>; }>)
.then(d => {
const data = d.spinkacky;
const keys = Object.keys(data);
const values = Object.values(data);
spinkacky.splice(0);
spinkacky = {};
for (let i = 0; i < keys.length; i++) {
if (!values[i].spinkacek || keys[i][0] === "i") continue;
spinkacky.push(keys[i].slice(8));
const k = keys[i];
if (k[0] != "d") continue;
spinkacky[k.slice(8)] = { spinkacek: values[i].spinkacek, timeup: values[i].timeup * 1000 };
}
});
};
@ -99,7 +100,6 @@ module.exports = {
const ted = new Date();
const tedT = Number(ted);
const spink = new Date();
const formatter = new Intl.DateTimeFormat("cs", { day: "numeric", month: "short", hour: "numeric", minute: "numeric", second: "numeric" });
if (/^\d+$/.test(kdy) || !kdy)
spink.setTime(tedT + Number(kdy || 7200) * 1000);
@ -126,12 +126,19 @@ module.exports = {
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)}`;
},
ps: {
als: ["poslednispink"],
run: (mes: Message) => {
return `naposled si spal ${formatter.format(new Date(spinkacky[mes.author.id].timeup))}`;
}
}
},
on_voiceStateUpdate: (bef: VoiceState, aft: VoiceState) => {
if (!aft.channel || bef.channel) return;
if (spinkacky.includes(aft.id)) aft.disconnect("spinkacek")
if (spinkacky[aft.id]?.spinkacek) aft.disconnect("spinkacek")
.catch(err => console.log("spinkacek odpojit se nepovedlo nebo co:", err));
},
@ -151,7 +158,7 @@ module.exports = {
}
}
}
} else if (spinkacky.includes(mes.author.id) && cmd != "vstavacek") {
} else if (spinkacky[mes.author.id]?.spinkacek && cmd != "vstavacek") {
mes.delete();
(async () => {
const chanel = mes.author.dmChannel ?? await mes.author.createDM();

View File

@ -31,6 +31,7 @@ export interface Komand {
export interface Spinkackar {
spinkacek: boolean;
timeup: number;
}
export interface FakePresence {
@ -47,13 +48,13 @@ export interface UserChange {
export type StatusyINaFounu = "Online" | "OnlinePhone" | "Idle" | "IdlePhone" | "DND" | "DNDPhone" | "Offline";
export interface ZmenovejObjekt {
id: string,
nick?: string,
pfp?: string,
id: string;
nick?: string;
pfp?: string;
status?: string;
}
export interface MuzikaFace {
name: string,
name: string;
volume: number;
}

View File

@ -163,3 +163,5 @@ export function loadEnv() {
if (!existsSync("config.json")) throw new Error("config.json neexistuje");
process.env = { ...process.env, ...require("../../config.json") };
}
export const formatter = new Intl.DateTimeFormat("cs", { day: "numeric", month: "short", hour: "numeric", minute: "numeric", second: "numeric" });