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
Next Next commit
Changed CommandInfo.reply and send_message to accept language and tok…
…ens.
  • Loading branch information
CookStar committed May 11, 2020
commit 8c61cf7cca90cfd8c517edb3c17d805e32fe31de
24 changes: 14 additions & 10 deletions addons/source-python/packages/source-python/commands/typed.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,17 @@ def __init__(self, command, typed_command_cls, index=None, team_only=None):
self.index = index
self.team_only = team_only

def reply(self, msg):
def reply(self, msg, language=None, **tokens):
"""Reply to the command issuer.

:param str msg:
:param str/TranslationStrings msg:
Message to send.
:param str language:
Language to be used.
:param tokens:
Translation tokens for message.
"""
self.typed_command_cls.send_message(self, msg)
self.typed_command_cls.send_message(self, msg, language, **tokens)

def is_private_command(self):
"""Return ``True`` if it's a private command.
Expand Down Expand Up @@ -625,7 +629,7 @@ def manager(self):
raise NotImplementedError('Needs to be implemented by a sub class.')

@staticmethod
def send_message(command_info, message):
def send_message(command_info, message, language=None, **tokens):
"""Send a message."""
raise NotImplementedError('Needs to be implemented by a sub class.')

Expand All @@ -645,10 +649,10 @@ class TypedServerCommand(_TypedCommand):
manager = server_command_manager

@staticmethod
def send_message(command_info, message):
def send_message(command_info, message, language=None, **tokens):
# Translate the message if it's a :class:`TranslationStrings` object.
if isinstance(message, TranslationStrings):
message = message.get_string()
message = message.get_string(language, **tokens)

logger.log_message(message)

Expand Down Expand Up @@ -690,8 +694,8 @@ class TypedClientCommand(_TypedPlayerCommand):
manager = client_command_manager

@staticmethod
def send_message(command_info, message):
TextMsg(message, HudDestination.CONSOLE).send(command_info.index)
def send_message(command_info, message, language=None, **tokens):
TextMsg(message, HudDestination.CONSOLE).send(command_info.index, **tokens)

@classmethod
def get_auto_command_return(cls, info):
Expand All @@ -705,8 +709,8 @@ class TypedSayCommand(_TypedPlayerCommand):
manager = say_command_manager

@staticmethod
def send_message(command_info, message):
SayText2(message).send(command_info.index)
def send_message(command_info, message, language=None, **tokens):
SayText2(message).send(command_info.index, **tokens)

@classmethod
def get_auto_command_return(cls, info):
Expand Down