mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-16 01:30:03 +08:00
Compare commits
6
Commits
07633727b8
...
8a25dea757
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a25dea757 | ||
|
|
c571bfb133 | ||
|
|
da6d5b4be4 | ||
|
|
62fac483f2 | ||
|
|
4a7b1cec4d | ||
|
|
ab4116a253 |
@@ -0,0 +1,26 @@
|
||||
name: Force Sync to Aliyun
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
jobs:
|
||||
sync:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Configure Git
|
||||
run: |
|
||||
git config --global http.postBuffer 524288000
|
||||
git config --global core.compression 0
|
||||
|
||||
- name: Add aliyun remote
|
||||
run: |
|
||||
git remote add aliyun https://${{secrets.ALIYUN_ACCOUNT}}:${{secrets.ALIYUN_PASSWORD}}@codeup.aliyun.com/67a361cf556e6cdab537117a/zhenxun-org/zhenxun_bot.git
|
||||
git fetch aliyun main --force # 强制更新本地引用
|
||||
|
||||
- name: Force push
|
||||
run: git push --progress --force aliyun HEAD:main
|
||||
+1
-1
@@ -1 +1 @@
|
||||
__version__: v0.2.4-2c97eea
|
||||
__version__: v0.2.4-da6d5b4
|
||||
|
||||
@@ -54,15 +54,17 @@ class ApiDataSource:
|
||||
if platform == "qq":
|
||||
login_info = await bot.get_login_info()
|
||||
nickname = login_info["nickname"]
|
||||
ava_url = (
|
||||
PlatformUtils.get_user_avatar_url(
|
||||
ava_url: str = (
|
||||
await PlatformUtils.get_user_avatar_url(
|
||||
bot.self_id, "qq", BotConfig.get_qbot_uid(bot.self_id)
|
||||
)
|
||||
or ""
|
||||
)
|
||||
else:
|
||||
nickname = bot.self_id
|
||||
ava_url = ""
|
||||
ava_url: str = (
|
||||
await PlatformUtils.get_user_avatar_url(bot.self_id, platform) or ""
|
||||
)
|
||||
bot_info = BotInfo(
|
||||
self_id=bot.self_id, nickname=nickname, ava_url=ava_url, platform=platform
|
||||
)
|
||||
|
||||
@@ -76,11 +76,13 @@ class ApiDataSource:
|
||||
login_info = await bot.get_login_info()
|
||||
except Exception as e:
|
||||
logger.warning("调用接口get_login_info失败", "WebUi", e=e)
|
||||
platform = PlatformUtils.get_platform(bot) or ""
|
||||
return TemplateBaseInfo(
|
||||
bot=bot,
|
||||
self_id=bot.self_id,
|
||||
nickname=login_info["nickname"] if login_info else bot.self_id,
|
||||
ava_url=AVA_URL.format(bot.self_id),
|
||||
ava_url=await PlatformUtils.get_user_avatar_url(bot.self_id, platform)
|
||||
or AVA_URL.format(bot.self_id),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -19,6 +19,10 @@ class BotSetting(BaseModel):
|
||||
"""平台超级用户"""
|
||||
qbot_id_data: dict[str, str] = Field(default_factory=dict)
|
||||
"""官bot id:账号id"""
|
||||
kaiheila_bots: list[dict[str, str]] = Field(default_factory=list)
|
||||
"""kaiheilabot id:账号id"""
|
||||
discord_bots: list[dict] = Field(default_factory=list)
|
||||
"""discordbot id:账号id"""
|
||||
|
||||
def get_qbot_uid(self, qbot_id: str) -> str | None:
|
||||
"""获取官bot账号id
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
from typing_extensions import Self
|
||||
|
||||
from nonebot.adapters import Bot
|
||||
@@ -132,6 +133,7 @@ class FgRequest(Model):
|
||||
bot.self_id
|
||||
)
|
||||
if file_path:
|
||||
await asyncio.sleep(2)
|
||||
await PlatformUtils.send_message(
|
||||
bot,
|
||||
req.user_id,
|
||||
|
||||
@@ -76,6 +76,7 @@ class BotProfileManager:
|
||||
_f = PROFILE_IMAGE_PATH / f
|
||||
if _f.is_file():
|
||||
_f.unlink()
|
||||
cls._bot_data.clear()
|
||||
|
||||
@classmethod
|
||||
async def _read_profile(cls, bot_id: str):
|
||||
|
||||
@@ -235,7 +235,7 @@ class PlatformUtils:
|
||||
return await AsyncHttpx.get_content(url) if url else None
|
||||
|
||||
@classmethod
|
||||
def get_user_avatar_url(
|
||||
async def get_user_avatar_url(
|
||||
cls, user_id: str, platform: str, appid: str | None = None
|
||||
) -> str | None:
|
||||
"""快捷获取用户头像url
|
||||
@@ -244,12 +244,41 @@ class PlatformUtils:
|
||||
user_id: 用户id
|
||||
platform: 平台
|
||||
"""
|
||||
if platform != "qq":
|
||||
return None
|
||||
if user_id.isdigit():
|
||||
return f"http://q1.qlogo.cn/g?b=qq&nk={user_id}&s=160"
|
||||
if platform == "qq":
|
||||
if user_id.isdigit():
|
||||
return f"http://q1.qlogo.cn/g?b=qq&nk={user_id}&s=160"
|
||||
else:
|
||||
return f"https://q.qlogo.cn/qqapp/{appid}/{user_id}/640"
|
||||
elif platform == "kaiheila":
|
||||
if not hasattr(cls, "_kook_cache"):
|
||||
params = {"user_id": user_id}
|
||||
header = {
|
||||
"Authorization": f"Bot {BotConfig.kaiheila_bots[0].get('token')}"
|
||||
}
|
||||
result = await AsyncHttpx.get(
|
||||
url="https://www.kookapp.cn/api/v3/user/view",
|
||||
params=params,
|
||||
headers=header,
|
||||
)
|
||||
cls._kook_cache = result.json()["data"]["avatar"]
|
||||
return cls._kook_cache
|
||||
else:
|
||||
return cls._kook_cache # 使用临时缓存
|
||||
elif platform == "discord":
|
||||
if not hasattr(cls, "_discord_cache"):
|
||||
header = {
|
||||
"Authorization": f"Bot {BotConfig.discord_bots[0].get('token')}"
|
||||
}
|
||||
result = await AsyncHttpx.get(
|
||||
url=f"https://discord.com/api/users/{user_id}", headers=header
|
||||
)
|
||||
cls._discord_cache = f"https://cdn.discordapp.com/avatars/{user_id}/{result.json()['avatar']}.png?size=256"
|
||||
return cls._discord_cache
|
||||
else:
|
||||
return cls._discord_cache # 使用临时缓存
|
||||
|
||||
else:
|
||||
return f"https://q.qlogo.cn/qqapp/{appid}/{user_id}/640"
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
async def get_group_avatar(cls, gid: str, platform: str) -> bytes | None:
|
||||
|
||||
Reference in New Issue
Block a user