Closed bowenjw closed 1 year ago
yarn test
yarn lint
Moved client and other classes to a client folder that encapsulates the base functions of the discord bot.
./src/Client
interactionCreate
./src/bot.ts
Moved discord date to sting function from prototypes to client types
Date.prototype.toDiscordString = function(format?: TimeCode) { const code = Math.floor(this.getTime() / 1000); if (!format) return `<t:${code}`; return `<t:${code}:${format}>`; };
example using the ping
export default new Interaction<ButtonInteraction>() .setName('ping') .setExecute(async (interaction) => { interaction.reply({ content: `${t({ locale: interaction.locale, key: 'button', ns:'ping', })} 🏓`, components: [getPingButton(interaction.locale)], ephemeral: true, }); });
Example ready event
export default new Event() .setName(Events.ClientReady) .setOnce(true) .setExecute(async (client:Client) => { console.log(`\nReady! Logged in as ${client.user?.tag} (${client.user?.id})\n`); });
export default new ChatInputCommand() .setBuilder(builder) .setGlobal(true) .setExecute(function) .setAutocomplete(function)
export default new ContextMenuCommand() .setBuilder(builder) .setGlobal(false) .setExecute(function);
i18n moved in to its own folder ./src/i18n/
./src/i18n/
This folder contains an implementations of Project Fluent
In your main file call the init function.
import { init } from './i18n'; init(path: string, options?: { hasGlobal?: boolean, fallback: Locale });
This function sets the file path where Localization files are stored and additional options:
hasGlobal: if a gobal.ftl file in present in your Localization directory
hasGlobal
gobal.ftl
fallback: deafalt language
fallback
translation options
interface tOptions { key: string ns?: string ons?: string locale?: Locale | LocaleString args?: Record<string, FluentVariable> }
key: command-name, namespace: command, locale: fallback language
command-name
command
t({ key: 'command-name', ns: 'command' }
key: count-reply, namespace: count, locale: locale of the interaction args: username and length
count-reply
count
t({ locale: interaction.locale, key: 'count-reply', ns: 'count', args: { 'username': message.author.username, 'length':length.toString(), } })
yarn test
does not throw any errorsyarn lint
to make sure my codebase is consistentCore Updates
Moved client and other classes to a client folder that encapsulates the base functions of the discord bot.
./src/Client
interactionCreate
event has been moved in to client./src/bot.ts
Date
Moved discord date to sting function from prototypes to client types
Interactions
example using the ping
Event
Example ready event
Chat Command
Context Command
i18n
i18n moved in to its own folder
./src/i18n/
This folder contains an implementations of Project Fluent
How to use
In your main file call the init function.
This function sets the file path where Localization files are stored and additional options:
hasGlobal
: if agobal.ftl
file in present in your Localization directoryfallback
: deafalt languageTranslation
translation options
Example
key:
command-name
, namespace:command
, locale: fallback languagekey:
count-reply
, namespace:count
, locale: locale of the interaction args: username and length