From fd713e4a7f73780482033aecf76ed7214188eb0a Mon Sep 17 00:00:00 2001 From: Yuzu Date: Tue, 7 Jun 2022 13:00:16 +0700 Subject: [PATCH] Localized help --- src/discord/Help.ts | 55 +++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/discord/Help.ts b/src/discord/Help.ts index 474184c..b218c4e 100644 --- a/src/discord/Help.ts +++ b/src/discord/Help.ts @@ -1,62 +1,60 @@ import { CommandInteraction, Interaction, Message } from 'discord.js'; +import { I18n } from 'i18n'; import DiscordProvider from '../providers/Discord'; import Cache from '../providers/Cache'; import DiscordModule, { HybridInteractionMessage } from '../utils/DiscordModule'; import { sendHybridInteractionMessageResponse, makeInfoEmbed } from '../utils/DiscordMessage'; +import Locale from '../services/Locale'; +import { Guild as PrismaGuild } from '@prisma/client'; const EMBEDS = { - INFO: async (data: Message | Interaction) => { - let GuildCache = await Cache.getCachedGuild(data.guildId!); - - // TODO: Better error handling - if (typeof GuildCache === 'undefined') throw new Error('Guild not found'); - - let prefix = GuildCache.prefix || '>'; + INFO: async (data: HybridInteractionMessage, locale: I18n, GuildCache: PrismaGuild) => { + let prefix = GuildCache.prefix; + const bot = DiscordProvider.client.user!; let _e = makeInfoEmbed({ icon: '๐Ÿ’Œ', - title: `Help - ${DiscordProvider.client.user?.username}`, - description: `\u200b\n๐Ÿ“ฐโ€‚**Info**\nYumi is currently undergoing complete rewrite, as expected, losing many of her functionality. All of the features will be re-implemented.\n\n๐Ÿท๏ธโ€‚**Prefix**\nYou can call me using \`\`${prefix.replaceAll( - '`', - '`โ€‹' - )}\`\`, <@${ - DiscordProvider.client.user?.id - }> or \`\`/slash command\`\`\n\n๐Ÿ’ปโ€‚**Available commands**`, + title: locale.__('help.title', bot.username), + description: `\u200b\n๐Ÿท๏ธโ€‚**${locale.__('help.prefix_title')}**\n${locale.__( + 'help.prefix_description', + prefix.replaceAll('`', '`โ€‹'), + `<@${bot.id}>` + )}\n\n๐Ÿ’ปโ€‚**${locale.__('help.available_commands')}**`, fields: [ { - name: 'โ˜•โ€‚General', + name: `โ˜•โ€‚${locale.__('help.general')}`, value: `help, ping, invite, userinfo, stats`, inline: true }, { - name: '๐ŸŽตโ€‚Music', + name: `๐ŸŽตโ€‚${locale.__('help.music')}`, value: `play (p), search, skip, pause, resume, queue (q), nowplaying (np), loop, join, leave (disconnect, dc)`, inline: true }, { - name: '๐ŸŽฎโ€‚Games', + name: `๐ŸŽฎโ€‚${locale.__('help.games')}`, value: `osu`, inline: true }, { - name: '๐Ÿ”โ€‚Admin', + name: `๐Ÿ”โ€‚${locale.__('help.admin')}`, value: `settings, say, membershipscreening (ms)`, inline: true }, { - name: '๐Ÿ”งโ€‚Developer', + name: `๐Ÿ”งโ€‚${locale.__('help.developer')}`, value: 'debug, interactions, serviceannouncement', inline: true }, { name: '\u200b', - value: '**Made with ๐Ÿ’– and [open source](https://github.com/YuzuZensai/Yumi)**', + value: `**${locale.__('help.footer')}(https://github.com/YuzuZensai/Yumi)**`, inline: false } ], - user: data instanceof Interaction ? data.user : data.author + user: data.getUser() }); _e.setThumbnail(`${DiscordProvider.client.user?.displayAvatarURL()}?size=4096`); return _e; @@ -77,11 +75,20 @@ export default class Help extends DiscordModule { } async run(data: HybridInteractionMessage, args: any) { + const guild = data.getGuild(); + const member = data.getMember(); + + if (!guild || !member) return; + + const GuildCache = await Cache.getCachedGuild(guild.id); + if (!GuildCache) return; + + const locale = await Locale.getGuildLocale(guild.id); + const message = await sendHybridInteractionMessageResponse(data, { - embeds: [await EMBEDS.INFO(data.getRaw())] + embeds: [await EMBEDS.INFO(data, locale, GuildCache)] }); - if (message && data.isMessage()) - return new HybridInteractionMessage(message).getMessage().react('โ™ฅ'); + if (message && data.isMessage()) return new HybridInteractionMessage(message).getMessage().react('โ™ฅ'); } }