Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method to register custom message providers #538

Merged
merged 3 commits into from
Aug 6, 2023

Conversation

utarwyn
Copy link
Owner

@utarwyn utarwyn commented Aug 5, 2023

Description

This PR adds a method to register a message provider programmatically.
You can use it to display dynamic values that may change over time.

Few examples:

  • Display a dynamic bet to play a game
  • Display the date/hour
  • Display your own statistics

ℹ️ You can use the default variables in the provided messages

Usage example

You can use it this way:

const bot = new TicTacToe({ language: 'en' });
bot.addMessageProvider('game.title', () => 'Current date is ' + new Date());

Signature of the method (in TypeScript) is:

/**
 * Adds a message provider for a given key.
 * Key must exist, otherwise an error will be thrown.
 *
 * @param key key corresponding to the added provider
 * @param provider function that dynamically supplies the message
 */
addMessageProvider(key: string, provider: () => string): void;

🌂Closes #258
🚀 Will be available from v3.x.

@utarwyn utarwyn added the type: enhancement Features and feature requests. label Aug 5, 2023
@utarwyn utarwyn added this to the 3.x milestone Aug 5, 2023
@utarwyn utarwyn self-assigned this Aug 5, 2023
@utarwyn utarwyn linked an issue Aug 5, 2023 that may be closed by this pull request
@sonarcloud
Copy link

sonarcloud bot commented Aug 5, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@utarwyn utarwyn merged commit 614e92d into release/3.x Aug 6, 2023
5 checks passed
@utarwyn utarwyn deleted the feature/258-dynamic-locale branch August 6, 2023 11:17
@utarwyn utarwyn mentioned this pull request Aug 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Features and feature requests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Edit challenge message
1 participant