novej (dočasnej) logging statusů

This commit is contained in:
Histmy 2024-10-05 18:34:16 +02:00
parent edeaba692f
commit ed4836a0fd
4 changed files with 106 additions and 11 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "denim_3001", "name": "denim_3001",
"version": "3001.60.2", "version": "3001.60.3",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "denim_3001", "name": "denim_3001",
"version": "3001.60.2", "version": "3001.60.3",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@discordjs/voice": "^0.17.0", "@discordjs/voice": "^0.17.0",

View File

@ -1,6 +1,6 @@
{ {
"name": "denim_3001", "name": "denim_3001",
"version": "3001.60.2", "version": "3001.60.3",
"description": "Toto je velmi kvalitní bot.", "description": "Toto je velmi kvalitní bot.",
"repository": { "repository": {
"url": "https://github.com/Histmy/Denim-Bot/" "url": "https://github.com/Histmy/Denim-Bot/"

View File

@ -1,10 +1,11 @@
import { ButtonStyle, ChannelType, Client, CommandInteraction, GatewayIntentBits, InteractionReplyOptions, Message, Partials } from "discord.js"; import { ButtonStyle, ChannelType, Client, CommandInteraction, GatewayIntentBits, InteractionReplyOptions, Message, Partials } from "discord.js";
import { readdirSync } from "fs"; import { readdirSync } from "fs";
import { CClient, CUser, HelpServer, Komand, KomandNaExport, KomandRaw, ListenerFunkce, Modul, SRecord, SuperListenerFunkce } from "./utils/types"; 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 { adminLog, areStatusesSame, formatCas, log, nabidni, oddiakritikovat, prefix, rand, send } from "./utils/utils.js";
import levenshtein from "js-levenshtein"; import levenshtein from "js-levenshtein";
import { emouty } from "./utils/emotes"; import { emouty } from "./utils/emotes";
import { lidiCoMajDenimPremium, setClient } from "./utils/denim-Spravce"; import { lidiCoMajDenimPremium, setClient } from "./utils/denim-Spravce";
import { logOOoZS, logSZS, logPZS } from "./utils/statuslog";
const ints = GatewayIntentBits; const ints = GatewayIntentBits;
const client = new Client({ const client = new Client({
@ -223,7 +224,7 @@ function renderMessage(expression: string, args: string[]) {
} }
} }
function handle(e: unknown, mesOrInt: Message | CommandInteraction) { function handle(e: unknown, mesOrInt: SMessage | CommandInteraction) {
if (process.env.dieOnError) throw e; if (process.env.dieOnError) throw e;
log("error pri spousteni akce", e as Error); log("error pri spousteni akce", e as Error);
const admin = process.env.adminID; const admin = process.env.adminID;
@ -233,9 +234,9 @@ function handle(e: unknown, mesOrInt: Message | CommandInteraction) {
mesOrInt.reply(txt); mesOrInt.reply(txt);
} }
async function runKomand(mes: Message, cmd: Komand, cmdName: string, arg: string): Promise<unknown>; async function runKomand(mes: SMessage, cmd: Komand, cmdName: string, arg: string): Promise<unknown>;
async function runKomand(interaction: CommandInteraction, cmd: Komand, cmdName: string): Promise<unknown>; async function runKomand(interaction: CommandInteraction, cmd: Komand, cmdName: string): Promise<unknown>;
async function runKomand(mesOrInt: Message | CommandInteraction, cmd: Komand, cmdName: string, arg?: string) { async function runKomand(mesOrInt: SMessage | CommandInteraction, cmd: Komand, cmdName: string, arg?: string) {
const jeMes = mesOrInt instanceof Message; const jeMes = mesOrInt instanceof Message;
if (jeMes && cmd.slashRun) { if (jeMes && cmd.slashRun) {
@ -250,7 +251,7 @@ async function runKomand(mesOrInt: Message | CommandInteraction, cmd: Komand, cm
} }
if (cmd.premium && !lidiCoMajDenimPremium.includes(jeMes ? mesOrInt.author.id : mesOrInt.member?.user.id || "")) { if (cmd.premium && !lidiCoMajDenimPremium.includes(jeMes ? mesOrInt.author.id : mesOrInt.member?.user.id || "")) {
return send(mesOrInt as Message, "sorka bracho tuto je koamnd jenom pro curaki co platy"); return send(mesOrInt as SMessage, "sorka bracho tuto je koamnd jenom pro curaki co platy");
} }
const akce = cmd.run ?? cmd.slashRun!; const akce = cmd.run ?? cmd.slashRun!;
@ -292,7 +293,6 @@ client.on("messageCreate", async mes => {
} }
const komandBez = oddiakritikovat(komandSDiakritikou).toLowerCase(); const komandBez = oddiakritikovat(komandSDiakritikou).toLowerCase();
// const cmdName = client.aliasy[komandBez] ?? komandBez;
let cmdName = komandBez; let cmdName = komandBez;
const aliasCelej = client.aliasy[komandBez]; const aliasCelej = client.aliasy[komandBez];
@ -349,16 +349,19 @@ client.on("presenceUpdate", async (bef, aft) => {
if (!user) return; if (!user) return;
if (!user.presence) user.presence = {}; if (!user.presence) user.presence = {};
logOOoZS(user.id, aft.clientStatus);
if (areStatusesSame(aft.clientStatus, user.presence)) return; if (areStatusesSame(aft.clientStatus, user.presence)) return;
logSZS(user.id, aft.clientStatus);
const naCo = aft.clientStatus || {}; const naCo = aft.clientStatus || {};
user.presence = naCo; user.presence = naCo;
await new Promise(r => setTimeout(r, 1000)); await new Promise(r => setTimeout(r, 1000));
if (!areStatusesSame(naCo, user.presence)) { if (!areStatusesSame(naCo, user.presence)) {
log("status se rychle nezmenil pro ", user.username, ": ", naCo, " -> ", user.presence); logPZS(user.id, naCo, user.presence);
adminLog(client, "stalo se to");
return; 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`);
}