From 348600aba5ab4948578272343c6c5d88cce38a3b Mon Sep 17 00:00:00 2001 From: Histmy Date: Fri, 28 Jan 2022 16:14:37 +0100 Subject: [PATCH] added userPresenceUpdate and made spink use it --- package-lock.json | 4 ++-- package.json | 2 +- src/app.ts | 15 +++++++++++++-- src/modules/spink.ts | 2 +- src/modules/zbytek.ts | 2 +- src/utils/types.ts | 8 +++++++- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 60926d7..a05dc0c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "denim_3001", - "version": "3001.36.0", + "version": "3001.36.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "denim_3001", - "version": "3001.36.0", + "version": "3001.36.1", "license": "ISC", "dependencies": { "@discordjs/opus": "github:discordjs/opus", diff --git a/package.json b/package.json index 2264743..acec824 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "denim_3001", - "version": "3001.36.0", + "version": "3001.36.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 b688424..fca6ef3 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,6 +1,6 @@ import { Client, Collection, Intents, Message, MessageActionRow, MessageButton } from "discord.js"; import { readdirSync } from "fs"; -import { EventSOn, KoamndNaExport, Komand, ListenerFunkce, Modul, RunFunkce, SRecord, SuperListenerFunkce } from "./utils/types"; +import { CUser, EventSOn, KoamndNaExport, Komand, ListenerFunkce, Modul, RunFunkce, SRecord, SuperListenerFunkce } from "./utils/types"; import { adminLog, formatCas, loadEnv, oddiakritikovat } from "./utils/utils.js"; import levenshtein from "js-levenshtein"; import { emouty } from "./utils/emotes"; @@ -63,7 +63,7 @@ readdirSync(modulFolder).forEach(soubor => { const ev = groups.s ? superEventy : eventy; if (!ev[groups.h]) { ev[groups.h] = []; - if (groups.h != "message") client.on(groups.h, (...args) => void runEvent(groups.h, args)); + if (!["message", "userPresenceUpdate"].includes(groups.h)) client.on(groups.h, (...args) => void runEvent(groups.h, args)); } const n = modul[name as EventSOn]!; if (typeof n == "object") { @@ -176,4 +176,15 @@ client.on("messageCreate", async mes => { runKomand(cmd, cmdName); }); +// Simulation of userPresenceUpdate event +client.on("presenceUpdate", (bef, aft) => { + const user = aft.user as CUser; + if (!user.presence) user.presence = {}; + + if (JSON.stringify(aft.clientStatus) == JSON.stringify(user.presence)) return; + user.presence = aft.clientStatus || {}; + + runEvent("userPresenceUpdate", [bef, aft]); +}); + client.login(process.env.token); diff --git a/src/modules/spink.ts b/src/modules/spink.ts index 3c5ce00..c2a049d 100644 --- a/src/modules/spink.ts +++ b/src/modules/spink.ts @@ -220,7 +220,7 @@ const exp: Modul = { } }, - on_presenceUpdate: async (bef: Presence | null, aft: Presence) => { + on_userPresenceUpdate: async (bef: Presence | null, aft: Presence) => { if (!bef) return; const befoff = bef.status == "offline"; const aftoff = aft.status == "offline"; diff --git a/src/modules/zbytek.ts b/src/modules/zbytek.ts index 3531986..76f482d 100644 --- a/src/modules/zbytek.ts +++ b/src/modules/zbytek.ts @@ -20,7 +20,7 @@ const exp: Modul = { } }, - update: async (mes) => { + update: async mes => { const sudo = mes.channel.id == process.env.adminChannel || mes.author.id == process.env.adminID; if (!sudo) { const verze = await fetch("https://denim3001.deadfish.cz/version.txt") diff --git a/src/utils/types.ts b/src/utils/types.ts index 5c3d924..9cd7b7b 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -25,7 +25,9 @@ interface SuperObject { fun: SuperListenerFunkce; } -export type EventSOn = `on_${keyof ClientEvents}` | `super_on_${keyof ClientEvents}`; +type Eventy = keyof ClientEvents | "userPresenceUpdate"; + +export type EventSOn = `on_${Eventy}` | `super_on_${Eventy}`; export type SRecord = Record; @@ -77,3 +79,7 @@ export interface JoinHovna { conn: VoiceConnection; prev: string | boolean; }; + +export interface CUser extends User { + presence?: ClientPresenceStatusData; +}