Skip to content

Commit dac55d4

Browse files
committed
feat: add daily ranking support for jmrank command
1 parent 5330d68 commit dac55d4

3 files changed

Lines changed: 58 additions & 6 deletions

File tree

core/browser.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,51 @@ def _get_month_ranking_sync(self, page: int, option) -> list[dict]:
332332
logger.error(f"获取月排行榜失败: {e}")
333333
return []
334334

335+
async def get_day_ranking(self, page: int = 1) -> list[dict]:
336+
"""
337+
获取日排行榜
338+
339+
Args:
340+
page: 页码
341+
342+
Returns:
343+
排行榜结果列表
344+
"""
345+
if not self.is_available():
346+
return []
347+
348+
try:
349+
option = self._get_option()
350+
if option is None:
351+
return []
352+
353+
return await self._run_sync(self._get_day_ranking_sync, page, option)
354+
except Exception as e:
355+
logger.error(f"获取日排行榜失败: {e}")
356+
return []
357+
358+
def _get_day_ranking_sync(self, page: int, option) -> list[dict]:
359+
"""同步获取日排行榜"""
360+
try:
361+
client = option.build_jm_client()
362+
ranking_page = client.day_ranking(page)
363+
364+
results = []
365+
for album_id, title in ranking_page.iter_id_title():
366+
results.append(
367+
{
368+
"id": album_id,
369+
"title": title,
370+
"author": "",
371+
"tags": [],
372+
"category": "",
373+
}
374+
)
375+
return results
376+
except Exception as e:
377+
logger.error(f"获取日排行榜失败: {e}")
378+
return []
379+
335380
# ==================== 分类浏览功能 ====================
336381

337382
# 常量映射已移至 constants.py

main.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ async def ranking_command(
417417
"""
418418
查看排行榜
419419
420-
用法: /jmrank [week/month] [页码]
420+
用法: /jmrank [day/week/month] [页码]
421421
示例: /jmrank week 1
422422
"""
423423
# 权限检查
@@ -428,9 +428,9 @@ async def ranking_command(
428428

429429
# 验证排行榜类型
430430
ranking_type = str(ranking_type).lower().strip()
431-
if ranking_type not in ("week", "month"):
431+
if ranking_type not in ("day", "week", "month"):
432432
yield event.plain_result(
433-
"❌ 无效的排行榜类型\n用法: /jmrank [week/month] [页码]\n示例: /jmrank week 1"
433+
"❌ 无效的排行榜类型\n用法: /jmrank [day/week/month] [页码]\n示例: /jmrank week 1"
434434
)
435435
return
436436

@@ -443,10 +443,13 @@ async def ranking_command(
443443
page = 1
444444

445445
try:
446-
type_name = "周" if ranking_type == "week" else "月"
446+
type_names = {"day": "日", "week": "周", "month": "月"}
447+
type_name = type_names.get(ranking_type, "周")
447448
yield event.plain_result(f"🏆 正在获取{type_name}排行榜第{page}页...")
448449

449-
if ranking_type == "week":
450+
if ranking_type == "day":
451+
results = await self.browser.get_day_ranking(page)
452+
elif ranking_type == "week":
450453
results = await self.browser.get_week_ranking(page)
451454
else:
452455
results = await self.browser.get_month_ranking(page)

utils/formatter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ def format_ranking_results(
116116
if not results:
117117
return "🏆 暂无排行榜数据"
118118

119-
type_name = "周" if ranking_type == "week" else "月"
119+
type_names = {"day": "日", "week": "周", "month": "月"}
120+
type_name = type_names.get(ranking_type, "周")
120121
lines = [
121122
f"🏆 {type_name}排行榜 (第{page}页)",
122123
"━━━━━━━━━━━━━━━━━━━━━",
@@ -137,6 +138,9 @@ def format_ranking_results(
137138
lines.append("━━━━━━━━━━━━━━━━━━━━━")
138139
lines.append("💡 使用 /jmi <ID> 查看详情")
139140
lines.append("💡 使用 /jm <ID> 直接下载")
141+
lines.append(f"💡 使用 /jmrank {ranking_type} {page + 1} 查看下一页")
142+
lines.append("")
143+
lines.append("📊 类型: day(日榜) · week(周榜) · month(月榜)")
140144

141145
return "\n".join(lines)
142146

0 commit comments

Comments
 (0)