Status' should actually work now
Added test, so this shouldn't happen again
This commit is contained in:
parent
dddc49db8d
commit
e6d4bec5bf
6005
package-lock.json
generated
6005
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "denim_3001",
|
"name": "denim_3001",
|
||||||
"version": "3001.42.1",
|
"version": "3001.42.2",
|
||||||
"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/"
|
||||||
@ -8,7 +8,8 @@
|
|||||||
"main": "out/app.js",
|
"main": "out/app.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node .",
|
"start": "node .",
|
||||||
"test": "tsc && node ."
|
"test": "tsc && node .",
|
||||||
|
"jest": "jest"
|
||||||
},
|
},
|
||||||
"author": "Histmy + det-fys",
|
"author": "Histmy + det-fys",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
@ -22,7 +23,9 @@
|
|||||||
"tweetnacl": "^1.0.3"
|
"tweetnacl": "^1.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/jest": "^29.1.0",
|
||||||
"@types/js-levenshtein": "^1.1.1",
|
"@types/js-levenshtein": "^1.1.1",
|
||||||
"@types/node-fetch": "^2.6.2"
|
"@types/node-fetch": "^2.6.2",
|
||||||
|
"jest": "^29.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,9 +2,8 @@
|
|||||||
import { Client, Guild, Presence, User } from "discord.js";
|
import { Client, Guild, Presence, User } from "discord.js";
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import { FakePresence, Modul, SRecord, StatusyINaFounu, UserChange, ZmenovejObjekt } from "../utils/types";
|
import { FakePresence, Modul, SRecord, StatusyINaFounu, UserChange, ZmenovejObjekt } from "../utils/types";
|
||||||
import { adminLog, log } from "../utils/utils";
|
import { adminLog, log, statusOnFoun } from "../utils/utils";
|
||||||
|
|
||||||
const role = { online: "Online", idle: "Idle", dnd: "DND", offline: "Offline" };
|
|
||||||
const statusy = { Offline: "0", Online: "1", Idle: "2", DND: "3", OnlinePhone: "11", IdlePhone: "12", DNDPhone: "13" };
|
const statusy = { Offline: "0", Online: "1", Idle: "2", DND: "3", OnlinePhone: "11", IdlePhone: "12", DNDPhone: "13" };
|
||||||
const prepSend = (zmeny: UserChange[]) => {
|
const prepSend = (zmeny: UserChange[]) => {
|
||||||
const changes: ZmenovejObjekt[] = [];
|
const changes: ZmenovejObjekt[] = [];
|
||||||
@ -35,26 +34,6 @@ const poslatData = (data: SRecord<unknown>) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const statusOnFoun = (bef: FakePresence | null, aft: FakePresence) => {
|
|
||||||
if (!bef) bef = { status: 'offline', clientStatus: {} };
|
|
||||||
const predAPo: StatusyINaFounu[] = [];
|
|
||||||
|
|
||||||
[bef, aft].forEach((s, i) => {
|
|
||||||
const mobile = s.clientStatus?.mobile;
|
|
||||||
const deskotopy = s.clientStatus?.web
|
|
||||||
? s.clientStatus.desktop == "online" ? s.clientStatus.desktop : s.clientStatus.web
|
|
||||||
: s.clientStatus?.desktop;
|
|
||||||
|
|
||||||
if (mobile && mobile != deskotopy && deskotopy == "idle") {
|
|
||||||
predAPo[i] = `${role[mobile]}Phone` as StatusyINaFounu;
|
|
||||||
} else {
|
|
||||||
predAPo[i] = role[s.status] as StatusyINaFounu;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return predAPo;
|
|
||||||
};
|
|
||||||
|
|
||||||
const ziju = () => {
|
const ziju = () => {
|
||||||
poslatData({ nejsemPoslej: !0 });
|
poslatData({ nejsemPoslej: !0 });
|
||||||
setTimeout(ziju, 60_000);
|
setTimeout(ziju, 60_000);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { AudioPlayerStatus, AudioResource, createAudioPlayer, createAudioResource, entersState, getVoiceConnection, joinVoiceChannel, PlayerSubscription, StreamType, VoiceConnection, VoiceConnectionStatus } from "@discordjs/voice";
|
import { AudioPlayerStatus, AudioResource, createAudioPlayer, createAudioResource, entersState, getVoiceConnection, joinVoiceChannel, PlayerSubscription, StreamType, VoiceConnection, VoiceConnectionStatus } from "@discordjs/voice";
|
||||||
import { ChannelType, Client, Guild, StageChannel, VoiceChannel } from "discord.js";
|
import { ChannelType, Client, Guild, StageChannel, VoiceChannel } from "discord.js";
|
||||||
import { once } from "events";
|
import { once } from "events";
|
||||||
import { JoinHovna, KomandNaExport, MuzikaFace, RunFunkce, SRecord } from "./types";
|
import { FakePresence, JoinHovna, KomandNaExport, MuzikaFace, RunFunkce, SRecord, StatusyINaFounu } from "./types";
|
||||||
import { existsSync } from "fs";
|
import { existsSync } from "fs";
|
||||||
import { Readable } from "node:stream";
|
import { Readable } from "node:stream";
|
||||||
|
|
||||||
@ -219,3 +219,25 @@ export function log(...content: (string | Error)[]) {
|
|||||||
const d = new Date();
|
const d = new Date();
|
||||||
console.log(`[${d.getDate()}.${d.getMonth() + 1}. ${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}]:`, ...jo);
|
console.log(`[${d.getDate()}.${d.getMonth() + 1}. ${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}]:`, ...jo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const statusOnFoun = (bef: FakePresence | null, aft: FakePresence) => {
|
||||||
|
const role = { online: "Online", idle: "Idle", dnd: "DND", offline: "Offline" };
|
||||||
|
|
||||||
|
if (!bef) bef = { status: 'offline', clientStatus: {} };
|
||||||
|
const predAPo: StatusyINaFounu[] = [];
|
||||||
|
|
||||||
|
[bef, aft].forEach((s, i) => {
|
||||||
|
const mobile = s.clientStatus?.mobile;
|
||||||
|
const deskotopy = s.clientStatus?.web
|
||||||
|
? s.clientStatus.desktop == "online" ? s.clientStatus.desktop : s.clientStatus.web
|
||||||
|
: s.clientStatus?.desktop;
|
||||||
|
|
||||||
|
if (mobile && mobile != deskotopy && (!deskotopy || deskotopy == "idle")) {
|
||||||
|
predAPo[i] = `${role[mobile]}Phone` as StatusyINaFounu;
|
||||||
|
} else {
|
||||||
|
predAPo[i] = role[s.status] as StatusyINaFounu;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return predAPo;
|
||||||
|
};
|
||||||
|
|||||||
16
test/status.test.js
Normal file
16
test/status.test.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
process.env.ignorePresence = "J";
|
||||||
|
const { statusOnFoun } = require("../out/utils/utils.js");
|
||||||
|
|
||||||
|
const get = (a, b) => statusOnFoun(null, { status: a, clientStatus: b })[1];
|
||||||
|
|
||||||
|
test("Zobrazovani spravne statusu", () => {
|
||||||
|
expect(get("online", { desktop: "online" })).toBe("Online");
|
||||||
|
expect(get("online", { mobile: "online" })).toBe("OnlinePhone");
|
||||||
|
expect(get("online", { web: "idle", desktop: "online" })).toBe("Online");
|
||||||
|
expect(get("online", { desktop: "online", mobile: "idle" })).toBe("Online");
|
||||||
|
expect(get("online", { web: "idle", mobile: "online" })).toBe("OnlinePhone");
|
||||||
|
expect(get("idle", { web: "idle" })).toBe("Idle");
|
||||||
|
expect(get("dnd", { web: "dnd" })).toBe("DND");
|
||||||
|
expect(get("offline", {})).toBe("Offline");
|
||||||
|
expect(get("offline", null)).toBe("Offline");
|
||||||
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user