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:
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
| Key | Default | Placeholders |
|---|---|---|
NO_SERVER | This command is only supported in a server! | |
UNSUPPORTED_CHANNEL | Unsupported channel type! | |
NOT_OWNER | You 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_FOUND | Command not found! | |
COMMAND_MISSING_PERMISSION | You are missing the permission `{permission}` to run this command! | permission |
COMMAND_MISSING_PERMISSIONS | You are missing the permissions `{permissions}` to run this command! | permissions |
COMMAND_BOT_MISSING_PERMISSION | I am missing the permission `{permission}` to run this command! | permission |
COMMAND_BOT_MISSING_PERMISSIONS | I am missing the permissions `{permissions}` to run this command! | permissions |
UNKNOWN_ERROR | Unknown error. | |
UNKNOWN_COMMAND_ERROR | Unknown 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:
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:
await success(ctx, get("WAVE_DONE").format(member=ctx.author.mention, count=3))The lookup order is:
strings:inconfig.yaml- your cog's
DEFAULT_STRINGS default(the second argument toget_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:
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 writtenFor your cog's keys, either look them up first (error(ctx, get("WAVE_TOO_MANY"))) or pass your table:
await error(ctx, "WAVE_TOO_MANY", default_table=DEFAULT_STRINGS)