Skip to content

Dynamic menus and translates TypedServerCommand. #330

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

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Changed ValidationError to accept language and tokens.
  • Loading branch information
CookStar committed May 27, 2020
commit db326bde77c90c18582192d37ebafce5425775b3
9 changes: 4 additions & 5 deletions addons/source-python/packages/source-python/commands/typed.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@
# =============================================================================
# >> EXCEPTIONS
# =============================================================================
# TODO:
# We probably need to update these exceptions if we want to add translations.
class ValidationError(Exception):
def __init__(self, message=''):
def __init__(self, message='', language=None, **tokens):
self.message = message
self.language = language
self.tokens = tokens

class ArgumentError(ValidationError): pass
class ArgumentNumberMismatch(ArgumentError): pass
Expand Down Expand Up @@ -588,13 +588,12 @@ def on_command(cls, command, *args):

Parse the command, clean its arguments and execute the callback.
"""
# TODO: Translations!
info = CommandInfo(command, cls, *args)
try:
command_node, args = cls.parser.parse_command(info.command)
result = cls.on_clean_command(info, command_node, args)
except ValidationError as e:
info.reply(e.message)
info.reply(e.message, e.language, **e.tokens)
else:
if result is None:
return info.auto_command_return
Expand Down