diff --git a/commands/everyone.py b/commands/everyone.py index 546fc36..b880f94 100755 --- a/commands/everyone.py +++ b/commands/everyone.py @@ -117,6 +117,73 @@ class CmdPull(Command): self.caller.msg(f"You can't pull {item.name}.") +class CmdOpen(Command): + """ + Open something. + + Usage: + + open + """ + key = "open" + + def func(self): + """ + Call an item's 'do_open' method. + + Note that if the room the caller is in has a 'do_open', we + call that first to see if the room can open something (like an + exit). + """ + opener = self.caller + room = opener.location + to_open = self.args.strip() + + if room.has_method('do_open'): + if room.do_open(opener, to_open): + return + + item = opener.search(to_open) + if item: + if item.has_method('do_open'): + item.do_open(opener) + else: + opener.msg(f"You can't open {item.name}.") + + +class CmdClose(Command): + """ + Close something. + + Usage: + + close + """ + key = "close" + + def func(self): + """Call the 'do_close' method. + + Note that if the room the caller is in has a 'do_close', we + call that first to see if the room can close something (like + an exit). + """ + closer = self.caller + room = closer.location + to_open = self.args.strip() + + if room.has_method('do_close'): + if room.do_close(closer, to_open): + return + + item = closer.search(to_open) + if item: + if item.has_method('do_close'): + item.do_close(closer) + else: + closer.msg(f"You can't close {item.name}.") + + class CmdWhisper(MuxCommand): """ Speak privately as your character to another.