Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
    def _get_room(self, actor, args):
        """
        :type actor: mudslingcore.objects.Character
        :type args: dict

        :raise AmbiguousMatch: When specified room matches multiple rooms.

        :rtype: mudslingcore.rooms.Room
        """
        if 'room' in args:
            # Attempt match.
            m = actor.match_object(args['room'], cls=Room)
            if len(m) > 1:
                raise errors.AmbiguousMatch(query=args['room'], matches=m)
            elif len(m) == 1:
                return m[0]  # Single match, that's our room!
            else:
                # Failed match. Usually this means we create. Let's make sure
                # this wasn't a wayward attempt at a literal match.
                if args['room'][:1] in literal_parsers:
                    # They were probably trying to use a literal, and it failed.
                    raise errors.FailedMatch(query=args['room'])

        # No matches. Let's create a room!
        if 'room' in args:
            names = parsers.StringListStaticParser.parse(args['room'])
        else:
            names = args['newRoomNames']  # Already parsed.
        return self._create_room(actor, names)
Exemplo n.º 3
0
 def run(self, this, actor, args):
     """
     :type this: mudslingcore.channels.ChannelUser
     :type actor: mudslingcore.channels.ChannelUser
     :type args: dict
     """
     alias = args['alias'].strip()
     if alias not in this.channels:
         raise errors.FailedMatch(msg="No channel alias '%s'." % alias)
     channel = actor.channels[alias]
     actor.remove_channel(alias)
     actor.tell("{yChannel {c", channel, "{y removed.")
Exemplo n.º 4
0
 def match_role(self, search):
     """
     Find a role.
     @param search: The role name to search for.
     @rtype: mudsling.perms.Role
     """
     matches = match_objlist(search, self.roles, varname="name")
     if len(matches) == 1:
         return matches[0]
     elif len(matches) > 1:
         raise errors.AmbiguousMatch(query=search, matches=matches)
     else:
         raise errors.FailedMatch(query=search)
Exemplo n.º 5
0
 def parse(self, input, actor=None):
     m = match.match_stringlist(input, self.stringlist,
                                exact=self.exact,
                                err=False,
                                case_sensitive=self.case_sensitive)
     if len(m) == 1:
         return m[0]
     msg = match.match_failed(
         matches=m,
         search=input,
         search_for=self.search_for,
         show=self.show,
         names=actor.name_for if actor is not None else str
     )
     err = errors.AmbiguousMatch(msg) if m else errors.FailedMatch(msg)
     if self.err:
         raise err
     else:
         return err
Exemplo n.º 6
0
 def parse(self, input, actor=None):
     if actor is None:
         return False
     m = self._match(actor, input)
     if len(m) == 1:
         return m[0]
     else:
         msg = match.match_failed(
             matches=m,
             search=input,
             search_for=self.search_for,
             show=self.show,
             names=actor.name_for if actor is not None else str
         )
         err = errors.AmbiguousMatch(msg) if m else errors.FailedMatch(msg)
         if self.err:
             raise err
         else:
             return err
Exemplo n.º 7
0
 def process_command(self, input, actor):
     cmdstr, sep, argstr = input[1:].partition(' ')
     matches = self.commands.match(cmdstr, self.ref(), actor)
     if len(matches) == 1:
         cls = matches[0]
     elif len(matches) > 1:
         raise errors.AmbiguousMatch("Ambiguous channel command.",
                                     query=cmdstr,
                                     matches=matches)
     else:
         raise errors.FailedMatch("Invalid command.", query=cmdstr)
     #: :type: mudsling.commands.Command
     cmd = cls(input,
               cmdstr,
               argstr,
               game=self.game,
               obj=self.ref(),
               actor=actor)
     if not cmd.match_syntax(argstr):
         self.tell(actor, *cmd.syntax_help().split('\n'))
     else:
         cmd.execute()
Exemplo n.º 8
0
    def find_topic(self, search, entryFilter=None):
        search = search.lower()
        if entryFilter is None:
            nameMap = self.name_map
            names = self.all_names
        else:
            entries = dict(x for x in self.entries.iteritems()
                           if entryFilter(x[1]))
            nameMap = self._name_map(entries)
            names = nameMap.keys()

        if search in nameMap:
            return nameMap[search]
        matches = [x for x in process.extract(search, names) if x[1] >= 85]
        if not matches:
            raise errors.FailedMatch(msg="No help found for '%s'." % search)
        elif (len(matches) == 1 or matches[0][1] - matches[1][1] >= 10
              or matches[0][0] == search.lower()):
            return self.name_map[matches[0][0]]

        # We know we have two or more elements that are 10 or more score apart.
        raise errors.AmbiguousMatch(query=search,
                                    matches=[x[0] for x in matches])