SanYeCao-Nonebot/src/clover_image/qq_image.py
SlyAimer e50a197c18 refactor(clover_image): 拆分图像处理功能到独立模块
- 将 `get_image.py` 中的功能拆分为多个独立模块:`qq_image.py`, `rua.py`, `add_text_to_image.py`, `delete_file.py`, `download_image.py`
- 更新相关插件的导入路径以适配新模块结构
- 新增 `nai_loong.py` 和 `platform.py` 插件
2025-02-13 15:54:30 +08:00

44 lines
No EOL
1.7 KiB
Python

import os
import requests
from src.configs.path_config import image_local_qq_image_path
from src.configs.api_config import app_id,bot_account
"""获取QQ头像"""
def download_qq_image(member_open_id):
if not os.path.exists(image_local_qq_image_path):
os.makedirs(image_local_qq_image_path)
save_path = image_local_qq_image_path + '/' + member_open_id + '.jpg'
size = 640 #尺寸 40、100、140、640
url = f"https://q.qlogo.cn/qqapp/{app_id}/{member_open_id}/{size}"
response = requests.get(url) # 发送 GET 请求获取图片资源
if response.status_code == 200: # 判断请求是否成功
with open(save_path, 'wb') as file: # 以二进制写入模式打开文件
file.write(response.content) # 将响应内容写入文件
return save_path
"""获取QQ头像"""
def download_qq_image_by_account(account):
if not os.path.exists(image_local_qq_image_path):
os.makedirs(image_local_qq_image_path)
if account is None:
account = bot_account
save_path = image_local_qq_image_path + '/' + account + '.jpg'
size = 640 # 尺寸 40、100、140、640
url = f"https://q2.qlogo.cn/headimg_dl?dst_uin={account}&spec={size}"
response = requests.get(url) # 发送 GET 请求获取图片资源
if response.status_code == 200: # 判断请求是否成功
with open(save_path, 'wb') as file: # 以二进制写入模式打开文件
file.write(response.content) # 将响应内容写入文件
return save_path
"""删除QQ头像"""
def qq_image_delete():
for root, dirs, files in os.walk(image_local_qq_image_path):
for file in files:
file_path = os.path.join(root, file)
os.remove(file_path)