斗鱼加入了一个弹幕记录功能。会自动记录开播的弹幕信息
This commit is contained in:
@@ -474,7 +474,8 @@ class DouyuPlugin(MessagePluginInterface):
|
||||
if first_token == "订阅鱼吧":
|
||||
parts = content.split()
|
||||
if len(parts) < 2:
|
||||
await self.bot.send_text_message(roomid or sender, "请提供鱼吧 hash_id,例如:订阅鱼吧 PDAP2zEk3nwx", sender)
|
||||
await self.bot.send_text_message(roomid or sender, "请提供鱼吧 hash_id,例如:订阅鱼吧 PDAP2zEk3nwx",
|
||||
sender)
|
||||
return True, "命令格式错误"
|
||||
hash_id = parts[1].strip()
|
||||
ok = self.redis_manager.add_group_yuba(roomid or sender, hash_id)
|
||||
@@ -484,7 +485,8 @@ class DouyuPlugin(MessagePluginInterface):
|
||||
if first_token == "取消订阅鱼吧":
|
||||
parts = content.split()
|
||||
if len(parts) < 2:
|
||||
await self.bot.send_text_message(roomid or sender, "请提供鱼吧 hash_id,例如:取消订阅鱼吧 PDAP2zEk3nwx", sender)
|
||||
await self.bot.send_text_message(roomid or sender, "请提供鱼吧 hash_id,例如:取消订阅鱼吧 PDAP2zEk3nwx",
|
||||
sender)
|
||||
return True, "命令格式错误"
|
||||
hash_id = parts[1].strip()
|
||||
ok = self.redis_manager.remove_group_yuba(roomid or sender, hash_id)
|
||||
@@ -548,10 +550,6 @@ class DouyuPlugin(MessagePluginInterface):
|
||||
logger.error(f"斗鱼定时任务异常: {e}")
|
||||
|
||||
async def _notify_groups_live(self, room_id: str, nickname: str, room_name: str, thumb_url: str):
|
||||
try:
|
||||
self._start_danmu_record(room_id)
|
||||
except Exception as e:
|
||||
logger.error(f"启动斗鱼弹幕记录失败({room_id}): {e}")
|
||||
groups = self.redis_manager.groups_for_room(room_id)
|
||||
text = f"🚀 斗鱼开播通知 \n🎤 {nickname} 正在直播中!\n 📌 房间标题:{room_name} \n 👉 点击观看:https://www.douyu.com/{room_id}"
|
||||
xml_content = DOUYU_MESSAGE_XML.format(title=room_name, liver=nickname, roomid=room_id, thumburl=thumb_url)
|
||||
@@ -567,12 +565,13 @@ class DouyuPlugin(MessagePluginInterface):
|
||||
except Exception as e:
|
||||
logger.error(f"发送斗鱼开播提醒失败: {e}")
|
||||
continue
|
||||
try:
|
||||
logger.info(f"启动斗鱼弹幕记录({room_id})")
|
||||
self._start_danmu_record(room_id)
|
||||
except Exception as e:
|
||||
logger.error(f"启动斗鱼弹幕记录失败({room_id}): {e}")
|
||||
|
||||
async def _notify_groups_offline(self, room_id: str, nickname: str, room_name: str, is_loop: bool = False):
|
||||
try:
|
||||
self._stop_danmu_record(room_id)
|
||||
except Exception as e:
|
||||
logger.error(f"停止斗鱼弹幕记录失败({room_id}): {e}")
|
||||
groups = self.redis_manager.groups_for_room(room_id)
|
||||
text = f"🔔 斗鱼提醒:{nickname} 下播啦~\n 🏷️ {room_name}"
|
||||
if is_loop:
|
||||
@@ -584,6 +583,11 @@ class DouyuPlugin(MessagePluginInterface):
|
||||
except Exception as e:
|
||||
logger.error(f"发送斗鱼下播提醒失败: {e}")
|
||||
continue
|
||||
try:
|
||||
logger.info(f"停止斗鱼弹幕记录({room_id})")
|
||||
self._stop_danmu_record(room_id)
|
||||
except Exception as e:
|
||||
logger.error(f"停止斗鱼弹幕记录失败({room_id}): {e}")
|
||||
|
||||
async def _scheduled_yuba_check_job(self):
|
||||
try:
|
||||
@@ -603,7 +607,8 @@ class DouyuPlugin(MessagePluginInterface):
|
||||
"User-Agent": self._user_agent,
|
||||
"Referer": f"https://yuba.douyu.com/member/{hash_id}/main/news",
|
||||
}
|
||||
async with session.get(self._yuba_api, headers=headers, params=params, timeout=aiohttp.ClientTimeout(total=10)) as resp:
|
||||
async with session.get(self._yuba_api, headers=headers, params=params,
|
||||
timeout=aiohttp.ClientTimeout(total=10)) as resp:
|
||||
data = await resp.json(content_type=None)
|
||||
|
||||
if data.get("error") != 0:
|
||||
@@ -633,19 +638,20 @@ class DouyuPlugin(MessagePluginInterface):
|
||||
content = target_feed.get("text", "")
|
||||
ctime = target_feed.get("ctime")
|
||||
from datetime import datetime
|
||||
publish_time = datetime.fromtimestamp(int(ctime)).strftime('%Y-%m-%d %H:%M:%S') if ctime else "未知时间"
|
||||
publish_time = datetime.fromtimestamp(int(ctime)).strftime(
|
||||
'%Y-%m-%d %H:%M:%S') if ctime else "未知时间"
|
||||
|
||||
# 限制内容长度
|
||||
if len(content) > 200:
|
||||
content = content[:200] + "..."
|
||||
|
||||
|
||||
full_url = f"https://yuba.douyu.com/feed/{feed_id}"
|
||||
|
||||
|
||||
await self._notify_groups_yuba(hash_id, nickname, content, full_url, publish_time)
|
||||
|
||||
|
||||
# 保存标记
|
||||
self.redis_manager.set_yuba_last_id(hash_id, feed_id)
|
||||
|
||||
|
||||
await asyncio.sleep(0.5)
|
||||
except Exception as e:
|
||||
logger.error(f"检查斗鱼鱼吧 ({hash_id}) 失败: {e}")
|
||||
@@ -653,7 +659,8 @@ class DouyuPlugin(MessagePluginInterface):
|
||||
except Exception as e:
|
||||
logger.error(f"斗鱼鱼吧定时任务异常: {e}")
|
||||
|
||||
async def _notify_groups_yuba(self, hash_id: str, nickname: str, content: str, url: str, publish_time: str = "未知时间"):
|
||||
async def _notify_groups_yuba(self, hash_id: str, nickname: str, content: str, url: str,
|
||||
publish_time: str = "未知时间"):
|
||||
groups = self.redis_manager.groups_for_yuba(hash_id)
|
||||
text = f"🌟 斗鱼鱼吧动态提醒 \n👤 主播:{nickname}\n⏰ 时间:{publish_time}\n📝 内容:{content}\n🔗 链接:{url}"
|
||||
for gid in groups:
|
||||
|
||||
Reference in New Issue
Block a user