def run(self, this, actor, args): """ :type this: mudslingcore.objects.Character :type actor: mudslingcore.objects.Character :type args: dict """ #: :type: Room room = actor.location if not self.game.db.is_valid(room, Room): raise errors.CommandError("You must be in a room.") exits = room.match_exits(args['exit']) if len(exits) > 1: msg = "%r can match multiple exits: %s" msg = msg % (args['exit'], utils.string.english_list(exits)) raise errors.AmbiguousMatch(msg=msg) elif not exits: try: # Maybe it's an exit offset? exitDelta = int(args['exit']) if 0 < exitDelta <= len(room.exits): exits = [room.exits[exitDelta - 1]] except ValueError: raise errors.FailedMatch(query=args['exit']) exit = exits[0] dest = exit.dest msg = actor._format_msg( ["{gExit {c", exit, "{g has been {rdeleted{g."]) room.remove_exit(exit) actor.msg(msg) if self.switches['both'] and self.game.db.is_valid(dest, Room): others = dest.filter_exits(lambda e: e.dest == room) names = utils.string.english_list( ['{c' + actor.name_for(x) + '{g' for x in others]) for o in others: dest.remove_exit(o) actor.tell("{gExits {rdeleted{g from {m", dest, "{g: ", names)
def handle_unmatched_input_for(self, actor, raw): matches = self.match_exits(raw) if len(matches) == 1: f = self.exit_cmd(matches[0], actor=actor) return f(raw, raw, raw, self.game, matches[0], actor) elif len(matches) > 1: msg = "Which way? {raw!r} matches: {exits}".format( raw=raw, exits=utils.string.english_list( matches, formatter=lambda e: actor.name_for(e))) raise errors.CommandError(msg) else: return super(Room, self).handle_unmatched_input(raw)
def run(self, this, actor, args): room = actor.location if not self.game.db.is_valid(room, Room): raise errors.CommandError("You must be in a room.") #: :type: Exit exit = args['exit'] if not exit.allows(actor, 'rename'): actor.tell('{yYou are not allowed to rename {c', exit, '{y.') return names = args['newNames'] oldName = actor.name_for(exit) exit.set_names(names) actor.tell('{gExit {y', oldName, '{g renamed to {m', exit, " {g(with aliases: {m", ', '.join(names[1:]), '{g).')
def process_command(self, raw, game): cmdstr, _, argstr = raw.partition(' ') all_commands = self.all_commands() exact_matches = [c for c in all_commands if c.exactly_matches(raw)] if exact_matches: all_commands = exact_matches cmd_matches = [ c(raw, cmdstr, argstr, game, self, self.owner) for c in all_commands if c.matches(raw) ] syntax_matches = [c for c in cmd_matches if c.match_syntax(argstr)] if len(syntax_matches) > 1: raise errors.AmbiguousMatch(msg="Ambiguous Command", query=raw, matches=syntax_matches) if len(syntax_matches) < 1: if len(cmd_matches): msg = [c.failed_command_match_help() for c in cmd_matches] if msg: raise errors.CommandError(msg='\n'.join(msg)) return False syntax_matches[0].execute() return True