Skip to content

RuleStore

Imani brown edited this page Aug 1, 2024 · 4 revisions

The RuleStore class provides an organized way to manage transformation rules for your variables. It works in conjunction with the Transformer class, which uses these rules to match and replace placeholders in text strings based on the identifiers defined within the RuleStore.

RuleStore(rules: Rule[]): RuleStore

  • Purpose: Manages and organizes multiple transformation rules for Discord bot messages.
  • Parameters:
    • rules: An array of Rule objects that define how text should be transformed.
  • Returns: A RuleStore instance that can be used to apply and manage the rules.

Example without createRule function

const rules = new RuleStore([
  {
    identifier: "{username}",
    event: "interactionCreate",
    definition: (interaction) => {
      return interaction.member?.user.username;
    },
  },
]);

Example with createRule function to maintain TypeScript types:

const rules = new RuleStore([
  createRule("{username}", "interactionCreate", (interaction) => {
    return interaction.member?.user.username;
  }),
]);
Clone this wiki locally