diff --git a/package-lock.json b/package-lock.json index 8a9e17f..2211d16 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "denim_3001", - "version": "3001.60.0", + "version": "3001.60.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "denim_3001", - "version": "3001.60.0", + "version": "3001.60.1", "license": "ISC", "dependencies": { "@discordjs/voice": "^0.17.0", diff --git a/package.json b/package.json index 889d213..00cf660 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "denim_3001", - "version": "3001.60.0", + "version": "3001.60.1", "description": "Toto je velmi kvalitní bot.", "repository": { "url": "https://github.com/Histmy/Denim-Bot/" diff --git a/src/app.ts b/src/app.ts index dab8466..a7b9b2a 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,7 +1,7 @@ import { ButtonStyle, ChannelType, Client, CommandInteraction, GatewayIntentBits, InteractionReplyOptions, Message, Partials } from "discord.js"; import { readdirSync } from "fs"; -import { CUser, KomandNaExport, Komand, ListenerFunkce, Modul, SRecord, SuperListenerFunkce, CClient, HelpServer, KomandRaw } from "./utils/types"; -import { adminLog, formatCas, oddiakritikovat, log, rand, prefix, nabidni, send } from "./utils/utils.js"; +import { CClient, CUser, HelpServer, Komand, KomandNaExport, KomandRaw, ListenerFunkce, Modul, SRecord, SuperListenerFunkce } from "./utils/types"; +import { adminLog, areStatusesSame, formatCas, log, nabidni, oddiakritikovat, prefix, rand, send } from "./utils/utils.js"; import levenshtein from "js-levenshtein"; import { emouty } from "./utils/emotes"; import { lidiCoMajDenimPremium, setClient } from "./utils/denim-Spravce"; @@ -294,14 +294,14 @@ client.on("messageCreate", async mes => { const komandBez = oddiakritikovat(komandSDiakritikou).toLowerCase(); // const cmdName = client.aliasy[komandBez] ?? komandBez; let cmdName = komandBez; - + const aliasCelej = client.aliasy[komandBez]; if (aliasCelej) { const [aliasCmdName, ...aliasArgs] = aliasCelej.split(" "); cmdName = aliasCmdName; args.unshift(...aliasArgs); } - + const celArgs = args.join(" "); if (await runEvent("messageCreate", [mes, cmdName])) return; @@ -344,13 +344,23 @@ client.on("messageCreate", async mes => { }); // Simulation of userPresenceUpdate event -client.on("presenceUpdate", (bef, aft) => { +client.on("presenceUpdate", async (bef, aft) => { const user = aft.user as CUser | null; if (!user) return; if (!user.presence) user.presence = {}; - if (JSON.stringify(aft.clientStatus) == JSON.stringify(user.presence)) return; - user.presence = aft.clientStatus || {}; + if (areStatusesSame(aft.clientStatus, user.presence)) return; + + const naCo = aft.clientStatus || {}; + user.presence = naCo; + + await new Promise(r => setTimeout(r, 1000)); + + if (!areStatusesSame(naCo, user.presence)) { + log("status se rychle nezmenil pro ", user.username, ": ", naCo, " -> ", user.presence); + adminLog(client, "stalo se to"); + return; + } runEvent("userPresenceUpdate", [bef, aft]); }); diff --git a/src/utils/utils.ts b/src/utils/utils.ts index cd57ea1..6a65bdc 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,6 +1,6 @@ /*eslint no-constant-condition: ["error", { "checkLoops": false }]*/ -import { APIEmbed, ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CacheType, ChannelType, Client, ComponentType, Message, MessageCreateOptions, ReadonlyCollection, TextBasedChannel, User } from "discord.js"; +import { APIEmbed, ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CacheType, ChannelType, Client, ClientPresenceStatusData, ComponentType, Message, MessageCreateOptions, ReadonlyCollection, TextBasedChannel, User } from "discord.js"; import { existsSync } from "fs"; import { MysqlError, createPool } from "mysql"; @@ -221,3 +221,24 @@ export async function send(mes: Message, co: string | MessageCreateOptions) { return nova; } + +export const areStatusesSame = (object1?: ClientPresenceStatusData | null, object2?: ClientPresenceStatusData | null) => { + + if ((object1 === null || object1 === undefined) && (object2 === null || object2 === undefined)) return true; + + if (object1 === null || object2 === null || object1 === undefined || object2 === undefined) return false; + + const objKeys1 = Object.keys(object1) as (keyof ClientPresenceStatusData)[]; + const objKeys2 = Object.keys(object2); + + if (objKeys1.length !== objKeys2.length) return false; + + for (const key of objKeys1) { + const value1 = object1[key]; + const value2 = object2[key]; + + if (value1 !== value2) + return false; + } + return true; +};