Skip to content

Commit 00f16be

Browse files
committed
fix: create guild settings to allow commands before configuration
1 parent f7d0519 commit 00f16be

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

src/client.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,30 @@ module.exports = class Client extends FrameworkClient {
4747
locales[name] = YAML.parse(data);
4848
});
4949

50+
this.keyv = new Keyv();
5051
/** @type {I18n} */
5152
this.i18n = new I18n('en-GB', locales);
5253
/** @type {TicketManager} */
5354
this.tickets = new TicketManager(this);
5455
this.config = config;
5556
this.log = log;
5657
this.supers = (process.env.SUPER ?? '').split(',');
58+
/** @param {import('discord.js/typings').Interaction} interaction */
59+
this.commands.interceptor = async interaction => {
60+
if (!interaction.inGuild()) return;
61+
const id = interaction.guildId;
62+
const cacheKey = `cache/known/guild:${id}`;
63+
if (await this.keyv.has(cacheKey)) return;
64+
await this.prisma.guild.upsert({
65+
create: {
66+
id,
67+
locale: this.i18n.locales.find(locale => locale === interaction.guild.preferredLocale), // undefined if not supported
68+
},
69+
update: {},
70+
where: { id },
71+
});
72+
await this.keyv.set(cacheKey, true);
73+
};
5774
}
5875

5976
async login(token) {
@@ -91,7 +108,6 @@ module.exports = class Client extends FrameworkClient {
91108
}, ms('6h'));
92109
}
93110

94-
this.keyv = new Keyv();
95111
return super.login(token);
96112
}
97113

src/i18n/en-GB.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ misc:
365365
this category.
366366
title: ❌ Insufficient roles
367367
no_categories:
368-
description: No ticket categories have been configured.
368+
description: |-
369+
No ticket categories have been configured.
370+
Configure your server at {url}.
369371
title: ❌ There are no ticket categories
370372
not_ticket:
371373
description: You can only use this command in tickets.

src/lib/tickets/utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = {
3333
new EmbedBuilder()
3434
.setColor(settings.errorColour)
3535
.setTitle(getMessage('misc.no_categories.title'))
36-
.setDescription(getMessage('misc.no_categories.description')),
36+
.setDescription(getMessage('misc.no_categories.description', { url: `${process.env.HTTP_EXTERNAL}/settings/${interaction.guildId}` })),
3737
],
3838
ephemeral: true,
3939
});
@@ -73,4 +73,4 @@ module.exports = {
7373
});
7474
}
7575
},
76-
};
76+
};

src/listeners/client/messageCreate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports = class extends Listener {
3838
new EmbedBuilder()
3939
.setColor(settings.errorColour)
4040
.setTitle(getMessage('misc.no_categories.title'))
41-
.setDescription(getMessage('misc.no_categories.description')),
41+
.setDescription(getMessage('misc.no_categories.description', { url: `${process.env.HTTP_EXTERNAL}/settings/${interaction.guildId}` })),
4242
],
4343
});
4444
} else if (settings.categories.length === 1) {

0 commit comments

Comments
 (0)