Merge pull request #1698 from TehomCD/add_force_command

Add a simple 'force' command to force objects to execute commands.
This commit is contained in:
Griatch 2018-10-21 00:07:06 +02:00 committed by GitHub
commit 18cf0ca6c9
3 changed files with 35 additions and 1 deletions

View file

@ -17,7 +17,7 @@ PERMISSION_HIERARCHY = [p.lower() for p in settings.PERMISSION_HIERARCHY]
# limit members for API inclusion
__all__ = ("CmdBoot", "CmdBan", "CmdUnban",
"CmdEmit", "CmdNewPassword", "CmdPerm", "CmdWall")
"CmdEmit", "CmdNewPassword", "CmdPerm", "CmdWall", "CmdForce")
class CmdBoot(COMMAND_DEFAULT_CLASS):
@ -513,3 +513,33 @@ class CmdWall(COMMAND_DEFAULT_CLASS):
message = "%s shouts \"%s\"" % (self.caller.name, self.args)
self.msg("Announcing to all connected sessions ...")
SESSIONS.announce_all(message)
class CmdForce(COMMAND_DEFAULT_CLASS):
"""
forces an object to execute a command
Usage:
@force <object>=<command string>
Example:
@force bob=get stick
"""
key = "@force"
locks = "cmd:perm(spawn) or perm(Builder)"
help_category = "Building"
perm_used = "edit"
def func(self):
"""Implements the force command"""
if not self.lhs or not self.rhs:
self.caller.msg("You must provide a target and a command string to execute.")
return
targ = self.caller.search(self.lhs)
if not targ:
return
if not targ.access(self.caller, self.perm_used):
self.caller.msg("You don't have permission to force them to execute commands.")
return
targ.execute_cmd(self.rhs)
self.caller.msg("You have forced %s to: %s" % (targ, self.rhs))

View file

@ -57,6 +57,7 @@ class CharacterCmdSet(CmdSet):
self.add(admin.CmdEmit())
self.add(admin.CmdPerm())
self.add(admin.CmdWall())
self.add(admin.CmdForce())
# Building and world manipulation
self.add(building.CmdTeleport())

View file

@ -243,6 +243,9 @@ class TestAdmin(CommandTest):
def test_ban(self):
self.call(admin.CmdBan(), "Char", "Name-Ban char was added.")
def test_force(self):
self.call(admin.CmdForce(), "Char2=say test", 'Char2(#7) says, "test"|You have forced Char2 to: say test')
class TestAccount(CommandTest):