Skip to content

Commit a5c5e03

Browse files
committed
feat(favorites): add favorites browsing functionality
- Add /jmfav command to view user favorites - Add get_favorites() method to browser.py - Add format_favorites() for display formatting - Require login to access favorites feature
1 parent b503806 commit a5c5e03

6 files changed

Lines changed: 160 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
所有版本更新记录。
44

5+
## **v2.3.0** (2025-12-27)
6+
7+
### 新增功能
8+
- **收藏夹功能** - 新增 `/jmfav` 命令,查看我的收藏
9+
- `/jmfav [页码]` - 查看收藏夹(需登录)
10+
- `/jmfav [页码] [收藏夹ID]` - 查看指定收藏夹
11+
- 显示收藏夹列表,支持多收藏夹切换
12+
13+
---
14+
515
## **v2.2.0** (2025-12-27)
616

717
### 新增功能

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<br>
1212
<div align="center">
13-
<a href="#更新日志"><img src="https://img.shields.io/badge/VERSION-v2.2.0-E91E63?style=for-the-badge" alt="Version"></a>
13+
<a href="#更新日志"><img src="https://img.shields.io/badge/VERSION-v2.3.0-E91E63?style=for-the-badge" alt="Version"></a>
1414
<a href="https://github.com/GEMILUXVII/astrbot_plugin_jm_cosmos/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-AGPL--3.0-009688?style=for-the-badge" alt="License"></a>
1515
<a href="https://www.python.org/"><img src="https://img.shields.io/badge/PYTHON-3.10+-3776AB?style=for-the-badge&logo=python&logoColor=white" alt="Python"></a>
1616
<a href="https://github.com/AstrBotDevs/AstrBot"><img src="https://img.shields.io/badge/AstrBot-Compatible-00BFA5?style=for-the-badge&logo=robot&logoColor=white" alt="AstrBot Compatible"></a>
@@ -98,6 +98,7 @@ pip install -r requirements.txt
9898
| `/jmlogin` | 登录JM账号 | `/jmlogin u p` |
9999
| `/jmlogout` | 登出账号 | `/jmlogout` |
100100
| `/jmstatus` | 查看登录状态 | `/jmstatus` |
101+
| `/jmfav` | 查看我的收藏 | `/jmfav 1` |
101102
| `/jmhelp` | 查看帮助信息 | `/jmhelp` |
102103

103104
## 配置说明
@@ -170,7 +171,7 @@ proxy_url: http://127.0.0.1:7890
170171

171172
查看完整更新日志:[CHANGELOG.md](./CHANGELOG.md)
172173

173-
**当前版本:v2.2.0** - 新增登录功能
174+
**当前版本:v2.3.0** - 新增收藏夹功能
174175

175176
## 注意事项
176177

core/browser.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,62 @@ def _get_month_ranking_sync(self, page: int, option) -> list[dict]:
219219
except Exception as e:
220220
logger.error(f"获取月排行榜失败: {e}")
221221
return []
222+
223+
# ==================== 收藏夹功能 ====================
224+
225+
async def get_favorites(
226+
self, client, page: int = 1, folder_id: str = "0"
227+
) -> tuple[list[dict], list[dict]]:
228+
"""
229+
获取收藏夹内容
230+
231+
Args:
232+
client: 已登录的客户端
233+
page: 页码
234+
folder_id: 收藏夹ID,默认为 "0"(全部收藏)
235+
236+
Returns:
237+
(收藏列表, 收藏夹列表)
238+
"""
239+
if not self.is_available():
240+
return [], []
241+
242+
try:
243+
return await self._run_sync(
244+
self._get_favorites_sync, client, page, folder_id
245+
)
246+
except Exception as e:
247+
logger.error(f"获取收藏夹失败: {e}")
248+
return [], []
249+
250+
def _get_favorites_sync(
251+
self, client, page: int, folder_id: str
252+
) -> tuple[list[dict], list[dict]]:
253+
"""同步获取收藏夹内容"""
254+
try:
255+
fav_page = client.favorite_folder(page=page, folder_id=folder_id)
256+
257+
# 获取收藏的本子
258+
albums = []
259+
for album_id, title in fav_page.iter_id_title():
260+
albums.append(
261+
{
262+
"id": album_id,
263+
"title": title,
264+
}
265+
)
266+
267+
# 获取收藏夹列表
268+
folders = []
269+
for folder_id, folder_name in fav_page.iter_folder_id_name():
270+
folders.append(
271+
{
272+
"id": folder_id,
273+
"name": folder_name,
274+
}
275+
)
276+
277+
return albums, folders
278+
except Exception as e:
279+
logger.error(f"获取收藏夹失败: {e}")
280+
return [], []

