Status roles change on every server

This commit is contained in:
Histmy 2021-06-26 11:41:27 +02:00
parent 07134af599
commit a3255691a7

View File

@ -1,8 +1,7 @@
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 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 prepSend = pair => {
const changes = [];
@ -21,11 +20,19 @@ const poslatData = data => {
const statusOnFoun = (bef, aft) => {
if (!bef) bef = { status: 'offline', clientStatus: {} };
[bef, aft].forEach(s => {
const predAPo = ["", ""];
[bef, aft].forEach((s, i) => {
const mobile = s.clientStatus.mobile;
if (mobile && mobile !== s.clientStatus.desktop) s.status = `${mobile}phone`;
if (mobile && mobile !== s.clientStatus.desktop) {
predAPo[i] = `${role[mobile]}Phone`;
}
else {
predAPo[i] = role[s.status];
}
});
return [bef, aft];
return predAPo;
};
const ziju = () => {
@ -35,21 +42,41 @@ const ziju = () => {
if (!process.env.IGNORE_PRESENCE) ziju();
const getRole = (status, server) =>
server.roles.cache.find(role => role.name === `Status${status}`);
//#region temp hovno
const logHovno = (before, after) => {
if (!after.guild.available) {
fetch("https://discord.com/api/webhooks/852964399459074088/5GZJSJYW30P0GmjXuLk23GwYANgaStS_-56GIIGaSCNmvIrzTHExMAojmqMH5VTQyod2",
{ method: "POST", headers: { "Content-Type": "application/json" }, body: `{"content":"server neeeni:\nbefore: ${JSON.stringify(before)}\nafter: ${JSON.stringify(after)}}` });
return true;
}
return false;
};
//#endregion
module.exports = {
// Změna rolí podle statusu a odeslání statusu
on_presenceUpdate: (bef, aft) => {
if (process.env.IGNORE_PRESENCE) return;
[bef, aft] = statusOnFoun(bef, aft);
if (bef.status === aft.status) return;
const [statusPred, statusPo] = statusOnFoun(bef, aft);
if (aft.guild.id === '555779161067749446') {
aft.member.roles.add(role[aft.status]);
aft.member.roles.remove(role[bef.status]);
}
//#region temp hovno
if (logHovno(bef, aft)) return;
//#endregion
prepSend([[aft.user, statusy[aft.status]]]);
if (statusPred === statusPo) return;
const rolePred = getRole(statusPred, bef.guild);
const rolePo = getRole(statusPo, aft.guild);
if (rolePred) aft.member.roles.remove(rolePred);
if (rolePo) aft.member.roles.add(rolePo);
prepSend([[aft.user, statusy[statusPo]]]);
},
// Odeslání statusů při startu bota
@ -69,7 +96,7 @@ module.exports = {
});
presence.forEach(presenc => {
const status = statusOnFoun(null, presenc)[1].status;
const status = statusOnFoun(null, presenc)[1];
changes.push([memberove.get(presenc.userID), statusy[status]]);
memberove.delete(presenc.userID);
});
@ -82,8 +109,9 @@ module.exports = {
},
// Odeslání statusu při změně jména nebo profilovky
on_userUpdate: (_, aft) => {
if (!process.env.IGNORE_PRESENCE)
prepSend([[aft, statusy[statusOnFoun(null, aft.presence)[1].status]]]);
on_userUpdate: (bef, aft) => {
if (process.env.IGNORE_PRESENCE) return;
if (!logHovno(bef, aft))
prepSend([[aft, statusy[statusOnFoun(null, aft.presence)[1]]]]);
}
};