Skip to content

Strings ​

Everything Ruby says comes from a string table: a dictionary of KEY → message. Servers can reword any message in config.yaml without touching code, and cogs can add their own.

Rewording messages ​

Add a strings: section to config.yaml. Your strings are merged over the defaults, so you only list the ones you want to change:

yaml
strings:
  NOT_OWNER: "Nice try."
  COMMAND_NOT_FOUND: "I don't know that one. Try r!help."

Keep the {placeholders} from the original, or the message loses that part, e.g. {timestamp} in COMMAND_ON_COOLDOWN.

Ruby's built-in strings ​

KeyDefaultPlaceholders
NO_SERVERThis command is only supported in a server!
UNSUPPORTED_CHANNELUnsupported channel type!
NOT_OWNERYou are not the owner of the bot!
COMMAND_ON_COOLDOWN**Please slow down** - You can use this command again <t:{timestamp}:R>.timestamp (Unix time)
COMMAND_NOT_FOUNDCommand not found!
COMMAND_MISSING_PERMISSIONYou are missing the permission `{permission}` to run this command!permission
COMMAND_MISSING_PERMISSIONSYou are missing the permissions `{permissions}` to run this command!permissions
COMMAND_BOT_MISSING_PERMISSIONI am missing the permission `{permission}` to run this command!permission
COMMAND_BOT_MISSING_PERMISSIONSI am missing the permissions `{permissions}` to run this command!permissions
UNKNOWN_ERRORUnknown error.
UNKNOWN_COMMAND_ERRORUnknown command error.

Each cog adds its own keys too. Look for DEFAULT_STRINGS at the top of the cog's file.

Strings in your own cogs ​

Make a table that extends Ruby's, and a small get() helper that looks keys up in it:

python
import ruby.utils
from ruby.utils import get_string

# fmt: off
DEFAULT_STRINGS = ruby.utils.DEFAULT_STRINGS | {
    "WAVE_DONE": "{member} waved! That's wave number **{count}**.",
    "WAVE_TOO_MANY": "You've waved enough for one day.",
}
# fmt: on


def get(string: str) -> str:
    return get_string(string, default_table=DEFAULT_STRINGS)

Then use it everywhere you'd write a message:

python
await success(ctx, get("WAVE_DONE").format(member=ctx.author.mention, count=3))

The lookup order is:

  1. strings: in config.yaml
  2. your cog's DEFAULT_STRINGS
  3. default (the second argument to get_string, "" if not given)

Prefix keys with the cog's name

All cogs share the config's strings: section, so use BIRTHDAY_SET and COUPON_INVALID, not SET and INVALID.

Keys or text in success() and error() ​

success() and error() look up whatever you pass them in Ruby's built-in table, and send it as written if there's no such key. So both of these work:

python
await error(ctx, "NO_SERVER")                    # looked up: "This command is only supported in a server!"
await error(ctx, "That code doesn't exist.")     # not a key, so sent as written

For your cog's keys, either look them up first (error(ctx, get("WAVE_TOO_MANY"))) or pass your table:

python
await error(ctx, "WAVE_TOO_MANY", default_table=DEFAULT_STRINGS)