const fetch = require("node-fetch"); const role = { online: '684443816383610916', idle: '684444083065978941', dnd: '684444020558135399', offline: '684443903759614049', onlinephone: '777989420728975390', idlephone: "836554207342362626", dndphone: "836554469478760449" }; const statusy = { offline: "0", online: "1", idle: "2", dnd: "3", onlinephone: "11", idlephone: "12", dndphone: "13" }; const prepSend = pair => { const changes = []; pair.forEach(par => { const us = par[0]; changes.push({ id: us.id, status: par[1], nick: us.username, pfp: us.avatar ?? "" }); }); poslatData({ changes }); }; const poslatData = data => { data.pwd = process.env.STAT_PASS; fetch("http://deadfish.cz:4629/endpoint-pro-denimka/", { method: "POST", headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); }; const statusOnFoun = (bef, aft) => { if (!bef) bef = { status: 'offline', clientStatus: {} }; [bef, aft].forEach(s => { const mobile = s.clientStatus.mobile; if (mobile && mobile !== s.clientStatus.desktop) s.status = `${mobile}phone`; }); return [bef, aft]; }; const hovno = () => { poslatData({ nejsemPoslej: !0 }); setTimeout(hovno, 60_000); }; hovno(); module.exports = { // Změna rolí podle statusu a odeslání statusu on_presenceUpdate: (bef, aft) => { if (aft.guild.id !== '555779161067749446' || process.env.IGNORE_PRESENCE) return; [bef, aft] = statusOnFoun(bef, aft); if (bef.status === aft.status) return; aft.member.roles.add(role[aft.status]); aft.member.roles.remove(role[bef.status]); prepSend([[aft.user, statusy[aft.status]]]); }, // Odeslání statusů při startu bota on_ready: () => { const client = module.exports.client; const guild = client.guilds.cache.get("555779161067749446"); const memberove = guild.members.cache.clone(); const presence = [...guild.presences.cache.values()]; const changes = []; presence.forEach(presenc => { const status = statusOnFoun(null, presenc)[1].status; changes.push([memberove.get(presenc.userID).user, statusy[status]]); memberove.delete(presenc.userID); }); for (const [_, value] of memberove) { changes.push([value.user, 0]); } prepSend(changes); }, // Odeslání statusu při změně jména nebo profilovky on_userUpdate: (_, aft) => { prepSend([[aft, statusy[statusOnFoun(null, aft.presence)[1].status]]]); } };