Skip to content

Commit

Permalink
Add user locale based localization on interaction commands and update…
Browse files Browse the repository at this point in the history
… codes for modifying interaction object
  • Loading branch information
chimpdev committed Sep 29, 2024
1 parent 6daf452 commit 7e44578
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 243 deletions.
30 changes: 15 additions & 15 deletions server/src/bot/commands/features/emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ module.exports = {

isGuildOnly: true,
execute: async interaction => {
if (!interaction.member.permissions.has(Discord.PermissionFlagsBits.CreateGuildExpressions)) return interaction.reply(await interaction.guild.translate('commands.shared.errors.missing_permissions'));
if (!interaction.guild.members.me.permissions.has(Discord.PermissionFlagsBits.ManageGuildExpressions) && !interaction.guild.members.me.permissions.has(Discord.PermissionFlagsBits.CreateGuildExpressions)) return interaction.reply(await interaction.guild.translate('commands.emoji.errors.missing_bot_permissions'));
if (!interaction.member.permissions.has(Discord.PermissionFlagsBits.CreateGuildExpressions)) return interaction.reply(await interaction.translate('commands.shared.errors.missing_permissions'));
if (!interaction.guild.members.me.permissions.has(Discord.PermissionFlagsBits.ManageGuildExpressions) && !interaction.guild.members.me.permissions.has(Discord.PermissionFlagsBits.CreateGuildExpressions)) return interaction.reply(await interaction.translate('commands.emoji.errors.missing_bot_permissions'));

if (!interaction.deferred && !interaction.replied) await interaction.deferReply();

const userQuarantined = await findQuarantineEntry.single('USER_ID', interaction.user.id, 'EMOJIS_QUICKLY_UPLOAD').catch(() => false);
if (userQuarantined) return interaction.followUp(await interaction.guild.translate('commands.emoji.errors.user_quarantined'));
if (userQuarantined) return interaction.followUp(await interaction.translate('commands.emoji.errors.user_quarantined'));

const group = interaction.options.getSubcommandGroup(false);

switch (group) {
case 'pack':
var packId = interaction.options.getString('pack');
var pack = await EmojiPack.findOne({ id: packId });
if (!pack) return interaction.followUp(await interaction.guild.translate('commands.emoji.errors.pack_not_found'));
if (!pack) return interaction.followUp(await interaction.translate('commands.emoji.errors.pack_not_found'));

var currentlyUploadingEmojiPack = client.currentlyUploadingEmojiPack.get(interaction.guild.id);
if (currentlyUploadingEmojiPack) {
Expand All @@ -70,19 +70,19 @@ module.exports = {
.addComponents(
new Discord.ButtonBuilder()
.setStyle(Discord.ButtonStyle.Link)
.setLabel(await interaction.guild.translate('commands.emoji.errors.currently_uploading.button_label'))
.setLabel(await interaction.translate('commands.emoji.errors.currently_uploading.button_label'))
.setURL(`https://discord.com/channels/${interaction.guild.id}/${interaction.channel.id}/${currentlyUploadingEmojiPack.messageId}`)
)
];

return interaction.followUp({
content: await interaction.guild.translate('commands.emoji.errors.currently_uploading.message', { packName: currentlyUploadingEmojiPack.name }),
content: await interaction.translate('commands.emoji.errors.currently_uploading.message', { packName: currentlyUploadingEmojiPack.name }),
components
});
}

var message = await interaction.followUp({
content: await interaction.guild.translate('commands.emoji.groups.pack.subcommands.upload.uploading', {
content: await interaction.translate('commands.emoji.groups.pack.subcommands.upload.uploading', {
emojiCount: pack.emoji_ids.length,
remainingSeconds: pack.emoji_ids.length
})
Expand All @@ -99,7 +99,7 @@ module.exports = {
const createdEmoji = await interaction.guild.emojis.create({
attachment: getEmojiURL(`packages/${packId}/${emoji.id}`, emoji.animated),
name: `${pack.name}_${pack.emoji_ids.indexOf(emoji) + 1}`,
reason: await interaction.guild.translate('commands.emoji.groups.pack.subcommands.upload.reason', {
reason: await interaction.translate('commands.emoji.groups.pack.subcommands.upload.reason', {
username: interaction.user.username,
userId: interaction.user.id,
packId,
Expand All @@ -109,7 +109,7 @@ module.exports = {
}).catch(() => null);

if (!createdEmoji) {
message.edit(await interaction.guild.translate('commands.emoji.errors.pack_failed', {
message.edit(await interaction.translate('commands.emoji.errors.pack_failed', {
index,
remainingSeconds: pack.emoji_ids.length - index
}));
Expand All @@ -127,7 +127,7 @@ module.exports = {

index++;

await message.edit(await interaction.guild.translate('commands.emoji.groups.pack.subcommands.upload.uploaded', {
await message.edit(await interaction.translate('commands.emoji.groups.pack.subcommands.upload.uploaded', {
index: index,
total: pack.emoji_ids.length,
remainingSeconds: pack.emoji_ids.length - index
Expand All @@ -138,26 +138,26 @@ module.exports = {

client.currentlyUploadingEmojiPack.delete(interaction.guild.id);

if (createdEmojis.length === 0) return message.edit(await interaction.guild.translate('commands.emoji.groups.pack.subcommands.upload.no_emojis_uploaded', { packName: pack.name }));
if (createdEmojis.length === 0) return message.edit(await interaction.translate('commands.emoji.groups.pack.subcommands.upload.no_emojis_uploaded', { packName: pack.name }));

await EmojiPack.updateOne({ id: packId }, { $inc: { downloads: 1 } });

return message.edit({ content: `${await interaction.guild.translate('commands.emoji.groups.pack.subcommands.upload.completed', { packName: pack.name })}\n\n${createdEmojis.map(({ emoji }, index) => `${index + 1}. ${emoji}`).join('\n')}` });
return message.edit({ content: `${await interaction.translate('commands.emoji.groups.pack.subcommands.upload.completed', { packName: pack.name })}\n\n${createdEmojis.map(({ emoji }, index) => `${index + 1}. ${emoji}`).join('\n')}` });
case null:
var id = interaction.options.getString('emoji');
var emoji = await Emoji.findOne({ id });
if (!emoji) return interaction.followUp(await interaction.guild.translate('commands.emoji.errors.emoji_not_found'));
if (!emoji) return interaction.followUp(await interaction.translate('commands.emoji.errors.emoji_not_found'));

interaction.guild.emojis.create({ attachment: getEmojiURL(emoji.id, emoji.animated), name: emoji.name })
.then(async createdEmoji => {
emoji.updateOne({ $inc: { downloads: 1 } });

return interaction.followUp({ content: `${await interaction.guild.translate('commands.emoji.subcommands.upload.uploaded')} ${createdEmoji}` });
return interaction.followUp({ content: `${await interaction.translate('commands.emoji.subcommands.upload.uploaded')} ${createdEmoji}` });
})
.catch(async error => {
logger.error(`Failed to upload emoji ${emoji.id} to ${interaction.guild.id}: ${error.message}`);

return interaction.followUp(await interaction.guild.translate('commands.emoji.errors.emoji_failed'));
return interaction.followUp(await interaction.translate('commands.emoji.errors.emoji_failed'));
});

break;
Expand Down
Loading

0 comments on commit 7e44578

Please sign in to comment.