Skip to content

Commit

Permalink
fix: create guild settings to allow commands before configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
eartharoid committed Jan 15, 2024
1 parent f7d0519 commit 00f16be
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
18 changes: 17 additions & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,30 @@ module.exports = class Client extends FrameworkClient {
locales[name] = YAML.parse(data);
});

this.keyv = new Keyv();
/** @type {I18n} */
this.i18n = new I18n('en-GB', locales);
/** @type {TicketManager} */
this.tickets = new TicketManager(this);
this.config = config;
this.log = log;
this.supers = (process.env.SUPER ?? '').split(',');
/** @param {import('discord.js/typings').Interaction} interaction */
this.commands.interceptor = async interaction => {
if (!interaction.inGuild()) return;
const id = interaction.guildId;
const cacheKey = `cache/known/guild:${id}`;
if (await this.keyv.has(cacheKey)) return;
await this.prisma.guild.upsert({
create: {
id,
locale: this.i18n.locales.find(locale => locale === interaction.guild.preferredLocale), // undefined if not supported
},
update: {},
where: { id },
});
await this.keyv.set(cacheKey, true);
};
}

async login(token) {
Expand Down Expand Up @@ -91,7 +108,6 @@ module.exports = class Client extends FrameworkClient {
}, ms('6h'));
}

this.keyv = new Keyv();
return super.login(token);
}

Expand Down
4 changes: 3 additions & 1 deletion src/i18n/en-GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ misc:
this category.
title: ❌ Insufficient roles
no_categories:
description: No ticket categories have been configured.
description: |-
No ticket categories have been configured.
Configure your server at {url}.
title: ❌ There are no ticket categories
not_ticket:
description: You can only use this command in tickets.
Expand Down
4 changes: 2 additions & 2 deletions src/lib/tickets/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = {
new EmbedBuilder()
.setColor(settings.errorColour)
.setTitle(getMessage('misc.no_categories.title'))
.setDescription(getMessage('misc.no_categories.description')),
.setDescription(getMessage('misc.no_categories.description', { url: `${process.env.HTTP_EXTERNAL}/settings/${interaction.guildId}` })),
],
ephemeral: true,
});
Expand Down Expand Up @@ -73,4 +73,4 @@ module.exports = {
});
}
},
};
};
2 changes: 1 addition & 1 deletion src/listeners/client/messageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = class extends Listener {
new EmbedBuilder()
.setColor(settings.errorColour)
.setTitle(getMessage('misc.no_categories.title'))
.setDescription(getMessage('misc.no_categories.description')),
.setDescription(getMessage('misc.no_categories.description', { url: `${process.env.HTTP_EXTERNAL}/settings/${interaction.guildId}` })),
],
});
} else if (settings.categories.length === 1) {
Expand Down

0 comments on commit 00f16be

Please sign in to comment.