From d4f76b3d2e0033c96515552ab02f1843321b9f6c Mon Sep 17 00:00:00 2001 From: Tehom Date: Thu, 18 Oct 2018 23:12:22 -0400 Subject: [PATCH] Add a simple 'force' command to force objects to execute commands. --- evennia/commands/default/admin.py | 32 +++++++++++++++++++- evennia/commands/default/cmdset_character.py | 1 + evennia/commands/default/tests.py | 3 ++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/evennia/commands/default/admin.py b/evennia/commands/default/admin.py index 08890dfcdc..c260abaa2e 100644 --- a/evennia/commands/default/admin.py +++ b/evennia/commands/default/admin.py @@ -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 = + + 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)) diff --git a/evennia/commands/default/cmdset_character.py b/evennia/commands/default/cmdset_character.py index cfc8a30ca4..438996f536 100644 --- a/evennia/commands/default/cmdset_character.py +++ b/evennia/commands/default/cmdset_character.py @@ -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()) diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index 19277c168a..b0f5211c6f 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -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):