Skip to content

Commit

Permalink
新增显示系统状态插件
Browse files Browse the repository at this point in the history
  • Loading branch information
NekoRabi committed Aug 31, 2023
1 parent bcadd84 commit ef9316f
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 5 deletions.
2 changes: 1 addition & 1 deletion plugin/MajSoulInfo/majsoulinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def drawcards(userid: int, up=None) -> dict:
resultsmsg += dec
else:
gift_index = random.randint(0, 7) * 3
gifttype = random.random() *100
gifttype = random.random() * 100
if gifttype < 6.25:
gift_index += 2
# elif gifttype < 9:
Expand Down
1 change: 1 addition & 0 deletions plugin/SystemInfo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .sysinfo_fix import *
Binary file added plugin/SystemInfo/cpu.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions plugin/SystemInfo/sysinfo_fix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# -*- coding: utf-8 -*-
import datetime
import re
import time

import psutil
from PIL import Image as IMG
from PIL import ImageDraw, ImageFont
from httpx import AsyncClient
from mirai import GroupMessage, Plain, Image

from core import bot, admin

@bot.on(GroupMessage)
async def sysinfo(event: GroupMessage):
msg = "".join(map(str, event.message_chain[Plain]))
m = re.match(fr"^sysinfo$", msg.strip())
if m is None:
return
if event.sender.id not in admin:
return
cpu_percent = round((psutil.cpu_percent()), 2) # cpu使用率
memory = psutil.virtual_memory()
disk = psutil.disk_usage('C:/')
total_nc = round((float(memory.total) / 1024 / 1024)) # 总内存
used_nc = round((float(memory.used) / 1024 / 1024)) # 已用内存
percent_nc = memory.percent # 内存使用率
total_disk = round((float(disk.total) / 1024 / 1024 / 1024), 2)
used_disk = round((float(disk.used) / 1024 / 1024 / 1024), 2)
percent_disk = disk.percent
now = time.time()
boot = psutil.boot_time()
boottime = datetime.datetime.fromtimestamp(boot).strftime("%Y-%m-%d %H:%M:%S")
up_time = str(
datetime.datetime.utcfromtimestamp(now).replace(microsecond=0)
- datetime.datetime.utcfromtimestamp(boot).replace(microsecond=0)
)
try:
async with AsyncClient(
timeout=10,
proxies="http://127.0.0.1:10809",
follow_redirects=True,
) as client:
start = time.time()
resp = await client.get("https://www.pixiv.net/")
delay = (time.time() - start) * 1000
pixiv_connection = f'pixiv:{round(delay)}ms'
if delay < 2000:
percent_pixiv = 100-delay/20
except Exception as e:
pixiv_connection = 'pixiv:timeout'
percent_pixiv = 0
try:
async with AsyncClient(
timeout=10,
proxies="http://127.0.0.1:10809",
follow_redirects=True,
) as client:
start = time.time()
resp = await client.get("https://www.google.com/")
delay = (time.time() - start) * 1000
google_connection = f'google:{round(delay)}ms'
except Exception as e:
google_connection = 'google:timeout'
'''
img = IMG.new('RGB', (1080, 1280), (255, 255, 255))
draw = ImageDraw.Draw(img)
draw.rectangle((48,78,352,282),fill='white',outline=(17,125,187),width=4)
draw.rectangle((48,378,352,582),fill='white',outline=(139,18,174),width=4)
draw.rectangle((48,678,352,882),fill='white',outline=(77,166,12),width=4)
draw.rectangle((48,978,352,1182),fill='white',outline=(167,79,1),width=4)
font = ImageFont.truetype('msyh.ttc', 80)
draw.text((400,50),text='CPU',font=font,fill=(0, 0, 0))
draw.text((400,350),text='内存',font=font,fill=(0, 0, 0))
draw.text((400,650),text='磁盘(C:)',font=font,fill=(0, 0, 0))
draw.text((400,950),text='以太网',font=font,fill=(0, 0, 0))
'''
img = IMG.open(r'./plugin/SystemInfo/cpu.jpg')
draw = ImageDraw.Draw(img)
font = ImageFont.truetype('msyh.ttc', 60)
draw.text((400,150),text=f'{cpu_percent}% 2.50 GHZ\n{up_time}',font=font,fill=(0, 0, 0))
draw.text((400,450),text=f'{used_nc}/{total_nc}MB\n{percent_nc}%',font=font,fill=(0, 0, 0))
draw.text((400,750),text=f'{used_disk}/{total_disk}GB\n{percent_disk}%',font=font,fill=(0, 0, 0))
draw.text((400,1050),text=f'{google_connection}\n{pixiv_connection}',font=font,fill=(0, 0, 0))
draw.rectangle((48,280-round(cpu_percent)*2,352,282-round(cpu_percent)*2),fill=(17,125,187))
draw.rectangle((48,580-round(percent_nc)*2,352,582-round(percent_nc)*2),fill=(139,18,174))
draw.rectangle((48,880-round(percent_disk)*2,352,882-round(percent_disk)*2),fill=(77,166,12))
draw.rectangle((48,1180-round(percent_pixiv)*2,352,1182-round(percent_pixiv)*2),fill=(167,79,1))
img.save(r'./plugin/SystemInfo/now_cpu.jpg')
path = r'./plugin/SystemInfo/now_cpu.jpg'
return await bot.send(event,Image(path=r'./plugin/SystemInfo/now_cpu.jpg'))

8 changes: 4 additions & 4 deletions utils/MessageChainBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ async def build(self) -> MessageChain:
raise ValueError("消息链为空")


async def messagechain_builder(reply_choices: list = None, text: str = None, imgpath: Union[str, list] = None,
async def messagechain_builder(reply_choices: list = None, text: str = "", imgpath: Union[str, list] = None,
rndimg=False,
imgurl: str = None, imgbase64=None, at: Union[list, int] = None,
atall=False) -> MessageChain:
Expand Down Expand Up @@ -202,7 +202,7 @@ async def messagechain_builder(reply_choices: list = None, text: str = None, img
msgchain.append(Plain(" "))
if reply_choices:
msgchain.append(Plain(random.choice(reply_choices)))
elif text:
elif len(text)>0:
msgchain.append(Plain(text))
if reply_choices or text:
msgchain.append(Plain(' '))
Expand All @@ -217,7 +217,7 @@ async def messagechain_builder(reply_choices: list = None, text: str = None, img
msgchain.append(Plain("\n"))
msgchain.append(Image(base64=imgbase64))
if imgpath:
if reply_choices or text:
if reply_choices or len(text)>0:
msgchain.append(Plain("\n"))
if isinstance(imgpath, str):
msgchain.append(
Expand All @@ -227,7 +227,7 @@ async def messagechain_builder(reply_choices: list = None, text: str = None, img
msgchain.append(
await Image.from_local(filename=f"{path}"))
if imgurl:
if reply_choices or text:
if reply_choices or len(text)>0:
msgchain.append(Plain("\n"))
msgchain.append(Image(url=imgurl))
return MessageChain(msgchain)

0 comments on commit ef9316f

Please sign in to comment.