Build plugin list containing local and online plugin information Args: plugins_dir (Path): Plugin directory path Returns: list: List of dicts containing plugin information
(plugins_dir: Path)
| 133 | |
| 134 | |
| 135 | def build_plug_list(plugins_dir: Path) -> list: |
| 136 | """Build plugin list containing local and online plugin information |
| 137 | |
| 138 | Args: |
| 139 | plugins_dir (Path): Plugin directory path |
| 140 | |
| 141 | Returns: |
| 142 | list: List of dicts containing plugin information |
| 143 | |
| 144 | """ |
| 145 | # Get local plugin info |
| 146 | result = [] |
| 147 | if plugins_dir.is_dir(): |
| 148 | for plugin_dir in plugins_dir.iterdir(): |
| 149 | if not plugin_dir.is_dir(): |
| 150 | continue |
| 151 | |
| 152 | # Load metadata from metadata.yaml |
| 153 | metadata = load_yaml_metadata(plugin_dir) |
| 154 | |
| 155 | if "desc" not in metadata and "description" in metadata: |
| 156 | metadata["desc"] = metadata["description"] |
| 157 | |
| 158 | # If metadata loaded successfully, add to result list |
| 159 | if metadata and all( |
| 160 | k in metadata for k in ["name", "desc", "version", "author", "repo"] |
| 161 | ): |
| 162 | result.append( |
| 163 | { |
| 164 | "name": str(metadata.get("name", "")), |
| 165 | "desc": str(metadata.get("desc", "")), |
| 166 | "version": str(metadata.get("version", "")), |
| 167 | "author": str(metadata.get("author", "")), |
| 168 | "repo": str(metadata.get("repo", "")), |
| 169 | "status": PluginStatus.INSTALLED, |
| 170 | "local_path": str(plugin_dir), |
| 171 | }, |
| 172 | ) |
| 173 | |
| 174 | # Get online plugin list |
| 175 | online_plugins_dict = {} |
| 176 | try: |
| 177 | with httpx.Client() as client: |
| 178 | resp = client.get("https://api.soulter.top/astrbot/plugins") |
| 179 | resp.raise_for_status() |
| 180 | data = resp.json() |
| 181 | for plugin_id, plugin_info in data.items(): |
| 182 | online_plugins_dict[str(plugin_id)] = { |
| 183 | "name": str(plugin_id), |
| 184 | "desc": str(plugin_info.get("desc", "")), |
| 185 | "version": str(plugin_info.get("version", "")), |
| 186 | "author": str(plugin_info.get("author", "")), |
| 187 | "repo": str(plugin_info.get("repo", "")), |
| 188 | "status": PluginStatus.NOT_INSTALLED, |
| 189 | "local_path": None, |
| 190 | } |
| 191 | except Exception as e: |
| 192 | click.echo(f"Failed to get online plugin list: {e}", err=True) |