Exemplo n.º 1
0
 def _reject(self, last_reason, reject=None):
     if reject:
         self._matches.remove(reject)
     if self._matches:
         return
     reject_format = {'command': self._command, 'verb': self._command.split(' ')[0]}
     if reject:
         extra = find_extra(reject.verb, 0, self._command)
         if extra:
             extra = extra.strip()
         reject_format['quantity'] = reject.quantity
         reject_format['verb'] = ' '.join(reject.verb)
         reject_format['extra'] = extra
         reject_format['prep'] = reject.prep
         if extra and reject.prep:
             prep_ix = extra.find(reject.prep)
             if prep_ix == -1:
                 reject_format['target'] = extra
             else:
                 reject_format['target'] = extra[:prep_ix].strip()
             reject_format['object'] = extra[prep_ix + len(reject.prep):]
         else:
             reject_format['target'] = extra
         if last_reason in (INVALID_TARGET, ABSENT_TARGET):
             if not reject_format['target']:
                 last_reason = MISSING_TARGET
             elif last_reason == ABSENT_TARGET:
                 try:
                     last_reason = reject.action.target_class[0].absent_msg
                 except (IndexError, AttributeError):
                     pass
     raise ParseError(last_reason.format(**reject_format))
Exemplo n.º 2
0
def email(verb, args, command, **_):
    if len(args) < 2:
        return "Player and message required"
    player = um.find_player(args[0])
    if not player:
        return "Player not found"
    user = db.load_object(player.user_id, User)
    message = find_extra(verb, 1, command)
    return email.send_targeted_email("Lampost Message", message, [user])
Exemplo n.º 3
0
def patch(target, verb, args, command, **_):
    try:
        split_ix = args.index(":")
        prop = args[split_ix + 1]
        new_value = find_extra(verb, split_ix + 2, command)
    except (ValueError, IndexError):
        return "Syntax -- 'patch [target] [:] [prop_name] [new_value]'"
    if not new_value:
        return "New value required"
    if new_value == "None":
        new_value = None
    patch_object(target, prop, new_value)
    return "Object successfully patched"
Exemplo n.º 4
0
def patch_db(verb, args, command, **_):
    if len(args) == 0:
        return "Type required."
    obj_type = args[0]
    if len(args) == 1:
        return "Object id required."
    obj_id = args[1]
    if len(args) == 2:
        return "Property name required."
    prop = args[2]
    new_value = find_extra(verb, 3, command)
    if not new_value:
        return "Value required."
    if new_value == "None":
        new_value = None
    obj = load_object(':'.join([obj_type, obj_id]))
    if not obj:
        return "Object not found"
    patch_object(obj, prop, new_value)
    save_object(obj)
    return "Object " + key + " patched"