Make holiday a getter

This commit is contained in:
lilyissillyyy
2026-02-17 17:23:37 -05:00
parent d5d0814947
commit 183424e081
+5 -3
View File
@@ -7,7 +7,6 @@ module.exports = class AvatarChanger {
Object.defineProperty(this, 'client', { value: client });
this.isWearingHat = false;
this.holiday = null;
}
async editAvatar(hat) {
@@ -44,14 +43,12 @@ module.exports = class AvatarChanger {
const today = new Date();
const holiday = this.isHoliday(today);
if (holiday && !this.holiday) {
this.holiday = holiday;
let { hat } = holiday;
if (Array.isArray(hat)) hat = hat[Math.floor(Math.random() * hat.length)];
this.setAvatar(hat)
.then(() => this.client.logger.info(`[AVATAR] Updated avatar to ${hat}!`))
.catch(err => this.client.logger.error(`[AVATAR] Failed to update avatar.\n${err.stack}`));
} else if (this.isWearingHat) {
this.holiday = null;
this.setAvatar()
.then(() => this.client.logger.info('[AVATAR] Reset avatar to default.'))
.catch(err => this.client.logger.error(`[AVATAR] Failed to update avatar.\n${err.stack}`));
@@ -60,6 +57,11 @@ module.exports = class AvatarChanger {
}, msUntilNext);
}
get holiday() {
const today = new Date();
return this.isHoliday(today) || null;
}
isHoliday(day) {
for (const holiday of holidayList) {
if (day.getUTCMonth() !== holiday.month - 1) continue;