mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Check for hats on startup
This commit is contained in:
@@ -130,6 +130,7 @@ client.on('clientReady', async () => {
|
|||||||
const isWearingHat = await client.redis.db.get('hat');
|
const isWearingHat = await client.redis.db.get('hat');
|
||||||
if (!isWearingHat) await client.redis.db.set('hat', false);
|
if (!isWearingHat) await client.redis.db.set('hat', false);
|
||||||
client.avatarChanger.isWearingHat = isWearingHat === 'true';
|
client.avatarChanger.isWearingHat = isWearingHat === 'true';
|
||||||
|
await client.avatarChanger.checkForUpdates();
|
||||||
client.avatarChanger.setInterval();
|
client.avatarChanger.setInterval();
|
||||||
|
|
||||||
// Set up disabled commands
|
// Set up disabled commands
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "160.0.1",
|
"version": "160.0.2",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+23
-13
@@ -32,6 +32,28 @@ module.exports = class AvatarChanger {
|
|||||||
await this.client.user.setAvatar(image);
|
await this.client.user.setAvatar(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async checkForUpdates() {
|
||||||
|
const today = new Date();
|
||||||
|
const holiday = this.isHoliday(today);
|
||||||
|
if (holiday && !this.isWearingHat) {
|
||||||
|
let { hat } = holiday;
|
||||||
|
if (Array.isArray(hat)) hat = hat[Math.floor(Math.random() * hat.length)];
|
||||||
|
try {
|
||||||
|
await this.setAvatar(hat);
|
||||||
|
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 && !holiday) {
|
||||||
|
try {
|
||||||
|
await this.setAvatar();
|
||||||
|
this.client.logger.info('[AVATAR] Reset avatar to default.');
|
||||||
|
} catch (err) {
|
||||||
|
this.client.logger.error(`[AVATAR] Failed to update avatar.\n${err.stack}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setInterval() {
|
setInterval() {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const midnight = new Date(Date.UTC(
|
const midnight = new Date(Date.UTC(
|
||||||
@@ -42,19 +64,7 @@ module.exports = class AvatarChanger {
|
|||||||
));
|
));
|
||||||
const msUntilNext = midnight - now;
|
const msUntilNext = midnight - now;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const today = new Date();
|
this.checkForUpdates();
|
||||||
const holiday = this.isHoliday(today);
|
|
||||||
if (holiday && !this.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.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}`));
|
|
||||||
}
|
|
||||||
this.setInterval();
|
this.setInterval();
|
||||||
}, msUntilNext);
|
}, msUntilNext);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user