mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-02-23 10:51:22 +02:00
fix(not really): catch working hours errors
This commit is contained in:
parent
04ada3c07b
commit
bb31242d6b
@ -732,66 +732,69 @@ module.exports = class TicketManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const workingHours = category.guild.workingHours;
|
try {
|
||||||
const timezone = workingHours[0];
|
const workingHours = category.guild.workingHours;
|
||||||
workingHours.shift(); // remove timezone
|
const timezone = workingHours[0];
|
||||||
const now = spacetime.now(timezone);
|
workingHours.shift(); // remove timezone
|
||||||
const currentHours = workingHours[now.day()];
|
const now = spacetime.now(timezone);
|
||||||
const start = now.time(currentHours[0]);
|
const currentHours = workingHours[now.day()];
|
||||||
const end = now.time(currentHours[1]);
|
const start = now.time(currentHours[0]);
|
||||||
let working = true;
|
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
|
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)
|
// first look for the next working day *this* week (after today)
|
||||||
let nextIndex = workingHours.findIndex((hours, i) => i > now.day() && hours[0] !== hours[1]);
|
let nextIndex = workingHours.findIndex((hours, i) => i > now.day() && hours[0] !== hours[1]);
|
||||||
// if there isn't one, look for the next working day *next* week (before and including today's weekday)
|
// 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) nextIndex = workingHours.findIndex((hours, i) => i <= now.day() && hours[0] !== hours[1]);
|
||||||
if (nextIndex) {
|
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');
|
||||||
|
const timestamp = Math.ceil(then.time(next[0]).goto('utc').d.getTime() / 1000); // in seconds
|
||||||
|
await channel.send({
|
||||||
|
embeds: [
|
||||||
|
new ExtendedEmbedBuilder()
|
||||||
|
.setColor(category.guild.primaryColour)
|
||||||
|
.setTitle(getMessage('ticket.working_hours.next.title'))
|
||||||
|
.setDescription(getMessage('ticket.working_hours.next.description', { timestamp })),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (now.isBefore(start)) { // staff haven't started working yet
|
||||||
working = false;
|
working = false;
|
||||||
const next = workingHours[nextIndex];
|
const timestamp = Math.ceil(start.goto('utc').d.getTime() / 1000); // in seconds
|
||||||
let then = now.add(nextIndex - now.day(), 'day');
|
|
||||||
if (nextIndex <= now.day()) then = then.add(1, 'week');
|
|
||||||
const timestamp = Math.ceil(then.time(next[0]).goto('utc').d.getTime() / 1000); // in seconds
|
|
||||||
await channel.send({
|
await channel.send({
|
||||||
embeds: [
|
embeds: [
|
||||||
new ExtendedEmbedBuilder()
|
new ExtendedEmbedBuilder()
|
||||||
.setColor(category.guild.primaryColour)
|
.setColor(category.guild.primaryColour)
|
||||||
.setTitle(getMessage('ticket.working_hours.next.title'))
|
.setTitle(getMessage('ticket.working_hours.today.title'))
|
||||||
.setDescription(getMessage('ticket.working_hours.next.description', { timestamp })),
|
.setDescription(getMessage('ticket.working_hours.today.description', { timestamp })),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (now.isBefore(start)) { // staff haven't started working yet
|
|
||||||
working = false;
|
|
||||||
const timestamp = Math.ceil(start.goto('utc').d.getTime() / 1000); // in seconds
|
|
||||||
await channel.send({
|
|
||||||
embeds: [
|
|
||||||
new ExtendedEmbedBuilder()
|
|
||||||
.setColor(category.guild.primaryColour)
|
|
||||||
.setTitle(getMessage('ticket.working_hours.today.title'))
|
|
||||||
.setDescription(getMessage('ticket.working_hours.today.description', { timestamp })),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (working && process.env.PUBLIC_BOT !== 'true') {
|
||||||
if (working && process.env.PUBLIC_BOT !== 'true') {
|
let online = 0;
|
||||||
let online = 0;
|
for (const [, member] of channel.members) {
|
||||||
for (const [, member] of channel.members) {
|
if (!await isStaff(channel.guild, member.id)) continue;
|
||||||
if (!await isStaff(channel.guild, member.id)) continue;
|
if (member.presence && member.presence !== 'offline') online++;
|
||||||
if (member.presence && member.presence !== 'offline') online++;
|
}
|
||||||
}
|
if (online === 0) {
|
||||||
if (online === 0) {
|
await channel.send({
|
||||||
await channel.send({
|
embeds: [
|
||||||
embeds: [
|
new ExtendedEmbedBuilder()
|
||||||
new ExtendedEmbedBuilder()
|
.setColor(category.guild.primaryColour)
|
||||||
.setColor(category.guild.primaryColour)
|
.setTitle(getMessage('ticket.offline.title'))
|
||||||
.setTitle(getMessage('ticket.offline.title'))
|
.setDescription(getMessage('ticket.offline.description')),
|
||||||
.setDescription(getMessage('ticket.offline.description')),
|
],
|
||||||
],
|
});
|
||||||
});
|
this.client.keyv.set(`offline/${channel.id}`, Date.now(), ms('1h'));
|
||||||
this.client.keyv.set(`offline/${channel.id}`, Date.now(), ms('1h'));
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.client.log.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user