mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-Nonebot.git
synced 2026-04-01 22:04:51 +00:00
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` 插件
This commit is contained in:
parent
0f63228733
commit
e50a197c18
15 changed files with 302 additions and 264 deletions
72
src/clover_image/add_text_to_image.py
Normal file
72
src/clover_image/add_text_to_image.py
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
from PIL import Image, ImageDraw,ImageFont
|
||||
|
||||
|
||||
"""
|
||||
图文合成
|
||||
"""
|
||||
async def add_text_to_image(image_path, output_path,content,font_path, font_size, text_color,text_position ,position):
|
||||
"""
|
||||
给图片添加文字
|
||||
:param image_path: 输入图片的路径
|
||||
:param output_path: 合成后的图片名称
|
||||
:param content: 要添加的文字内容
|
||||
:param font_path: 字体文件路径
|
||||
:param font_size: 文字的字体大小
|
||||
:param text_color: 文字颜色 (255, 0, 0) "#FF0000" "red"
|
||||
:param text_position: 文字对齐方式,可选值:"left", "center", "right"
|
||||
:param position: 文字位置,可选值:"left", "right", "center", "top", "bottom", "top left corner", "top right corner", "bottom left corner", "bottom right corner"
|
||||
:return:
|
||||
"""
|
||||
# 打开图片
|
||||
image = Image.open(image_path)
|
||||
# 创建一个可用于绘制的对象
|
||||
draw = ImageDraw.Draw(image)
|
||||
# 设置字体和字体大小
|
||||
font = ImageFont.truetype(font_path, font_size)
|
||||
|
||||
wrapped_text,current_width = "",0
|
||||
|
||||
# 遍历文本中的每个字符
|
||||
for char in content:
|
||||
# 获取字符的宽度
|
||||
char_width, _ = draw.textbbox((0, 0), char, font=font)[2:]
|
||||
# 如果当前行的宽度加上字符宽度超过图片指定宽度,则换行
|
||||
if current_width + char_width > image.width * 9 // 10: # 这里是图片的十分之九
|
||||
wrapped_text += "\n"
|
||||
current_width = 0
|
||||
# 将字符添加到当前行
|
||||
wrapped_text += char
|
||||
# 更新当前行的宽度
|
||||
current_width += char_width
|
||||
|
||||
# 获取换行后文本的宽度和高度
|
||||
text_width, text_height = draw.textbbox((0, 0), wrapped_text, font=font)[2:]
|
||||
|
||||
# 根据位置参数计算文本的位置
|
||||
if position == "left":
|
||||
position = (0, (image.height - text_height) // 2)
|
||||
elif position == "right":
|
||||
position = (image.width - text_width, (image.height - text_height) // 2)
|
||||
elif position == "center":
|
||||
position = ((image.width - text_width) // 2, (image.height - text_height) // 2)
|
||||
elif position == "top":
|
||||
position = ((image.width - text_width) // 2, 0)
|
||||
elif position == "bottom":
|
||||
position = ((image.width - text_width) // 2, image.height - text_height)
|
||||
elif position == "top left corner":
|
||||
position = (0, 0)
|
||||
elif position == "top right corner":
|
||||
position = (image.width - text_width, 0)
|
||||
elif position == "bottom left corner":
|
||||
position = (0, image.height - text_height)
|
||||
elif position == "bottom right corner":
|
||||
position = (image.width - text_width, image.height - text_height)
|
||||
elif position == "bottom left corner 9/10":
|
||||
position = (0, image.height * 9 // 10 - text_height)
|
||||
|
||||
# 在图片上绘制文本
|
||||
draw.multiline_text(position, wrapped_text, font=font, fill=text_color, align=text_position)
|
||||
# 保存合成后的图片
|
||||
image.save(output_path)
|
||||
# 关闭图片
|
||||
# image.close()
|
||||
10
src/clover_image/delete_file.py
Normal file
10
src/clover_image/delete_file.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import os
|
||||
|
||||
|
||||
async def delete_file(file_path):
|
||||
try:
|
||||
os.remove(file_path)
|
||||
except FileNotFoundError:
|
||||
print(f"文件 {file_path} 不存在。")
|
||||
except Exception as e:
|
||||
print(f"删除文件时发生错误: {e}")
|
||||
17
src/clover_image/download_image.py
Normal file
17
src/clover_image/download_image.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import requests
|
||||
|
||||
def download_image(url,file_path):
|
||||
"""
|
||||
下载图片
|
||||
:param url:
|
||||
:param file_path:
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
response = requests.get(url, stream=True)
|
||||
response.raise_for_status()
|
||||
with open(file_path, 'wb') as file:
|
||||
for chunk in response.iter_content(chunk_size=8192):
|
||||
file.write(chunk)
|
||||
except requests.RequestException as e:
|
||||
print(f"下载图片时出错: {e}")
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
import os
|
||||
import random
|
||||
import requests
|
||||
from PIL import Image, ImageDraw,ImageFont
|
||||
|
||||
from src.configs.path_config import image_local_path,image_local_qq_image_path,rua_png,temp_path
|
||||
from src.configs.api_config import smms_token,smms_image_upload_history,ju_he_token,ju_he_image_list,app_id,bot_account
|
||||
from src.configs.path_config import image_local_path
|
||||
from src.configs.api_config import smms_token,smms_image_upload_history,ju_he_token,ju_he_image_list
|
||||
|
||||
"""本地图片"""
|
||||
def get_image_names():
|
||||
|
|
@ -18,42 +17,6 @@ def get_image_names():
|
|||
local_image_path = image_local_path + '/' + random.choice(image_names) # 随机选取一张图片的路径
|
||||
return local_image_path
|
||||
|
||||
"""获取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)
|
||||
|
||||
""" sm.ms 图床"""
|
||||
def get_smms_image_url():
|
||||
# 定义请求的参数
|
||||
|
|
@ -68,152 +31,3 @@ def get_juhe_image_url():
|
|||
params = {"token": ju_he_token,"f": "json","categories": "猫羽雫","page": 1, "size": 400}
|
||||
random_url = random.choice(requests.get(ju_he_image_list, params=params).json().get('docs', [])).get('url')
|
||||
return random_url
|
||||
|
||||
|
||||
""" rua 头动图生成"""
|
||||
class rua():
|
||||
def __init__(self, img_file):
|
||||
self.author = Image.open(img_file)
|
||||
|
||||
def add_png(self, png_d):
|
||||
# 重置图片大小
|
||||
author = self.author.resize((png_d[0], png_d[1] - png_d[2]))
|
||||
|
||||
# 载入素材
|
||||
rua_p1 = Image.open(png_d[3])
|
||||
|
||||
# 创建背景模板
|
||||
rua_png1 = Image.new('RGBA', (110, 110), (255, 255, 255, 255))
|
||||
|
||||
# 使用预定义的参数:jd,合成一帧的样例
|
||||
rua_png1.paste(author, (110 - png_d[0], 110 - png_d[1] + png_d[2]), author)
|
||||
rua_png1.paste(rua_p1, (0, 110 - png_d[1] - png_d[2]), rua_p1)
|
||||
return rua_png1
|
||||
|
||||
def add_gif(self):
|
||||
|
||||
# 获取素材列表
|
||||
pst = os.listdir(rua_png)
|
||||
for i in range(len(pst)):
|
||||
pst[i] = rua_png + pst[i]
|
||||
|
||||
# 预调试好的参数,传入素材列表
|
||||
jd = [[90, 90, 5, pst[0]],
|
||||
[90, 87, 5, pst[2]],
|
||||
[90, 84, 10, pst[3]],
|
||||
[90, 81, 8, pst[4]],
|
||||
[90, 78, 5, pst[5]],
|
||||
[90, 75, 5, pst[6]],
|
||||
[90, 72, 8, pst[7]],
|
||||
[90, 74, 8, pst[8]],
|
||||
[90, 77, 9, pst[9]],
|
||||
[90, 80, 8, pst[1]]]
|
||||
|
||||
# 重置要生成的图片大小
|
||||
self.author = self.author.resize((90, 90))
|
||||
|
||||
# 绘制模板
|
||||
alpha_layer = Image.new('L', (90, 90), 0)
|
||||
draw = ImageDraw.Draw(alpha_layer)
|
||||
draw.ellipse((0, 0, 90, 90), fill=255)
|
||||
self.author.putalpha(alpha_layer)
|
||||
|
||||
# gif列表
|
||||
gifs = []
|
||||
for i in range(len(jd)):
|
||||
# 将参数传递给生成方法
|
||||
# 添加到gif列表
|
||||
gifs.append(self.add_png(jd[i]))
|
||||
|
||||
# 文件名,是否保存所有,图片列表,fps/ms
|
||||
gifs[0].save(image_local_qq_image_path + '/rua.gif', "GIF", save_all=True, append_images=gifs, duration=35, loop=0)
|
||||
self.author.close()
|
||||
return image_local_qq_image_path + '/rua.gif'
|
||||
|
||||
"""
|
||||
图文合成
|
||||
"""
|
||||
async def add_text_to_image(image_path, output_path,content,font_path, font_size, text_color,text_position ,position):
|
||||
"""
|
||||
给图片添加文字
|
||||
:param image_path: 输入图片的路径
|
||||
:param output_path: 合成后的图片名称
|
||||
:param content: 要添加的文字内容
|
||||
:param font_path: 字体文件路径
|
||||
:param font_size: 文字的字体大小
|
||||
:param text_color: 文字颜色 (255, 0, 0) "#FF0000" "red"
|
||||
:param position: 文字位置,可选值:"left", "right", "center", "top", "bottom", "top left corner", "top right corner", "bottom left corner", "bottom right corner"
|
||||
:return:
|
||||
"""
|
||||
# 打开图片
|
||||
image = Image.open(image_path)
|
||||
# 创建一个可用于绘制的对象
|
||||
draw = ImageDraw.Draw(image)
|
||||
# 设置字体和字体大小
|
||||
font = ImageFont.truetype(font_path, font_size)
|
||||
|
||||
wrapped_text,current_width = "",0
|
||||
|
||||
# 遍历文本中的每个字符
|
||||
for char in content:
|
||||
# 获取字符的宽度
|
||||
char_width, _ = draw.textbbox((0, 0), char, font=font)[2:]
|
||||
# 如果当前行的宽度加上字符宽度超过图片指定宽度,则换行
|
||||
if current_width + char_width > image.width * 9 // 10: # 这里是图片的十分之九
|
||||
wrapped_text += "\n"
|
||||
current_width = 0
|
||||
# 将字符添加到当前行
|
||||
wrapped_text += char
|
||||
# 更新当前行的宽度
|
||||
current_width += char_width
|
||||
|
||||
# 获取换行后文本的宽度和高度
|
||||
text_width, text_height = draw.textbbox((0, 0), wrapped_text, font=font)[2:]
|
||||
|
||||
# 根据位置参数计算文本的位置
|
||||
if position == "left":
|
||||
position = (0, (image.height - text_height) // 2)
|
||||
elif position == "right":
|
||||
position = (image.width - text_width, (image.height - text_height) // 2)
|
||||
elif position == "center":
|
||||
position = ((image.width - text_width) // 2, (image.height - text_height) // 2)
|
||||
elif position == "top":
|
||||
position = ((image.width - text_width) // 2, 0)
|
||||
elif position == "bottom":
|
||||
position = ((image.width - text_width) // 2, image.height - text_height)
|
||||
elif position == "top left corner":
|
||||
position = (0, 0)
|
||||
elif position == "top right corner":
|
||||
position = (image.width - text_width, 0)
|
||||
elif position == "bottom left corner":
|
||||
position = (0, image.height - text_height)
|
||||
elif position == "bottom right corner":
|
||||
position = (image.width - text_width, image.height - text_height)
|
||||
elif position == "bottom left corner 9/10":
|
||||
position = (0, image.height * 9 // 10 - text_height)
|
||||
|
||||
# 在图片上绘制文本
|
||||
draw.multiline_text(position, wrapped_text, font=font, fill=text_color, align=text_position)
|
||||
# 保存合成后的图片
|
||||
image.save(output_path)
|
||||
# 关闭图片
|
||||
# image.close()
|
||||
|
||||
async def delete_file(file_path):
|
||||
try:
|
||||
os.remove(file_path)
|
||||
except FileNotFoundError:
|
||||
print(f"文件 {file_path} 不存在。")
|
||||
except Exception as e:
|
||||
print(f"删除文件时发生错误: {e}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
# print(get_smms_image_url())
|
||||
# print(get_juhe_image_url())
|
||||
# print(get_image_names())
|
||||
# file_path = '8A91A2F3BE5B5AF3FEC97FB5AA6D9B38.jpg'
|
||||
# au = rua(file_path).add_gif()
|
||||
image_path = "021.png"
|
||||
content = "你是很大的哈设计开发哈卡斯萨夫卡是大华饭店不是的话覆盖过海宿管会啊傻瓜金佛上帝海水淡化你是很大的哈设计开发哈卡斯萨夫卡是大华饭店不是的话覆盖u过海宿管会啊傻瓜金佛上帝海水淡化你"
|
||||
output_path = "output.png"
|
||||
add_text_to_image(image_path, content, output_path, "微软雅黑.ttc",text_color = (255, 0, 0),font_size=48,position="top")
|
||||
44
src/clover_image/qq_image.py
Normal file
44
src/clover_image/qq_image.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
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)
|
||||
65
src/clover_image/rua.py
Normal file
65
src/clover_image/rua.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import os
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
from src.configs.path_config import image_local_qq_image_path,rua_png
|
||||
|
||||
|
||||
""" rua 头动图生成"""
|
||||
class rua():
|
||||
def __init__(self, img_file):
|
||||
self.author = Image.open(img_file)
|
||||
|
||||
def add_png(self, png_d):
|
||||
# 重置图片大小
|
||||
author = self.author.resize((png_d[0], png_d[1] - png_d[2]))
|
||||
|
||||
# 载入素材
|
||||
rua_p1 = Image.open(png_d[3])
|
||||
|
||||
# 创建背景模板
|
||||
rua_png1 = Image.new('RGBA', (110, 110), (255, 255, 255, 255))
|
||||
|
||||
# 使用预定义的参数:jd,合成一帧的样例
|
||||
rua_png1.paste(author, (110 - png_d[0], 110 - png_d[1] + png_d[2]), author)
|
||||
rua_png1.paste(rua_p1, (0, 110 - png_d[1] - png_d[2]), rua_p1)
|
||||
return rua_png1
|
||||
|
||||
def add_gif(self):
|
||||
|
||||
# 获取素材列表
|
||||
pst = os.listdir(rua_png)
|
||||
for i in range(len(pst)):
|
||||
pst[i] = rua_png + pst[i]
|
||||
|
||||
# 预调试好的参数,传入素材列表
|
||||
jd = [[90, 90, 5, pst[0]],
|
||||
[90, 87, 5, pst[2]],
|
||||
[90, 84, 10, pst[3]],
|
||||
[90, 81, 8, pst[4]],
|
||||
[90, 78, 5, pst[5]],
|
||||
[90, 75, 5, pst[6]],
|
||||
[90, 72, 8, pst[7]],
|
||||
[90, 74, 8, pst[8]],
|
||||
[90, 77, 9, pst[9]],
|
||||
[90, 80, 8, pst[1]]]
|
||||
|
||||
# 重置要生成的图片大小
|
||||
self.author = self.author.resize((90, 90))
|
||||
|
||||
# 绘制模板
|
||||
alpha_layer = Image.new('L', (90, 90), 0)
|
||||
draw = ImageDraw.Draw(alpha_layer)
|
||||
draw.ellipse((0, 0, 90, 90), fill=255)
|
||||
self.author.putalpha(alpha_layer)
|
||||
|
||||
# gif列表
|
||||
gifs = []
|
||||
for i in range(len(jd)):
|
||||
# 将参数传递给生成方法
|
||||
# 添加到gif列表
|
||||
gifs.append(self.add_png(jd[i]))
|
||||
|
||||
# 文件名,是否保存所有,图片列表,fps/ms
|
||||
gifs[0].save(image_local_qq_image_path + '/rua.gif', "GIF", save_all=True, append_images=gifs, duration=35, loop=0)
|
||||
self.author.close()
|
||||
return image_local_qq_image_path + '/rua.gif'
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
# https://api.bilibili.com/x/web-interface/search/type?keyword=av28465342&search_type=video&page=1
|
||||
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import nonebot.adapters.qq.exception
|
||||
from nonebot import on_command
|
||||
from nonebot.rule import to_me
|
||||
|
|
|
|||
|
|
@ -1,23 +1,17 @@
|
|||
import os
|
||||
import yaml
|
||||
import random
|
||||
from pathlib import Path
|
||||
from nonebot import on_message
|
||||
from nonebot.rule import Rule, to_me
|
||||
from nonebot.plugin import on_command, on_keyword
|
||||
from nonebot.adapters.qq import Message, MessageEvent, MessageSegment
|
||||
|
||||
from nonebot.adapters.qq import Message, MessageEvent
|
||||
from src.clover_openai import ai_chat
|
||||
from src.clover_sqlite.models.chat import GroupChatRole
|
||||
from src.clover_sqlite.models.user import UserList
|
||||
import platform
|
||||
import psutil
|
||||
import time
|
||||
|
||||
menu = ['/今日运势','/今日塔罗','/图','/点歌','/摸摸头','/群老婆','/今日老婆', "/开启ai","/关闭ai","/角色列表","/添加人设", "/更新人设", "/删除人设", "/切换人设", "/管理员注册",
|
||||
'/待办', '/test','/天气','我喜欢你', "❤", "/待办查询", "/新建待办", "/删除待办" ,"/cf","/B站搜索", "/BV搜索", "/喜报", "/悲报", "/luxun","/鲁迅说",
|
||||
"/奶龙", "/repo", "/info", "/menu"]
|
||||
|
||||
send_menu = ["/开启ai","/关闭ai","/角色列表","/添加人设", "/更新人设", "/删除人设", "/切换人设", "/管理员注册", '/待办', '/test', '我喜欢你', "❤", "/menu"]
|
||||
|
||||
async def check_value_in_menu(message: MessageEvent) -> bool:
|
||||
value = message.get_plaintext().strip().split(" ")
|
||||
|
|
@ -58,6 +52,13 @@ text_list = [
|
|||
"难道是新指令?猫猫一脸茫然,喵~" + '\n' + "(๑>ڡ<)☆ 说详细点,别这么隐晦,喵~",
|
||||
]
|
||||
|
||||
get_menu = on_command("menu", rule=to_me(), priority=10, block=True)
|
||||
@get_menu.handle()
|
||||
async def send_menu_list():
|
||||
content = "\n"
|
||||
for command in send_menu:
|
||||
content += command + "\n"
|
||||
await get_menu.finish(content)
|
||||
|
||||
love = on_keyword({"我喜欢你", "❤"}, rule=to_me(), priority=2, block=False)
|
||||
@love.handle()
|
||||
|
|
@ -68,61 +69,3 @@ test = on_command("test", rule=to_me(), priority=10, block=True)
|
|||
@test.handle()
|
||||
async def bot_on_ready():
|
||||
await test.finish("\nBoost & Magnum, ready fight!!!")
|
||||
|
||||
nai_loong = on_keyword({"奶龙"}, rule=to_me(), priority=1, block=True)
|
||||
@nai_loong.handle()
|
||||
async def not_nai_loong():
|
||||
await nai_loong.finish(message=Message(random.choice(text_list_nailoong)))
|
||||
|
||||
text_list_nailoong = [
|
||||
"我是?你是?😨",
|
||||
"你才是奶龙😡",
|
||||
"你是奶龙?🤔我是奶龙?😨你才是奶龙!😱",
|
||||
"今夜星光闪闪✨️我爱你的心满满🤩",
|
||||
"唐",
|
||||
]
|
||||
|
||||
repository = on_command("repo", rule=to_me(), priority=10, block=True)
|
||||
@repository.handle()
|
||||
async def github_repo():
|
||||
|
||||
content = "三叶草bot仓库地址\n一起来搭个机器人吧😆"
|
||||
msg = Message([
|
||||
MessageSegment.file_image(Path("src/resources/clover_image/github_repo/SanYeCao-Nonebot3.png")),
|
||||
MessageSegment.text(content),
|
||||
])
|
||||
await repository.finish(msg)
|
||||
|
||||
platform_info = on_command("info", rule=to_me(), priority=10, block=True)
|
||||
@platform_info.handle()
|
||||
async def get_platform_info():
|
||||
# 获取操作系统名称
|
||||
os_name = platform.system()
|
||||
os_version = platform.version()
|
||||
processor_name = platform.processor()
|
||||
processor_architecture = platform.architecture()
|
||||
python_version = platform.python_version()
|
||||
memory = psutil.virtual_memory().total
|
||||
memory_usage = psutil.virtual_memory().percent
|
||||
cpu_usage = psutil.cpu_percent()
|
||||
|
||||
content = ("\n[操作系统]: " + os_name + "\n[系统版本]: " + os_version + "\n[开机时长]: " + str(format((time.time() - psutil.boot_time()) / 3600, ".1f")) + "h" +
|
||||
"\n[服务器时间]: \n" + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) +
|
||||
"\n\n[CPU架构]: " + processor_architecture[0] + ", " + processor_architecture[1] +
|
||||
"\n[CPU占用]: " + str(cpu_usage) + "%" +
|
||||
"\n\n[物理内存]: " + str(format(memory / (1024 ** 3), ".1f")) + "GB" +
|
||||
"\n[内存占用]: " + str(memory_usage) + "%"
|
||||
"\n\n[Python版本]: " + python_version +
|
||||
"\n\n[Bot源码]: 请发送 /repo \n[联系我们]: cloverta@petalmail·com")
|
||||
await platform_info.finish(content)
|
||||
|
||||
get_menu = on_command("menu", rule=to_me(), priority=10, block=True)
|
||||
@get_menu.handle()
|
||||
async def send_menu_list():
|
||||
content = "\n"
|
||||
for command in menu:
|
||||
if command in ["/开启ai","/关闭ai","/角色列表","/添加人设", "/更新人设", "/删除人设", "/切换人设", "/管理员注册", '/待办', '/test', '我喜欢你', "❤", "/menu"]:
|
||||
continue
|
||||
content += command + "\n"
|
||||
|
||||
await get_menu.finish(content)
|
||||
|
|
@ -6,7 +6,8 @@ import urllib.parse
|
|||
import requests
|
||||
import time
|
||||
import httpx
|
||||
from src.clover_image.get_image import add_text_to_image,delete_file
|
||||
from src.clover_image.add_text_to_image import add_text_to_image
|
||||
from src.clover_image.delete_file import delete_file
|
||||
from src.configs.path_config import font_path,good_bad,temp_path
|
||||
|
||||
# good_news = on_command("喜报", rule=to_me(), priority=10, block=True, aliases={"悲报"})
|
||||
|
|
|
|||
|
|
@ -1,13 +1,26 @@
|
|||
import random
|
||||
from pathlib import Path
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.plugin import on_command
|
||||
from nonebot.adapters.qq import MessageSegment
|
||||
from nonebot.adapters.qq import MessageSegment,MessageEvent
|
||||
from src.clover_image.get_image import get_image_names
|
||||
from src.clover_image.download_image import download_image
|
||||
from src.configs.path_config import temp_path
|
||||
|
||||
image = on_command("图", rule=to_me(), priority=10, block=True)
|
||||
|
||||
@image.handle()
|
||||
async def handle_function():
|
||||
|
||||
local_image_path = get_image_names()
|
||||
await image.finish(MessageSegment.file_image(Path(local_image_path)))
|
||||
|
||||
|
||||
image = on_command("/搜图", rule=to_me(), priority=10, block=True)
|
||||
@image.handle()
|
||||
async def handle_function(message: MessageEvent):
|
||||
|
||||
filename = str(message.get_user_id()) + str(random.randint(0, 10000)) + ".jpg"
|
||||
image_ptah = temp_path + filename
|
||||
|
||||
download_image(message.attachments[0].url, image_ptah)
|
||||
await image.finish(MessageSegment.file_image(Path(image_ptah)))
|
||||
18
src/plugins/nai_loong.py
Normal file
18
src/plugins/nai_loong.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import random
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.plugin import on_keyword
|
||||
from nonebot.adapters.qq import Message
|
||||
|
||||
|
||||
nai_loong = on_keyword({"奶龙"}, rule=to_me(), priority=1, block=True)
|
||||
@nai_loong.handle()
|
||||
async def not_nai_loong():
|
||||
await nai_loong.finish(message=Message(random.choice(text_list_nailoong)))
|
||||
|
||||
text_list_nailoong = [
|
||||
"我是?你是?😨",
|
||||
"你才是奶龙😡",
|
||||
"你是奶龙?🤔我是奶龙?😨你才是奶龙!😱",
|
||||
"今夜星光闪闪✨️我爱你的心满满🤩",
|
||||
"唐",
|
||||
]
|
||||
42
src/plugins/platform.py
Normal file
42
src/plugins/platform.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
from pathlib import Path
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.plugin import on_command
|
||||
from nonebot.adapters.qq import Message, MessageSegment
|
||||
import platform
|
||||
import psutil
|
||||
import time
|
||||
|
||||
|
||||
repository = on_command("repo", rule=to_me(), priority=10, block=True)
|
||||
@repository.handle()
|
||||
async def github_repo():
|
||||
|
||||
content = "三叶草bot仓库地址\n一起来搭个机器人吧😆"
|
||||
msg = Message([
|
||||
MessageSegment.file_image(Path("src/resources/image/github_repo/SanYeCao-Nonebot3.png")),
|
||||
MessageSegment.text(content),
|
||||
])
|
||||
await repository.finish(msg)
|
||||
|
||||
platform_info = on_command("info", rule=to_me(), priority=10, block=True)
|
||||
@platform_info.handle()
|
||||
async def get_platform_info():
|
||||
# 获取操作系统名称
|
||||
os_name = platform.system()
|
||||
os_version = platform.version()
|
||||
processor_name = platform.processor()
|
||||
processor_architecture = platform.architecture()
|
||||
python_version = platform.python_version()
|
||||
memory = psutil.virtual_memory().total
|
||||
memory_usage = psutil.virtual_memory().percent
|
||||
cpu_usage = psutil.cpu_percent()
|
||||
|
||||
content = ("\n[操作系统]: " + os_name + "\n[系统版本]: " + os_version + "\n[开机时长]: " + str(format((time.time() - psutil.boot_time()) / 3600, ".1f")) + "h" +
|
||||
"\n[服务器时间]: \n" + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) +
|
||||
"\n\n[CPU架构]: " + processor_architecture[0] + ", " + processor_architecture[1] +
|
||||
"\n[CPU占用]: " + str(cpu_usage) + "%" +
|
||||
"\n\n[物理内存]: " + str(format(memory / (1024 ** 3), ".1f")) + "GB" +
|
||||
"\n[内存占用]: " + str(memory_usage) + "%"
|
||||
"\n\n[Python版本]: " + python_version +
|
||||
"\n\n[Bot源码]: 请发送 /repo \n[联系我们]: cloverta@petalmail·com")
|
||||
await platform_info.finish(content)
|
||||
|
|
@ -3,7 +3,7 @@ from nonebot.adapters.qq import Message, MessageEvent
|
|||
from nonebot.adapters.qq import MessageSegment
|
||||
from nonebot.plugin import on_command
|
||||
from nonebot.rule import to_me
|
||||
from src.clover_image.get_image import download_qq_image,qq_image_delete
|
||||
from src.clover_image.qq_image import download_qq_image,qq_image_delete
|
||||
from src.clover_sqlite.models.user import UserList
|
||||
|
||||
today_group_wife = on_command("群老婆", rule=to_me(), priority=10, block=True)
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ from nonebot.rule import to_me
|
|||
from nonebot.plugin import on_command
|
||||
from nonebot.adapters.qq import Message, MessageEvent, MessageSegment
|
||||
from src.clover_sqlite.models.touch import QrTouch, QrTouchLog
|
||||
from src.clover_image.get_image import download_qq_image_by_account, qq_image_delete, rua
|
||||
|
||||
from src.clover_image.qq_image import download_qq_image_by_account, qq_image_delete
|
||||
from src.clover_image.rua import rua
|
||||
|
||||
to = on_command("摸摸头", rule=to_me(), priority=10, block=True)
|
||||
@to.handle()
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ import random
|
|||
from pathlib import Path
|
||||
from nonebot.plugin import on_command
|
||||
from nonebot.adapters.qq import MessageEvent, MessageSegment
|
||||
from src.clover_image.get_image import add_text_to_image,delete_file
|
||||
from src.clover_image.add_text_to_image import add_text_to_image
|
||||
from src.clover_image.delete_file import delete_file
|
||||
from src.configs.path_config import who_say_path,font_path,temp_path
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue