def load_json() -> 'Hallo': """ Loads up the json configuration and creates a new Hallo object :return: new Hallo object :rtype: Hallo """ try: with open("config/config.json", "r") as f: json_obj = json.load(f) except (OSError, IOError): error = MessageError("No current config, loading from default.") logger.error(error.get_log_line()) with open("config/config-default.json", "r") as f: json_obj = json.load(f) # Create new hallo object new_hallo = Hallo() new_hallo.default_nick = json_obj["default_nick"] new_hallo.default_prefix = json_obj["default_prefix"] new_hallo.default_full_name = json_obj["default_full_name"] new_hallo.function_dispatcher = FunctionDispatcher.from_json( json_obj["function_dispatcher"], new_hallo ) # User groups must be done before servers, as users will try and look up and add user groups! for user_group in json_obj["user_groups"]: new_hallo.add_user_group(UserGroup.from_json(user_group, new_hallo)) for server in json_obj["servers"]: new_server = new_hallo.server_factory.new_server_from_json(server) new_hallo.add_server(new_server) if "permission_mask" in json_obj: new_hallo.permission_mask = PermissionMask.from_json( json_obj["permission_mask"] ) for api_key in json_obj["api_keys"]: new_hallo.add_api_key(api_key, json_obj["api_keys"][api_key]) return new_hallo
def from_json(json_obj, server): name = json_obj["name"] address = json_obj["address"] new_channel = Channel(server, address, name) new_channel.logging = json_obj["logging"] new_channel.use_caps_lock = json_obj["caps_lock"] new_channel.passive_enabled = json_obj["passive_enabled"] new_channel.auto_join = json_obj["auto_join"] if "password" in json_obj: new_channel.password = json_obj["password"] if "permission_mask" in json_obj: new_channel.permission_mask = PermissionMask.from_json( json_obj["permission_mask"]) return new_channel
def from_json(json_obj, hallo): """ Creates a UserGroup object from json object dictionary :param json_obj: json object dictionary :type json_obj: dict :param hallo: root hallo object :type hallo: hallo.Hallo :return: new user group :rtype: UserGroup """ new_group = UserGroup(json_obj["name"], hallo) if "permission_mask" in json_obj: new_group.permission_mask = PermissionMask.from_json( json_obj["permission_mask"] ) return new_group
def from_json(json_obj, server): name = json_obj["name"] address = json_obj["address"] new_user = User(server, address, name) new_user.logging = json_obj["logging"] new_user.use_caps_lock = json_obj["caps_lock"] for user_group_name in json_obj["user_groups"]: user_group = server.hallo.get_user_group_by_name(user_group_name) if user_group is not None: new_user.add_user_group(user_group) if "permission_mask" in json_obj: new_user.permission_mask = PermissionMask.from_json( json_obj["permission_mask"]) if "extra_data" in json_obj: new_user.extra_data_dict = json_obj["extra_data"] return new_user
def from_json(json_obj, hallo): api_key = json_obj["api_key"] new_server = ServerTelegram(hallo, api_key) new_server.name = json_obj["name"] new_server.auto_connect = json_obj["auto_connect"] if "nick" in json_obj: new_server.nick = json_obj["nick"] if "prefix" in json_obj: new_server.prefix = json_obj["prefix"] if "permission_mask" in json_obj: new_server.permission_mask = PermissionMask.from_json( json_obj["permission_mask"]) for channel in json_obj["channels"]: new_server.add_channel(Channel.from_json(channel, new_server)) for user in json_obj["users"]: new_server.add_user(User.from_json(user, new_server)) return new_server