From d2115991f83ee9bd8be801ef2de6545df7b7d146 Mon Sep 17 00:00:00 2001 From: Michael King Date: Fri, 25 May 2007 17:31:29 +0000 Subject: [PATCH] * Merged in wipe-command branch into trunk (mking) --- apps/objects/models.py | 2 +- commands_general.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/apps/objects/models.py b/apps/objects/models.py index 0b6679a83f..fc68eb639b 100755 --- a/apps/objects/models.py +++ b/apps/objects/models.py @@ -353,7 +353,7 @@ class Object(models.Model): """ attribs = self.get_all_attributes() for attrib in attribs: - self.delete() + attrib.delete() def destroy(self): """ diff --git a/commands_general.py b/commands_general.py index f45ecc8b76..bb7929c550 100644 --- a/commands_general.py +++ b/commands_general.py @@ -339,6 +339,47 @@ def cmd_who(cdat): session.msg(retval) +def cmd_wipe(cdat): + """ + Wipe all attributes from a given object. + """ + session = cdat['session'] + pobject = session.get_pobject() + args = cdat['uinput']['splitted'][1:] + wildcard = wildcard_to_regexp(cdat['uinput']['root_chunk'][1]) + has_wildcard = False + + if wildcard: + has_wildcard = True + + if len(args) == 0: + session.msg("Wipe attributes from what?") + return + else: + target_obj = functions_db.standard_plr_objsearch(session, ' '.join(args)) + + # Use standard_plr_objsearch to handle duplicate/nonexistant results. + if not target_obj: + return + if target_obj.is_player() and not pobject.controls_other(target_obj): + session.msg("I'm sorry, you do not have permission to wipe attributes from that player.") + return + if has_wildcard: + import re + deleted_attribs = [] + attribs = target_obj.get_all_attributes() + for attrib in attribs: + pattern = re.compile(wildcard) + if pattern.match(attrib.name): + deleted_attribs.append(attrib.name) + attrib.delete() + session.message("Attribute(s) %s deleted." % ', '.join(deleted_attribs)) + return + else: + target_obj.clear_all_attributes() + session.msg("All non-hidden attributes deleted.") + return + def cmd_say(cdat): """ Room-based speech command.