Added status tranking
This commit is contained in:
parent
8bcb037f28
commit
5c5db451ba
5
app.js
5
app.js
@ -14,11 +14,12 @@ const runEvent = (name, args) => {
|
|||||||
eventy[name].forEach(listener => {
|
eventy[name].forEach(listener => {
|
||||||
listener(...args);
|
listener(...args);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
fs.readdirSync(modulFolder).forEach(function (soubor) {
|
fs.readdirSync(modulFolder).forEach(function (soubor) {
|
||||||
if (soubor.endsWith(".js")) {
|
if (soubor.endsWith(".js")) {
|
||||||
const modul = require(`${modulFolder}${soubor}`);
|
const modul = require(`${modulFolder}${soubor}`);
|
||||||
|
modul.client = client;
|
||||||
Object.keys(modul).forEach(name => {
|
Object.keys(modul).forEach(name => {
|
||||||
if (name.startsWith('on_')) {
|
if (name.startsWith('on_')) {
|
||||||
if (!eventy[name]) {
|
if (!eventy[name]) {
|
||||||
@ -49,7 +50,7 @@ const spim = mes => {
|
|||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
};
|
||||||
|
|
||||||
client.on("message", function (mes) {
|
client.on("message", function (mes) {
|
||||||
if (process.env.IGNORE_MESS || spim(mes)) return;
|
if (process.env.IGNORE_MESS || spim(mes)) return;
|
||||||
|
|||||||
77
modules/status.js
Normal file
77
modules/status.js
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
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]]]);
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -1,6 +1,5 @@
|
|||||||
// Komandy nebo handelery který se nikam jinam nehodí
|
// Komandy nebo handelery který se nikam jinam nehodí
|
||||||
|
|
||||||
const role = { online: '684443816383610916', idle: '684444083065978941', dnd: '684444020558135399', offline: '684443903759614049', onlinephone: '777989420728975390', idlephone: "836554207342362626", dndphone: "836554469478760449" };
|
|
||||||
const spoustece = ['mares', 'mareš', 'purfie', 'denim', '<@!477202009066438668>'];
|
const spoustece = ['mares', 'mareš', 'purfie', 'denim', '<@!477202009066438668>'];
|
||||||
const emouty = ['purfiek3:616026189269696512', 'purfiek3:616026189269696512', 'purfiek3:616026189269696512', 'purfieUchyl:576487602203525138', 'bafW:574646319696576532', 'purfiek4:616026180889477258'];
|
const emouty = ['purfiek3:616026189269696512', 'purfiek3:616026189269696512', 'purfiek3:616026189269696512', 'purfieUchyl:576487602203525138', 'bafW:574646319696576532', 'purfiek4:616026180889477258'];
|
||||||
const rand = max => Math.floor(Math.random() * max);
|
const rand = max => Math.floor(Math.random() * max);
|
||||||
@ -30,21 +29,6 @@ module.exports = {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Změna rolí podle statusu
|
|
||||||
on_presenceUpdate: (bef, aft) => {
|
|
||||||
if (aft.guild.id !== '555779161067749446' || process.env.IGNORE_PRESENCE) return;
|
|
||||||
|
|
||||||
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`;
|
|
||||||
});
|
|
||||||
if (bef.status === aft.status) return;
|
|
||||||
|
|
||||||
aft.member.roles.add(role[aft.status]);
|
|
||||||
aft.member.roles.remove(role[bef.status]);
|
|
||||||
},
|
|
||||||
|
|
||||||
// Zareaguje na zprávu pokud obsahuje spouštěče a pokud RNG
|
// Zareaguje na zprávu pokud obsahuje spouštěče a pokud RNG
|
||||||
on_message: mes => {
|
on_message: mes => {
|
||||||
let sance = 0;
|
let sance = 0;
|
||||||
@ -54,4 +38,4 @@ module.exports = {
|
|||||||
if (rand(3) < sance) mes.react(emouty[rand(emouty.length)])
|
if (rand(3) < sance) mes.react(emouty[rand(emouty.length)])
|
||||||
.catch(er => console.log("neco se doebalo:", er.message));
|
.catch(er => console.log("neco se doebalo:", er.message));
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user