mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-12-23 00:03:09 +02:00
fix: allow no activities
This commit is contained in:
parent
296002e04f
commit
bd15bd8145
@ -53,43 +53,47 @@ module.exports = class extends Listener {
|
|||||||
await client.application.commands.fetch();
|
await client.application.commands.fetch();
|
||||||
|
|
||||||
// presence/activity
|
// presence/activity
|
||||||
let next = 0;
|
if (client.config.presence.activities?.length > 0) {
|
||||||
const setPresence = async () => {
|
let next = 0;
|
||||||
const cacheKey = 'cache/presence';
|
const setPresence = async () => {
|
||||||
let cached = await client.keyv.get(cacheKey);
|
const cacheKey = 'cache/presence';
|
||||||
if (!cached) {
|
let cached = await client.keyv.get(cacheKey);
|
||||||
const tickets = await client.prisma.ticket.findMany({
|
if (!cached) {
|
||||||
select: {
|
const tickets = await client.prisma.ticket.findMany({
|
||||||
closedAt: true,
|
select: {
|
||||||
createdAt: true,
|
closedAt: true,
|
||||||
firstResponseAt: true,
|
createdAt: true,
|
||||||
},
|
firstResponseAt: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const closedTicketsWithResponse = tickets.filter(t => t.firstResponseAt && t.closedAt);
|
||||||
|
const closedTickets = tickets.filter(t => t.closedAt);
|
||||||
|
cached = {
|
||||||
|
avgResolutionTime: ms(getAvgResolutionTime(closedTicketsWithResponse)),
|
||||||
|
avgResponseTime: ms(getAvgResponseTime(closedTicketsWithResponse)),
|
||||||
|
openTickets: tickets.length - closedTickets.length,
|
||||||
|
totalTickets: tickets.length,
|
||||||
|
};
|
||||||
|
await client.keyv.set(cacheKey, cached, ms('15m'));
|
||||||
|
}
|
||||||
|
const activity = { ...client.config.presence.activities[next] };
|
||||||
|
activity.name = activity.name
|
||||||
|
.replace(/{+avgResolutionTime}+/gi, cached.avgResolutionTime)
|
||||||
|
.replace(/{+avgResponseTime}+/gi, cached.avgResponseTime)
|
||||||
|
.replace(/{+openTickets}+/gi, cached.openTickets)
|
||||||
|
.replace(/{+totalTickets}+/gi, cached.totalTickets);
|
||||||
|
client.user.setPresence({
|
||||||
|
activities: [activity],
|
||||||
|
status: client.config.presence.status,
|
||||||
});
|
});
|
||||||
const closedTicketsWithResponse = tickets.filter(t => t.firstResponseAt && t.closedAt);
|
next++;
|
||||||
const closedTickets = tickets.filter(t => t.closedAt);
|
if (next === client.config.presence.activities.length) next = 0;
|
||||||
cached = {
|
};
|
||||||
avgResolutionTime: ms(getAvgResolutionTime(closedTicketsWithResponse)),
|
setPresence();
|
||||||
avgResponseTime: ms(getAvgResponseTime(closedTicketsWithResponse)),
|
if (client.config.presence.activities.length > 1) setInterval(() => setPresence(), client.config.presence.interval * 1000);
|
||||||
openTickets: tickets.length - closedTickets.length,
|
} else {
|
||||||
totalTickets: tickets.length,
|
client.log.info('Presence activities are disabled');
|
||||||
};
|
}
|
||||||
await client.keyv.set(cacheKey, cached, ms('15m'));
|
|
||||||
}
|
|
||||||
const activity = { ...client.config.presence.activities[next] };
|
|
||||||
activity.name = activity.name
|
|
||||||
.replace(/{+avgResolutionTime}+/gi, cached.avgResolutionTime)
|
|
||||||
.replace(/{+avgResponseTime}+/gi, cached.avgResponseTime)
|
|
||||||
.replace(/{+openTickets}+/gi, cached.openTickets)
|
|
||||||
.replace(/{+totalTickets}+/gi, cached.totalTickets);
|
|
||||||
client.user.setPresence({
|
|
||||||
activities: [activity],
|
|
||||||
status: client.config.presence.status,
|
|
||||||
});
|
|
||||||
next++;
|
|
||||||
if (next === client.config.presence.activities.length) next = 0;
|
|
||||||
};
|
|
||||||
setPresence();
|
|
||||||
if (client.config.presence.activities.length > 1) setInterval(() => setPresence(), client.config.presence.interval * 1000);
|
|
||||||
|
|
||||||
// stats posting
|
// stats posting
|
||||||
if (client.config.stats) {
|
if (client.config.stats) {
|
||||||
|
Loading…
Reference in New Issue
Block a user