implementace dle dokumentace

This commit is contained in:
Histmy 2024-10-05 18:29:21 +02:00
parent 38f04f3612
commit 7244db314e
Signed by: Histmy
GPG Key ID: AC2E43C463D8F329
4 changed files with 98 additions and 40 deletions

View File

@ -1,30 +0,0 @@
# Dokumentace k logovacímu souboru DLOG verze 3.0
YOYO, čusák lidi! Vítejte u mojí další dokumentace. Tentokrát se podíváme na žhavou novinku: "DLOG verze 3.0"! Ačkoli se může zdát, že tento formát je vylepšení předchozí verze a uchovává data stejného typu, není tomu vůbec tak. Autor (já) byl pouze příliš líný vymýšlet jinou příponu a tak stvořil tuhle prasárnu.
Každopádně dostatek preamblu a jdeme se do toho pustit!
Obsah:
1. [Popis souboru](#popis-souboru)
1. [Header](#header)
## Popis souboru
K čemu že tento formát slouží? V souboru `.dlog` obsahující [header DLOGu verze 3.0](#header) se nachází záznamy o změnách statusů uživatelů Discordu, o kterých má Denim3001 přehled. Data v takto uloženém souboru slouží pro analýzu fekálnosti těchto dat posílaných Discordem. V souboru se nachází několik typů změn statusů, které jsou popsané níže.
## Header
První částí tohoto formátu je header. Ano, je to tak. Skutečně se autor od posledních dvou odpadních formátů poučil a nyní ho nezapoměl specifikovat.
Na headeru není vůbec nic zajímavého. Jedinou informaci kterou předává, je to, že se jedná o nový počátek DLOGu verze 3.0. Hádám že trochu zajímavé může být to, že soubor s příponou `.dlog` obsahující DLOG verze 3.0 může obsahovat více těchto headerů, neboli distinktních záznamů. Je to proto, že kdyby bot pošel, tak aby šlo poznat, která data spolu souvisí, a která nikoli.
### Příklad
Header vypadá pokaždé přesně takto:
```
DLOG3.0
```
Ano, i včetně všech bílých znaků.

View File

@ -1,10 +1,11 @@
import { ButtonStyle, ChannelType, Client, CommandInteraction, GatewayIntentBits, InteractionReplyOptions, Message, Partials } from "discord.js";
import { appendFileSync, readdirSync } from "fs";
import { readdirSync } from "fs";
import { CClient, CUser, HelpServer, Komand, KomandNaExport, KomandRaw, ListenerFunkce, Modul, SMessage, 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";
import { logOOoZS, logSZS, logPZS } from "./utils/statuslog";
const ints = GatewayIntentBits;
const client = new Client({
@ -19,8 +20,6 @@ const kuldan_log: SRecord<SRecord<number>> = {};
const komandyNaPoslani: KomandNaExport[] = [];
const helpServer: HelpServer = require("./utils/helpServer");
appendFileSync("statlog.dlog", "\n\n\nDLOG3.0\n\n");
client.on("error", err => {
log(err);
adminLog(client, "nejaka chyba na klijentovi", err);
@ -350,18 +349,19 @@ client.on("presenceUpdate", async (bef, aft) => {
if (!user) return;
if (!user.presence) user.presence = {};
appendFileSync("statlog.dlog", `r`);
logOOoZS(user.id, aft.clientStatus);
if (areStatusesSame(aft.clientStatus, user.presence)) return;
logSZS(user.id, aft.clientStatus);
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");
logPZS(user.id, naCo, user.presence);
return;
}

92
src/utils/statuslog.ts Normal file
View File

@ -0,0 +1,92 @@
import { ClientPresenceStatusData } from "discord.js";
import { appendFileSync } from "fs";
import { SRecord } from "./types";
const cesta = "statlog.dlog";
appendFileSync(cesta, "\n\n\nDLOG3.0\n");
let aktualniOffset: number;
const lidiVDLOG3 = new Map<string, string>();
function updateOffset() {
aktualniOffset = Date.now();
appendFileSync(cesta, `T${aktualniOffset.toString(36)}\n`);
}
setInterval(updateOffset, 27 * 60 * 1000);
updateOffset();
export function getDLOGTimestamp() {
return (Date.now() - aktualniOffset).toString(36);
}
export function getIdInDLOG3(id: string) {
if (lidiVDLOG3.has(id)) // Pokud už je v mapě
return lidiVDLOG3.get(id);
// Pokud není v mapě vygenerujeme nové ID a uložíme do mapy
let letters = '';
let num = lidiVDLOG3.size + 1;
while (num > 0) {
num--; // Adjust for 0-indexing
// Get the remainder and convert to a character
letters = String.fromCharCode((num % 26) + 65) + letters;
// Divide by 26 for the next iteration
num = Math.floor(num / 26);
}
lidiVDLOG3.set(id, letters);
return `${letters}${id}`;
}
const platformTable: SRecord<string> = {
desktop: "D",
web: "W",
mobile: "M"
};
const statusTable: SRecord<number> = {
online: 1,
idle: 2,
dnd: 3
};
export function statusToDLOG3(status: ClientPresenceStatusData | null) {
if (!status) return "-";
let tovje = [];
for (const [key, value] of Object.entries(status)) {
const platform = platformTable[key] ?? key;
const status = statusTable[value] ?? 0;
if (status) tovje.push(`${platform} ${status}`);
}
if (!tovje.length) return "-";
return tovje.join(" ");
}
// Logování Obecného oznámení o změně statusu
export function logOOoZS(userId: string, status: ClientPresenceStatusData | null) {
const timestamp = getDLOGTimestamp();
const id = getIdInDLOG3(userId);
const stat = statusToDLOG3(status);
appendFileSync(cesta, `${timestamp}${id}o${stat}\n`);
}
// Logování Skutečné změny statusu
export function logSZS(userId: string, status: ClientPresenceStatusData | null) {
const id = getIdInDLOG3(userId);
const stat = statusToDLOG3(status);
appendFileSync(cesta, `${id}s${stat}\n`);
}
// Logování Podezřelé změny statusu
export function logPZS(userId: string, status1: ClientPresenceStatusData | null, status2: ClientPresenceStatusData | null) {
const id = getIdInDLOG3(userId);
const stat1 = statusToDLOG3(status1);
const stat2 = statusToDLOG3(status2);
appendFileSync(cesta, `${id}p${stat1}|${stat2}\n`);
}

View File

@ -243,7 +243,3 @@ export const areStatusesSame = (object1?: ClientPresenceStatusData | null, objec
}
return true;
};
export function statusToDLOG3(status: ClientPresenceStatusData) {
}