mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-06 02:01:26 +03:00
feat: notify when staff are offline (closes #304)
This commit is contained in:
@@ -690,6 +690,7 @@ module.exports = class TicketManager {
|
||||
const currentHours = workingHours[now.day()];
|
||||
const start = now.time(currentHours[0]);
|
||||
const end = now.time(currentHours[1]);
|
||||
let working = true;
|
||||
|
||||
if (currentHours[0] === currentHours[1] || now.isAfter(end)) { // staff have the day off or have finished for the day
|
||||
// first look for the next working day *this* week (after today)
|
||||
@@ -697,6 +698,7 @@ module.exports = class TicketManager {
|
||||
// if there isn't one, look for the next working day *next* week (before and including today's weekday)
|
||||
if (!nextIndex) nextIndex = workingHours.findIndex((hours, i) => i <= now.day() && hours[0] !== hours[1]);
|
||||
if (nextIndex) {
|
||||
working = false;
|
||||
const next = workingHours[nextIndex];
|
||||
let then = now.add(nextIndex - now.day(), 'day');
|
||||
if (nextIndex <= now.day()) then = then.add(1, 'week');
|
||||
@@ -711,6 +713,7 @@ module.exports = class TicketManager {
|
||||
});
|
||||
}
|
||||
} else if (now.isBefore(start)) { // staff haven't started working yet
|
||||
working = false;
|
||||
const timestamp = Math.ceil(start.d.getTime() / 1000); // in seconds
|
||||
await channel.send({
|
||||
embeds: [
|
||||
@@ -722,7 +725,25 @@ module.exports = class TicketManager {
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: !staff
|
||||
|
||||
if (working) {
|
||||
let online = 0;
|
||||
for (const [, member] of message.channel.members) {
|
||||
if (!await isStaff(message.channel.guild, member.id)) continue;
|
||||
if (member.presence && member.presence !== 'offline') online++;
|
||||
}
|
||||
if (online === 0) {
|
||||
await channel.send({
|
||||
embeds: [
|
||||
new ExtendedEmbedBuilder()
|
||||
.setColor(category.guild.primaryColour)
|
||||
.setTitle(getMessage('ticket.offline.title'))
|
||||
.setDescription(getMessage('ticket.offline.description')),
|
||||
],
|
||||
});
|
||||
this.client.keyv.set(`offline/${channel.id}`, Date.now(), ms('1h'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user