Skip to content

Commit cde103e

Browse files
committed
Added CommandInfo.reply()
1 parent f047250 commit cde103e

File tree

1 file changed

+14
-3
lines changed
  • addons/source-python/packages/source-python/commands

1 file changed

+14
-3
lines changed

addons/source-python/packages/source-python/commands/typed.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,13 @@ def parse_command(self, command):
466466
class CommandInfo(object):
467467
"""Stores command information for typed commands."""
468468

469-
def __init__(self, command, index=None, team_only=None):
469+
def __init__(self, command, typed_command_cls, index=None, team_only=None):
470470
"""Initializes the instance.
471471
472472
:param Command command:
473473
The actual Command instance.
474+
:param _TypedCommand typed_command_cls:
475+
Command this instance belongs to.
474476
:param int index:
475477
The index of the player that issued the command. None, if it's a
476478
server command.
@@ -479,9 +481,18 @@ def __init__(self, command, index=None, team_only=None):
479481
it's a server or client command.
480482
"""
481483
self.command = command
484+
self.typed_command_cls = typed_command_cls
482485
self.index = index
483486
self.team_only = team_only
484487

488+
def reply(self, msg):
489+
"""Reply to the command issuer.
490+
491+
:param str msg:
492+
Message to send.
493+
"""
494+
self.typed_command_cls.send_message(self, msg)
495+
485496

486497
# We can't integrate this into SayCommand, ServerCommand and ClientCommand,
487498
# because multiple callbacks are not supported by this system (because of the
@@ -547,13 +558,13 @@ def on_command(cls, command, *args):
547558
Parse the command, clean its arguments and execute the callback.
548559
"""
549560
# TODO: Translations!
550-
command_info = CommandInfo(command, *args)
561+
command_info = CommandInfo(command, cls, *args)
551562
try:
552563
command_node, args = cls.parser.parse_command(
553564
command_info.command)
554565
result = cls.on_clean_command(command_info, command_node, args)
555566
except ValidationError as e:
556-
cls.send_message(command_info, e.message)
567+
command_info.reply(e.message)
557568
else:
558569
return result
559570

0 commit comments

Comments
 (0)