def make_zone(user, name, bounds_info): zone = new_zone(name, bounds_info, user.username, confirmed=False) if zone is None: tell(user, "An error occurred while creating the zone. Try again or call an op.") else: tell(user, "Zone %s created. Exiting menu." % name) if user in ops(): zone['confirmed'] = True tell(user, "Zone auto-confirmed for ops.") else: tell(user, "You will need to get your zone approved by an op\n" "for plot protection to work.")
def zonenew(message, user, name, args): name = name.strip('"') if name in get_zones(): tell(user, "Name already taken.") return if args.startswith("json "): try: data = loads(args[5:]) except Exception: tell(user, "Bad json.") return def validate_point(data): if type(data) != list: raise ValueError() if len(data) != 3: raise ValueError() if not all(type(x) in (int, float) for x in data): raise ValueError() def validate_info(data): if type(data) != list: raise ValueError() style = data[0] if style == 'cube': dim, point1, point2 = data[1:] if type(dim) != int or dim not in (-1,0,1): raise ValueError() validate_point(point1) validate_point(point2) elif style == 'cylinder': dim, base, radius, height = data[1:] if type(dim) != int or dim not in (-1,0,1): raise ValueError() if not validate_point(base): raise ValueError() if type(radius) not in (int, float) or radius <= 0: raise ValueError() if type(height) not in (int, float) or height <= 0: raise ValueError() elif style == 'union': [validate_info(x) for x in data[1:]] else: raise ValueError() try: validate_info(data) except ValueError: tell(user, "Invalid JSON, see /help json for schema.") return zone = new_zone(name, data, user.username) else: args = filter(None, args.split()) style = args.pop(0) try: dim = int(args.pop(0)) if dim not in (-1,0,1): raise ValueError() args = [float(arg) for arg in args] if style == 'cube': if len(args) != 6: raise ValueError() point1 = args[:3] point2 = args[3:] zone = new_zone(name, ('cube',dim,point1,point2), user.username) elif style == 'cylinder': if len(args) != 5: raise ValueError() base = args[:3] radius, height = args[3:] if radius <= 0 or height <= 0: raise ValueError() zone = new_zone(name, ('cylinder',dim,base,radius,height), user.username) else: raise ValueError except ValueError: tell(user, "Bad args.") return if zone is None: tell(user, "Unknown error while creating zone") else: tell(user, "Success. Remember that you still need an op to confirm the zone.")