mirror of
https://github.com/KimigaiiWuyi/GenshinUID.git
synced 2025-05-12 06:55:58 +08:00
🎨 修改图片发送方式
This commit is contained in:
parent
24062bf528
commit
4de48a26dd
@ -1,17 +1,14 @@
|
||||
import asyncio
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from git.repo import Repo
|
||||
from pip._internal import main as pip_install
|
||||
|
||||
CORE_PATH = Path().cwd().parent / 'gsuid_core'
|
||||
GSUID_PATH = CORE_PATH / 'gsuid_core' / 'plugins' / 'GenshinUID'
|
||||
from .path import RUN_CORE, CORE_PATH, GSUID_PATH
|
||||
|
||||
GS_GIT = 'https://ghproxy.com/https://github.com/KimigaiiWuyi/GenshinUID.git'
|
||||
CORE_GIT = 'https://ghproxy.com/https://github.com/Genshin-bots/gsuid-core.git'
|
||||
|
||||
RUN_CORE = CORE_PATH / 'gsuid_core'
|
||||
|
||||
|
||||
async def _install():
|
||||
if not CORE_PATH.exists():
|
||||
|
@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
from typing import Union
|
||||
from base64 import b64encode
|
||||
from typing import Union, Optional
|
||||
|
||||
import websockets.client
|
||||
from nonebot import get_bot
|
||||
@ -33,14 +34,14 @@ class GsClient:
|
||||
logger.info(f'【接收】[gsuid-core]: {msg}')
|
||||
# 解析消息
|
||||
content = ''
|
||||
image = ''
|
||||
image: Optional[bytes] = None
|
||||
if msg.content:
|
||||
for _c in msg.content:
|
||||
if _c.data:
|
||||
if _c.type == 'text':
|
||||
content += _c.data
|
||||
elif _c.type == 'image':
|
||||
image += _c.data
|
||||
image = _c.data
|
||||
elif _c.type and _c.type.startswith('log'):
|
||||
_type = _c.type.split('_')[-1].lower()
|
||||
getattr(logger, _type)(_c.data)
|
||||
@ -49,7 +50,11 @@ class GsClient:
|
||||
|
||||
# 根据bot_id字段发送消息
|
||||
if msg.bot_id == 'onebot':
|
||||
result_image = f'[CQ:image,file={image}]' if image else ''
|
||||
result_image = (
|
||||
f'[CQ:image,file=base64://{b64encode(image).decode()}]'
|
||||
if image
|
||||
else ''
|
||||
)
|
||||
result_msg = content + result_image
|
||||
if msg.target_type == 'group':
|
||||
await bot.call_api(
|
||||
@ -77,13 +82,18 @@ class GsClient:
|
||||
content=content,
|
||||
)
|
||||
elif msg.bot_id == 'qqguild':
|
||||
result = {}
|
||||
if image:
|
||||
result['file_image'] = image
|
||||
if content:
|
||||
result['content'] = content
|
||||
if msg.target_type == 'group':
|
||||
await bot.call_api(
|
||||
'post_messages',
|
||||
channel_id=int(msg.target_id)
|
||||
if msg.target_id
|
||||
else 0,
|
||||
content=content,
|
||||
**result,
|
||||
)
|
||||
except ConnectionClosedError:
|
||||
logger.warning(f'与[gsuid-core]断开连接! Bot_ID: {BOT_ID}')
|
||||
|
16
GenshinUID/path.py
Normal file
16
GenshinUID/path.py
Normal file
@ -0,0 +1,16 @@
|
||||
from pathlib import Path
|
||||
|
||||
from nonebot import get_driver
|
||||
|
||||
driver = get_driver()
|
||||
|
||||
_CORE_PATH = Path().cwd().parent / 'gsuid_core'
|
||||
|
||||
CORE_PATH = (
|
||||
Path(driver.config.gsuid_core_path)
|
||||
if hasattr(driver.config, 'gsuid_core_path')
|
||||
else _CORE_PATH
|
||||
)
|
||||
|
||||
GSUID_PATH = CORE_PATH / 'gsuid_core' / 'plugins' / 'GenshinUID'
|
||||
RUN_CORE = CORE_PATH / 'gsuid_core'
|
Loading…
x
Reference in New Issue
Block a user