Skip to content

Commit 2a874d5

Browse files
committed
Add new config option to working hours field
1 parent df35750 commit 2a874d5

File tree

2 files changed

+53
-35
lines changed

2 files changed

+53
-35
lines changed

config.yml.example

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,11 @@ workingHours:
302302
- day: "sunday"
303303
min: "09:00"
304304
max: "12:00"
305-
blockTicketCreation: true
305+
blockTicketCreation: true
306306
addField: true # If working hours is enabled, this option will enable or disable the addition of the working hours field to the ticket creation embed
307307
fieldTitle: "Working Hours" # The title of the working hours field
308-
fieldValue: "> {day}: {openingTime} to {closingTime}" # The value of "each" working hours field (depending on how many days you configured above), use {day} for today's day of the week, {openingTime} for the opening time and {closingTime} for the closing time
308+
valueDays: "TODAY" # Options are: "TODAY" which will only show today's working hours or "ALL" which will show the configured working hours for each day
309+
fieldValue: "> {day}: {openingTime} to {closingTime}" # The value of each working hours field, use {day} for today's day of the week, {openingTime} for the opening time and {closingTime} for the closing time
309310

310311
# The embed that is sent when the ticket creation is blocked due to being outside the working hours
311312
workingHoursEmbed:

events/interactionCreate.js

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,42 +1885,59 @@ module.exports = {
18851885

18861886
if (config.workingHours.enabled && config.workingHours.addField) {
18871887
let workingHoursText = "";
1888-
const currentDay = userCurrentTime.format("dddd").toLowerCase();
1889-
for (const day in workingHours) {
1890-
const { min, max } = workingHours[day];
1891-
const isCurrentDay = day === currentDay;
1892-
const dayText = isCurrentDay
1893-
? `**${day.charAt(0).toUpperCase() + day.slice(1)}**`
1894-
: day.charAt(0).toUpperCase() + day.slice(1);
1895-
let openTime = min || config.workingHours.default.min;
1896-
let closeTime = max || config.workingHours.default.max;
1897-
1898-
const openTimeToday = userCurrentTime
1899-
.clone()
1900-
.startOf("day")
1901-
.set({
1902-
hour: openTime.split(":")[0],
1903-
minute: openTime.split(":")[1],
1904-
});
1888+
if (config.workingHours.valueDays === "ALL") {
1889+
const currentDay = userCurrentTime.format("dddd").toLowerCase();
1890+
for (const day in workingHours) {
1891+
const { min, max } = workingHours[day];
1892+
const isCurrentDay = day === currentDay;
1893+
const dayText = isCurrentDay
1894+
? `**${day.charAt(0).toUpperCase() + day.slice(1)}**`
1895+
: day.charAt(0).toUpperCase() + day.slice(1);
1896+
let openTime = min || config.workingHours.default.min;
1897+
let closeTime = max || config.workingHours.default.max;
1898+
1899+
const openTimeToday = userCurrentTime
1900+
.clone()
1901+
.startOf("day")
1902+
.set({
1903+
hour: openTime.split(":")[0],
1904+
minute: openTime.split(":")[1],
1905+
});
19051906

1906-
const closeTimeToday = userCurrentTime
1907-
.clone()
1908-
.startOf("day")
1909-
.set({
1910-
hour: closeTime.split(":")[0],
1911-
minute: closeTime.split(":")[1],
1912-
});
1907+
const closeTimeToday = userCurrentTime
1908+
.clone()
1909+
.startOf("day")
1910+
.set({
1911+
hour: closeTime.split(":")[0],
1912+
minute: closeTime.split(":")[1],
1913+
});
19131914

1914-
const openingTimestamp = `<t:${openTimeToday.unix()}:t>`;
1915-
const closingTimestamp = `<t:${closeTimeToday.unix()}:t>`;
1915+
const openingTimestamp = `<t:${openTimeToday.unix()}:t>`;
1916+
const closingTimestamp = `<t:${closeTimeToday.unix()}:t>`;
19161917

1917-
const workingHoursField = config.workingHours.fieldValue
1918-
? `${config.workingHours.fieldValue}\n`
1919-
: `> {day}: {openingTime} to {closingTime}\n`;
1920-
workingHoursText += workingHoursField
1921-
.replace(/\{day\}/g, dayText)
1922-
.replace(/\{openingTime\}/g, openingTimestamp)
1923-
.replace(/\{closingTime\}/g, closingTimestamp);
1918+
const workingHoursField = config.workingHours.fieldValue
1919+
? `${config.workingHours.fieldValue}\n`
1920+
: `> {day}: {openingTime} to {closingTime}\n`;
1921+
workingHoursText += workingHoursField
1922+
.replace(/\{day\}/g, dayText)
1923+
.replace(/\{openingTime\}/g, openingTimestamp)
1924+
.replace(/\{closingTime\}/g, closingTimestamp);
1925+
}
1926+
} else if (config.workingHours.valueDays === "TODAY") {
1927+
workingHoursText +=
1928+
`${config.workingHours.fieldValue || "> {day}: {openingTime} to {closingTime}"}`
1929+
.replace(
1930+
/\{day\}/g,
1931+
dayToday.charAt(0).toUpperCase() + dayToday.slice(1),
1932+
)
1933+
.replace(
1934+
/\{openingTime\}/g,
1935+
`<t:${openingTimeToday.unix()}:t>`,
1936+
)
1937+
.replace(
1938+
/\{closingTime\}/g,
1939+
`<t:${closingTimeToday.unix()}:t>`,
1940+
);
19241941
}
19251942
ticketOpenEmbed.addFields({
19261943
name: config.workingHours.fieldTitle || "Working Hours",

0 commit comments

Comments
 (0)