main.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,46 @@ async def status_command(self, event: AstrMessageEvent):
477477
yield event.plain_result(
478478
"❌ 当前未登录\n💡 使用 /jmlogin <用户名> <密码> 登录"
479479
)
480+
481+
@filter.command("jmfav")
482+
async def favorites_command(
483+
self, event: AstrMessageEvent, page: int = 1, folder_id: str = "0"
484+
):
485+
"""
486+
查看我的收藏
487+
488+
用法: /jmfav [页码] [收藏夹ID]
489+
示例: /jmfav 1
490+
"""
491+
# 权限检查
492+
has_perm, error_msg = self._check_permission(event)
493+
if not has_perm:
494+
yield event.plain_result(error_msg)
495+
return
496+
497+
# 检查登录状态
498+
logged_in, login_msg = await self.auth_manager.ensure_logged_in()
499+
if not logged_in:
500+
yield event.plain_result(f"❌ {login_msg}\n💡 请先使用 /jmlogin 登录")
501+
return
502+
503+
# 验证页码
504+
try:
505+
page = int(page)
506+
if page < 1:
507+
page = 1
508+
except (ValueError, TypeError):
509+
page = 1
510+
511+
try:
512+
yield event.plain_result(f"⭐ 正在获取收藏夹第{page}页...")
513+
514+
client = self.auth_manager.get_client()
515+
albums, folders = await self.browser.get_favorites(client, page, folder_id)
516+
517+
result_msg = MessageFormatter.format_favorites(albums, folders, page)
518+
yield event.plain_result(result_msg)
519+
520+
except Exception as e:
521+
logger.error(f"获取收藏夹失败: {e}")
522+
yield event.plain_result(MessageFormatter.format_error("network", str(e)))

metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: jm_cosmos2
22
desc: JM漫画下载插件 - 支持搜索、下载禁漫天堂的漫画本子,基于jmcomic库,支持加密PDF/ZIP打包
3-
version: v2.2.0
3+
version: v2.3.0
44
author: GEMILUXVII
55
repo: https://github.com/GEMILUXVII/astrbot_plugin_jm_cosmos

utils/formatter.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,48 @@ def format_ranking_results(
138138

139139
return "\n".join(lines)
140140

141+
@staticmethod
142+
def format_favorites(albums: list[dict], folders: list[dict], page: int = 1) -> str:
143+
"""
144+
格式化收藏夹结果
145+
146+
Args:
147+
albums: 收藏的本子列表
148+
folders: 收藏夹列表
149+
page: 当前页码
150+
151+
Returns:
152+
格式化后的字符串
153+
"""
154+
lines = []
155+
lines.append("⭐ 我的收藏")
156+
lines.append(f"📄 第 {page} 页")
157+
lines.append("━━━━━━━━━━━━━━━━━━━━━")
158+
159+
if not albums:
160+
lines.append("📭 收藏夹为空")
161+
else:
162+
for i, album in enumerate(albums, 1):
163+
album_id = album.get("id", "")
164+
title = album.get("title", "未知")
165+
lines.append(f"{i}. 【{album_id}{title}")
166+
167+
# 显示收藏夹列表(如果有多个)
168+
if folders and len(folders) > 1:
169+
lines.append("")
170+
lines.append("📁 收藏夹列表:")
171+
for folder in folders:
172+
folder_id = folder.get("id", "")
173+
folder_name = folder.get("name", "未知")
174+
lines.append(f" • [{folder_id}] {folder_name}")
175+
176+
lines.append("")
177+
lines.append("━━━━━━━━━━━━━━━━━━━━━")
178+
lines.append("💡 使用 /jmfav <页码> 翻页")
179+
lines.append("💡 使用 /jmfav <页码> <收藏夹ID> 查看特定收藏夹")
180+
181+
return "\n".join(lines)
182+
141183
@staticmethod
142184
def format_download_result(result, pack_result=None) -> str:
143185
"""
@@ -222,12 +264,13 @@ def format_help() -> str:
222264
/jmlogin <用户名> <密码> - 登录JM账号
223265
/jmlogout - 登出账号
224266
/jmstatus - 查看登录状态
267+
/jmfav - 查看我的收藏(需登录)
225268
226269
【使用示例】
227270
/jm 123456 - 下载ID为123456的本子
228271
/jms 标签名 - 搜索包含该标签的漫画
229272
/jmrank week - 查看周排行榜
230-
/jmlogin user pw - 登录账号
273+
/jmfav 1 - 查看收藏夹第1页
231274
232275
【说明】
233276
• 下载的文件将自动打包发送

0 commit comments

Comments
 (0)