Permalink
Browse files

Added CommandInfo.reply()

  • Loading branch information...
Ayuto committed Dec 15, 2018
1 parent f047250 commit cde103ea4c5a5e02d29b51a627d0452cc314cb56
Showing with 14 additions and 3 deletions.
  1. +14 −3 addons/source-python/packages/source-python/commands/typed.py
@@ -466,11 +466,13 @@ def parse_command(self, command):
class CommandInfo(object):
"""Stores command information for typed commands."""

def __init__(self, command, index=None, team_only=None):
def __init__(self, command, typed_command_cls, index=None, team_only=None):
"""Initializes the instance.
:param Command command:
The actual Command instance.
:param _TypedCommand typed_command_cls:
Command this instance belongs to.
:param int index:
The index of the player that issued the command. None, if it's a
server command.
@@ -479,9 +481,18 @@ def __init__(self, command, index=None, team_only=None):
it's a server or client command.
"""
self.command = command
self.typed_command_cls = typed_command_cls
self.index = index
self.team_only = team_only

def reply(self, msg):
"""Reply to the command issuer.
:param str msg:
Message to send.
"""
self.typed_command_cls.send_message(self, msg)


# We can't integrate this into SayCommand, ServerCommand and ClientCommand,
# because multiple callbacks are not supported by this system (because of the
@@ -547,13 +558,13 @@ def on_command(cls, command, *args):
Parse the command, clean its arguments and execute the callback.
"""
# TODO: Translations!
command_info = CommandInfo(command, *args)
command_info = CommandInfo(command, cls, *args)
try:
command_node, args = cls.parser.parse_command(
command_info.command)
result = cls.on_clean_command(command_info, command_node, args)
except ValidationError as e:
cls.send_message(command_info, e.message)
command_info.reply(e.message)
else:
return result

0 comments on commit cde103e

Please sign in to comment.