feature:1.点歌功能,2.签到功能

This commit is contained in:
liuwei
2025-03-05 09:23:39 +08:00
parent 8e65a9732b
commit e648449970
2 changed files with 51 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ import logging
import tomllib
import aiohttp
import requests
from wcferry import WxMsg, Wcf
from robot_cmd.robot_command import Feature, PermissionStatus, GroupBotManager
@@ -22,7 +23,9 @@ class BotMusic:
self.command_format = config["command-format"]
self.LOG.info(f"[点歌台] 组件初始化完成,指令: {self.command}")
async def get_music(self, message: WxMsg):
import requests
def get_music(self, message: WxMsg):
if not self.enable:
return
@@ -43,15 +46,22 @@ class BotMusic:
song_name = content[len(command[0]):].strip()
async with aiohttp.ClientSession() as session:
async with session.get(
f"https://www.hhlqilongzhu.cn/api/dg_wyymusic.php?gm={song_name}&n=1&br=2&type=json") as resp:
data = await resp.json()
try:
response = requests.get(
f"https://www.hhlqilongzhu.cn/api/dg_wyymusic.php?gm={song_name}&n=1&br=2&type=json",
timeout=5 # 设置超时,防止阻塞
)
data = response.json()
except requests.RequestException as e:
self.wcf.send_text(f"-----Bot-----\n❌请求出错:{e}",
(message.roomid if message.from_group() else message.sender), message.sender)
return
if data["code"] != 200:
if data.get("code") != 200:
self.wcf.send_text(f"-----Bot-----\n❌点歌失败!\n{data}",
(message.roomid if message.from_group() else message.sender), message.sender)
return
title = data["title"]
singer = data["singer"]
url = data["link"]
@@ -59,5 +69,35 @@ class BotMusic:
cover_url = data["cover"]
lyric = data["lrc"]
xml = f"""<appmsg appid="wx79f2c4418704b4f8" sdkver="0"><title>{title}</title><des>{singer}</des><action>view</action><type>3</type><showtype>0</showtype><content/><url>{url}</url><dataurl>{music_url}</dataurl><lowurl>{url}</lowurl><lowdataurl>{music_url}</lowdataurl><recorditem/><thumburl>{cover_url}</thumburl><messageaction/><laninfo/><extinfo/><sourceusername/><sourcedisplayname/><songlyric>{lyric}</songlyric><commenturl/><appattach><totallen>0</totallen><attachid/><emoticonmd5/><fileext/><aeskey/></appattach><webviewshared><publisherId/><publisherReqId>0</publisherReqId></webviewshared><weappinfo><pagepath/><username/><appid/><appservicetype>0</appservicetype></weappinfo><websearch/><songalbumurl>{cover_url}</songalbumurl></appmsg><fromusername>{bot.wxid}</fromusername><scene>0</scene><appinfo><version>1</version><appname/></appinfo><commenturl/>"""
xml = f"""<appmsg appid="wx79f2c4418704b4f8" sdkver="0">
<title>{title}</title>
<des>{singer}</des>
<action>view</action>
<type>3</type>
<showtype>0</showtype>
<content/>
<url>{url}</url>
<dataurl>{music_url}</dataurl>
<lowurl>{url}</lowurl>
<lowdataurl>{music_url}</lowdataurl>
<recorditem/>
<thumburl>{cover_url}</thumburl>
<messageaction/>
<laninfo/>
<extinfo/>
<sourceusername/>
<sourcedisplayname/>
<songlyric>{lyric}</songlyric>
<commenturl/>
<appattach><totallen>0</totallen><attachid/><emoticonmd5/><fileext/><aeskey/></appattach>
<webviewshared><publisherId/><publisherReqId>0</publisherReqId></webviewshared>
<weappinfo><pagepath/><username/><appid/><appservicetype>0</appservicetype></weappinfo>
<websearch/>
<songalbumurl>{cover_url}</songalbumurl>
</appmsg>
<fromusername>{message.sender}</fromusername>
<scene>0</scene>
<appinfo><version>1</version><appname/></appinfo>
<commenturl/>"""
self.wcf.send_xml(message.sender, xml, 3)

View File

@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
import asyncio
import json
import logging
import re
import time
@@ -326,7 +324,7 @@ class Robot(Job):
except Exception as e:
self.LOG.error(f"group_member_change error: {e}")
try:
asyncio.create_task(self.music.get_music(message=msg)) # ✅ 推荐在事件循环中使用
self.music.get_music(message=msg) # ✅ 推荐在事件循环中使用
except Exception as e:
self.LOG.error(f"get_music error: {e}")
@@ -621,6 +619,8 @@ class Robot(Job):
except Exception as e:
self.LOG.error(f"xiu_ren_pdf_send error{e}")
if __name__ == '__main__':
heisi_path = generate_pdf_from_images("xiuren/heisi")
print(heisi_path)
print(heisi_path)