mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-22 18:29:14 +02:00
Make holiday a getter
This commit is contained in:
@@ -7,7 +7,6 @@ module.exports = class AvatarChanger {
|
|||||||
Object.defineProperty(this, 'client', { value: client });
|
Object.defineProperty(this, 'client', { value: client });
|
||||||
|
|
||||||
this.isWearingHat = false;
|
this.isWearingHat = false;
|
||||||
this.holiday = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async editAvatar(hat) {
|
async editAvatar(hat) {
|
||||||
@@ -44,14 +43,12 @@ module.exports = class AvatarChanger {
|
|||||||
const today = new Date();
|
const today = new Date();
|
||||||
const holiday = this.isHoliday(today);
|
const holiday = this.isHoliday(today);
|
||||||
if (holiday && !this.holiday) {
|
if (holiday && !this.holiday) {
|
||||||
this.holiday = holiday;
|
|
||||||
let { hat } = holiday;
|
let { hat } = holiday;
|
||||||
if (Array.isArray(hat)) hat = hat[Math.floor(Math.random() * hat.length)];
|
if (Array.isArray(hat)) hat = hat[Math.floor(Math.random() * hat.length)];
|
||||||
this.setAvatar(hat)
|
this.setAvatar(hat)
|
||||||
.then(() => this.client.logger.info(`[AVATAR] Updated avatar to ${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}`));
|
.catch(err => this.client.logger.error(`[AVATAR] Failed to update avatar.\n${err.stack}`));
|
||||||
} else if (this.isWearingHat) {
|
} else if (this.isWearingHat) {
|
||||||
this.holiday = null;
|
|
||||||
this.setAvatar()
|
this.setAvatar()
|
||||||
.then(() => this.client.logger.info('[AVATAR] Reset avatar to default.'))
|
.then(() => this.client.logger.info('[AVATAR] Reset avatar to default.'))
|
||||||
.catch(err => this.client.logger.error(`[AVATAR] Failed to update avatar.\n${err.stack}`));
|
.catch(err => this.client.logger.error(`[AVATAR] Failed to update avatar.\n${err.stack}`));
|
||||||
@@ -60,6 +57,11 @@ module.exports = class AvatarChanger {
|
|||||||
}, msUntilNext);
|
}, msUntilNext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get holiday() {
|
||||||
|
const today = new Date();
|
||||||
|
return this.isHoliday(today) || null;
|
||||||
|
}
|
||||||
|
|
||||||
isHoliday(day) {
|
isHoliday(day) {
|
||||||
for (const holiday of holidayList) {
|
for (const holiday of holidayList) {
|
||||||
if (day.getUTCMonth() !== holiday.month - 1) continue;
|
if (day.getUTCMonth() !== holiday.month - 1) continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user