added userPresenceUpdate and made spink use it

This commit is contained in:
Histmy 2022-01-28 16:14:37 +01:00
parent e67dd8d856
commit 348600aba5
6 changed files with 25 additions and 8 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "denim_3001", "name": "denim_3001",
"version": "3001.36.0", "version": "3001.36.1",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "denim_3001", "name": "denim_3001",
"version": "3001.36.0", "version": "3001.36.1",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@discordjs/opus": "github:discordjs/opus", "@discordjs/opus": "github:discordjs/opus",

View File

@ -1,6 +1,6 @@
{ {
"name": "denim_3001", "name": "denim_3001",
"version": "3001.36.0", "version": "3001.36.1",
"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,6 +1,6 @@
import { Client, Collection, Intents, Message, MessageActionRow, MessageButton } from "discord.js"; import { Client, Collection, Intents, Message, MessageActionRow, MessageButton } from "discord.js";
import { readdirSync } from "fs"; 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 { adminLog, formatCas, loadEnv, oddiakritikovat } from "./utils/utils.js";
import levenshtein from "js-levenshtein"; import levenshtein from "js-levenshtein";
import { emouty } from "./utils/emotes"; import { emouty } from "./utils/emotes";
@ -63,7 +63,7 @@ readdirSync(modulFolder).forEach(soubor => {
const ev = groups.s ? superEventy : eventy; const ev = groups.s ? superEventy : eventy;
if (!ev[groups.h]) { if (!ev[groups.h]) {
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]!; const n = modul[name as EventSOn]!;
if (typeof n == "object") { if (typeof n == "object") {
@ -176,4 +176,15 @@ client.on("messageCreate", async mes => {
runKomand(cmd, cmdName); 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); client.login(process.env.token);

View File

@ -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; if (!bef) return;
const befoff = bef.status == "offline"; const befoff = bef.status == "offline";
const aftoff = aft.status == "offline"; const aftoff = aft.status == "offline";

View File

@ -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; const sudo = mes.channel.id == process.env.adminChannel || mes.author.id == process.env.adminID;
if (!sudo) { if (!sudo) {
const verze = await fetch("https://denim3001.deadfish.cz/version.txt") const verze = await fetch("https://denim3001.deadfish.cz/version.txt")

View File

@ -25,7 +25,9 @@ interface SuperObject {
fun: SuperListenerFunkce; 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<T> = Record<string, T>; export type SRecord<T> = Record<string, T>;
@ -77,3 +79,7 @@ export interface JoinHovna {
conn: VoiceConnection; conn: VoiceConnection;
prev: string | boolean; prev: string | boolean;
}; };
export interface CUser extends User {
presence?: ClientPresenceStatusData;
}