From 6e4154cdecaa7824dd8193d6cd0470e5bc480808 Mon Sep 17 00:00:00 2001 From: Chenric <91937041+ChenXu233@users.noreply.github.com> Date: Fri, 21 Jun 2024 10:04:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?:sparkles:=20=E6=81=A2=E5=A4=8D=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 5 +- nonebot_plugin_dialectlist/__init__.py | 18 ++- pdm.lock | 198 ++++++++++++++++++++++++- pyproject.toml | 4 +- 4 files changed, 219 insertions(+), 6 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bdb468c..d99f56e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,8 +10,11 @@ "dialectlist", "displayname", "parameterless", + "pyecharts", "pygal", "sqlalchemy", - "userinfo" + "userinfo", + "xaxis", + "yaxis" ] } \ No newline at end of file diff --git a/nonebot_plugin_dialectlist/__init__.py b/nonebot_plugin_dialectlist/__init__.py index 2237fe8..9be93f6 100644 --- a/nonebot_plugin_dialectlist/__init__.py +++ b/nonebot_plugin_dialectlist/__init__.py @@ -2,14 +2,18 @@ from nonebot import require require("nonebot_plugin_chatrecorder") require("nonebot_plugin_apscheduler") +require("nonebot_plugin_htmlrender") require("nonebot_plugin_userinfo") require("nonebot_plugin_alconna") require("nonebot_plugin_cesaa") import re - +import os import nonebot_plugin_saa as saa +from pyecharts.charts import Bar +from pyecharts.render import make_snapshot + from typing import Union, Optional, List from datetime import datetime, timedelta from arclet.alconna import ArparmaBehavior @@ -37,6 +41,8 @@ from nonebot_plugin_alconna import ( ) from nonebot_plugin_chatrecorder import get_message_records +from nonebot_plugin_localstore import get_cache_file +from nonebot_plugin_htmlrender import html_to_pic from nonebot_plugin_userinfo import get_user_info from nonebot_plugin_session import Session, SessionIdType, extract_session @@ -252,4 +258,12 @@ async def handle_rank( ) string += str_example - await saa.Text(string).finish(reply=True) + bar = Bar() + bar.add_xaxis(nicknames) + bar.add_yaxis("B话数量", [i[1] for i in rank]) # type: ignore + bar.render(str(get_cache_file("nonebot_plugin_dialectlist","cache.html"))) + with open(get_cache_file("nonebot_plugin_dialectlist","cache.html")) as f: + a = f.read() + image = await html_to_pic(a) + + await (saa.Text(string)+saa.Image(image)).finish(reply=True) diff --git a/pdm.lock b/pdm.lock index 4ee5852..2cc3ce2 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,18 @@ groups = ["default", "dev"] strategy = ["cross_platform", "inherit_metadata"] lock_version = "4.4.1" -content_hash = "sha256:c2bcbd7ea449960fb9b84e296de4c0925bf24e9b957351264c9c7366e91626ad" +content_hash = "sha256:fdb46c5e66cf97af4806bb28cc369a5cfee536532eb9a1b05d581d5856ffcf6d" + +[[package]] +name = "aiofiles" +version = "23.2.1" +requires_python = ">=3.7" +summary = "File support for asyncio." +groups = ["default"] +files = [ + {file = "aiofiles-23.2.1-py3-none-any.whl", hash = "sha256:19297512c647d4b27a2cf7c34caa7e405c0d60b5560618a29a9fe027b18b0107"}, + {file = "aiofiles-23.2.1.tar.gz", hash = "sha256:84ec2218d8419404abcb9f0c02df3f34c6e0a68ed41072acfb1cef5cbc29051a"}, +] [[package]] name = "alembic" @@ -422,7 +433,6 @@ version = "3.0.3" requires_python = ">=3.7" summary = "Lightweight in-process concurrent programming" groups = ["default"] -marker = "platform_machine == \"win32\" or platform_machine == \"WIN32\" or platform_machine == \"AMD64\" or platform_machine == \"amd64\" or platform_machine == \"x86_64\" or platform_machine == \"ppc64le\" or platform_machine == \"aarch64\"" files = [ {file = "greenlet-3.0.3-cp310-cp310-macosx_11_0_universal2.whl", hash = "sha256:9da2bd29ed9e4f15955dd1595ad7bc9320308a3b766ef7f837e23ad4b4aac31a"}, {file = "greenlet-3.0.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d353cadd6083fdb056bb46ed07e4340b0869c305c8ca54ef9da3421acbdf6881"}, @@ -683,6 +693,17 @@ files = [ {file = "Mako-1.3.5.tar.gz", hash = "sha256:48dbc20568c1d276a2698b36d968fa76161bf127194907ea6fc594fa81f943bc"}, ] +[[package]] +name = "markdown" +version = "3.6" +requires_python = ">=3.8" +summary = "Python implementation of John Gruber's Markdown." +groups = ["default"] +files = [ + {file = "Markdown-3.6-py3-none-any.whl", hash = "sha256:48f276f4d8cfb8ce6527c8f79e2ee29708508bf4d40aa410fbc3b4ee832c850f"}, + {file = "Markdown-3.6.tar.gz", hash = "sha256:ed4f41f6daecbeeb96e576ce414c41d2d876daa9a16cb35fa8ed8c2ddfad0224"}, +] + [[package]] name = "markdown-it-py" version = "3.0.0" @@ -923,6 +944,27 @@ files = [ {file = "nonebot_plugin_chatrecorder-0.6.0.tar.gz", hash = "sha256:a80acbbfe2388a60177effc62857fa09154a38871643e14c7eb7352226c03138"}, ] +[[package]] +name = "nonebot-plugin-htmlrender" +version = "0.3.2" +requires_python = "<4.0,>=3.9" +summary = "通过浏览器渲染图片" +groups = ["default"] +dependencies = [ + "Pygments>=2.10.0", + "aiofiles>=0.8.0", + "jinja2>=3.0.3", + "markdown>=3.3.6", + "nonebot2[fastapi]>=2.2.0", + "playwright>=1.17.2", + "pymdown-extensions>=9.1", + "python-markdown-math>=0.8", +] +files = [ + {file = "nonebot_plugin_htmlrender-0.3.2-py3-none-any.whl", hash = "sha256:6de89ce6427faa1c5096de9b64565c66293e319813da04267954dd362707c0ed"}, + {file = "nonebot_plugin_htmlrender-0.3.2.tar.gz", hash = "sha256:acddfe12a2a82784e32e1d2b00d22de2ad75da5452fa1290fb8aa89f0d415e7d"}, +] + [[package]] name = "nonebot-plugin-localstore" version = "0.6.0" @@ -1125,6 +1167,40 @@ files = [ {file = "pkginfo-1.11.1.tar.gz", hash = "sha256:2e0dca1cf4c8e39644eed32408ea9966ee15e0d324c62ba899a393b3c6b467aa"}, ] +[[package]] +name = "playwright" +version = "1.44.0" +requires_python = ">=3.8" +summary = "A high-level API to automate web browsers" +groups = ["default"] +dependencies = [ + "greenlet==3.0.3", + "pyee==11.1.0", +] +files = [ + {file = "playwright-1.44.0-py3-none-macosx_10_13_x86_64.whl", hash = "sha256:c2317a80896796fdeb03d60f06cc229e775ff2e19b80c64b1bb9b29c8a59d992"}, + {file = "playwright-1.44.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:54d44fb634d870839301c2326e1e12a178a1be0de76d0caaec230ab075c2e077"}, + {file = "playwright-1.44.0-py3-none-macosx_11_0_universal2.whl", hash = "sha256:64b67194e73b47ae72acf25f1a9cfacfef38ca2b52e4bb8b0abd385c5deeaadf"}, + {file = "playwright-1.44.0-py3-none-manylinux1_x86_64.whl", hash = "sha256:29161b1fae71f7c402df5b15f0bd3deaeecd8b3d1ecd9ff01271700c66210e7b"}, + {file = "playwright-1.44.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f8c8a3bfea17576d3f94a2363eee195cbda8dbba86975588c7eaac7792b25eee"}, + {file = "playwright-1.44.0-py3-none-win32.whl", hash = "sha256:235e37832deaa9af8a629d09955396259ab757533cc1922f9b0308b4ee0d9cdf"}, + {file = "playwright-1.44.0-py3-none-win_amd64.whl", hash = "sha256:5b8a4a1d4d50f4ff99b47965576322a8c4e34631854b862a25c1feb824be22a8"}, +] + +[[package]] +name = "prettytable" +version = "3.10.0" +requires_python = ">=3.8" +summary = "A simple Python library for easily displaying tabular data in a visually appealing ASCII table format" +groups = ["default"] +dependencies = [ + "wcwidth", +] +files = [ + {file = "prettytable-3.10.0-py3-none-any.whl", hash = "sha256:6536efaf0757fdaa7d22e78b3aac3b69ea1b7200538c2c6995d649365bddab92"}, + {file = "prettytable-3.10.0.tar.gz", hash = "sha256:9665594d137fb08a1117518c25551e0ede1687197cf353a4fdc78d27e1073568"}, +] + [[package]] name = "pycparser" version = "2.22" @@ -1220,6 +1296,35 @@ files = [ {file = "pydantic_core-2.18.4.tar.gz", hash = "sha256:ec3beeada09ff865c344ff3bc2f427f5e6c26401cc6113d77e372c3fdac73864"}, ] +[[package]] +name = "pyecharts" +version = "2.0.5" +summary = "Python options, make charting easier" +groups = ["default"] +dependencies = [ + "jinja2", + "prettytable", + "simplejson", +] +files = [ + {file = "pyecharts-2.0.5-py3-none-any.whl", hash = "sha256:77380f671679e349d676835a3a0e2f27644fec63e695e9c64556a2dae85d4070"}, + {file = "pyecharts-2.0.5.tar.gz", hash = "sha256:664bdb6075eb585900d97204382905c958ade306b277ae68aedd310434de56ff"}, +] + +[[package]] +name = "pyee" +version = "11.1.0" +requires_python = ">=3.8" +summary = "A rough port of Node.js's EventEmitter to Python with a few tricks of its own" +groups = ["default"] +dependencies = [ + "typing-extensions", +] +files = [ + {file = "pyee-11.1.0-py3-none-any.whl", hash = "sha256:5d346a7d0f861a4b2e6c47960295bd895f816725b27d656181947346be98d7c1"}, + {file = "pyee-11.1.0.tar.gz", hash = "sha256:b53af98f6990c810edd9b56b87791021a8f54fd13db4edd1142438d44ba2263f"}, +] + [[package]] name = "pygal" version = "3.0.4" @@ -1255,6 +1360,21 @@ files = [ {file = "pygtrie-2.5.0.tar.gz", hash = "sha256:203514ad826eb403dab1d2e2ddd034e0d1534bbe4dbe0213bb0593f66beba4e2"}, ] +[[package]] +name = "pymdown-extensions" +version = "10.8.1" +requires_python = ">=3.8" +summary = "Extension pack for Python Markdown." +groups = ["default"] +dependencies = [ + "markdown>=3.6", + "pyyaml", +] +files = [ + {file = "pymdown_extensions-10.8.1-py3-none-any.whl", hash = "sha256:f938326115884f48c6059c67377c46cf631c733ef3629b6eed1349989d1b30cb"}, + {file = "pymdown_extensions-10.8.1.tar.gz", hash = "sha256:3ab1db5c9e21728dabf75192d71471f8e50f216627e9a1fa9535ecb0231b9940"}, +] + [[package]] name = "python-dotenv" version = "1.0.1" @@ -1266,6 +1386,20 @@ files = [ {file = "python_dotenv-1.0.1-py3-none-any.whl", hash = "sha256:f7b63ef50f1b690dddf550d03497b66d609393b40b564ed0d674909a68ebf16a"}, ] +[[package]] +name = "python-markdown-math" +version = "0.8" +requires_python = ">=3.6" +summary = "Math extension for Python-Markdown" +groups = ["default"] +dependencies = [ + "Markdown>=3.0", +] +files = [ + {file = "python-markdown-math-0.8.tar.gz", hash = "sha256:8564212af679fc18d53f38681f16080fcd3d186073f23825c7ce86fadd3e3635"}, + {file = "python_markdown_math-0.8-py3-none-any.whl", hash = "sha256:c685249d84b5b697e9114d7beb352bd8ca2e07fd268fd4057ffca888c14641e5"}, +] + [[package]] name = "python-multipart" version = "0.0.9" @@ -1469,6 +1603,56 @@ files = [ {file = "shellingham-1.5.4.tar.gz", hash = "sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de"}, ] +[[package]] +name = "simplejson" +version = "3.19.2" +requires_python = ">=2.5, !=3.0.*, !=3.1.*, !=3.2.*" +summary = "Simple, fast, extensible JSON encoder/decoder for Python" +groups = ["default"] +files = [ + {file = "simplejson-3.19.2-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:2f98d918f7f3aaf4b91f2b08c0c92b1774aea113334f7cde4fe40e777114dbe6"}, + {file = "simplejson-3.19.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:7d74beca677623481810c7052926365d5f07393c72cbf62d6cce29991b676402"}, + {file = "simplejson-3.19.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:7f2398361508c560d0bf1773af19e9fe644e218f2a814a02210ac2c97ad70db0"}, + {file = "simplejson-3.19.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6ad331349b0b9ca6da86064a3599c425c7a21cd41616e175ddba0866da32df48"}, + {file = "simplejson-3.19.2-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:332c848f02d71a649272b3f1feccacb7e4f7e6de4a2e6dc70a32645326f3d428"}, + {file = "simplejson-3.19.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:25785d038281cd106c0d91a68b9930049b6464288cea59ba95b35ee37c2d23a5"}, + {file = "simplejson-3.19.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:18955c1da6fc39d957adfa346f75226246b6569e096ac9e40f67d102278c3bcb"}, + {file = "simplejson-3.19.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:11cc3afd8160d44582543838b7e4f9aa5e97865322844b75d51bf4e0e413bb3e"}, + {file = "simplejson-3.19.2-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:b01fda3e95d07a6148702a641e5e293b6da7863f8bc9b967f62db9461330562c"}, + {file = "simplejson-3.19.2-cp310-cp310-musllinux_1_1_ppc64le.whl", hash = "sha256:778331444917108fa8441f59af45886270d33ce8a23bfc4f9b192c0b2ecef1b3"}, + {file = "simplejson-3.19.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:9eb117db8d7ed733a7317c4215c35993b815bf6aeab67523f1f11e108c040672"}, + {file = "simplejson-3.19.2-cp310-cp310-win32.whl", hash = "sha256:39b6d79f5cbfa3eb63a869639cfacf7c41d753c64f7801efc72692c1b2637ac7"}, + {file = "simplejson-3.19.2-cp310-cp310-win_amd64.whl", hash = "sha256:5675e9d8eeef0aa06093c1ff898413ade042d73dc920a03e8cea2fb68f62445a"}, + {file = "simplejson-3.19.2-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:ed628c1431100b0b65387419551e822987396bee3c088a15d68446d92f554e0c"}, + {file = "simplejson-3.19.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:adcb3332979cbc941b8fff07181f06d2b608625edc0a4d8bc3ffc0be414ad0c4"}, + {file = "simplejson-3.19.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:08889f2f597ae965284d7b52a5c3928653a9406d88c93e3161180f0abc2433ba"}, + {file = "simplejson-3.19.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ef7938a78447174e2616be223f496ddccdbf7854f7bf2ce716dbccd958cc7d13"}, + {file = "simplejson-3.19.2-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a970a2e6d5281d56cacf3dc82081c95c1f4da5a559e52469287457811db6a79b"}, + {file = "simplejson-3.19.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:554313db34d63eac3b3f42986aa9efddd1a481169c12b7be1e7512edebff8eaf"}, + {file = "simplejson-3.19.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4d36081c0b1c12ea0ed62c202046dca11438bee48dd5240b7c8de8da62c620e9"}, + {file = "simplejson-3.19.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:a3cd18e03b0ee54ea4319cdcce48357719ea487b53f92a469ba8ca8e39df285e"}, + {file = "simplejson-3.19.2-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:66e5dc13bfb17cd6ee764fc96ccafd6e405daa846a42baab81f4c60e15650414"}, + {file = "simplejson-3.19.2-cp311-cp311-musllinux_1_1_ppc64le.whl", hash = "sha256:972a7833d4a1fcf7a711c939e315721a88b988553fc770a5b6a5a64bd6ebeba3"}, + {file = "simplejson-3.19.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:3e74355cb47e0cd399ead3477e29e2f50e1540952c22fb3504dda0184fc9819f"}, + {file = "simplejson-3.19.2-cp311-cp311-win32.whl", hash = "sha256:1dd4f692304854352c3e396e9b5f0a9c9e666868dd0bdc784e2ac4c93092d87b"}, + {file = "simplejson-3.19.2-cp311-cp311-win_amd64.whl", hash = "sha256:9300aee2a8b5992d0f4293d88deb59c218989833e3396c824b69ba330d04a589"}, + {file = "simplejson-3.19.2-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:b8d940fd28eb34a7084877747a60873956893e377f15a32ad445fe66c972c3b8"}, + {file = "simplejson-3.19.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:4969d974d9db826a2c07671273e6b27bc48e940738d768fa8f33b577f0978378"}, + {file = "simplejson-3.19.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:c594642d6b13d225e10df5c16ee15b3398e21a35ecd6aee824f107a625690374"}, + {file = "simplejson-3.19.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e2f5a398b5e77bb01b23d92872255e1bcb3c0c719a3be40b8df146570fe7781a"}, + {file = "simplejson-3.19.2-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:176a1b524a3bd3314ed47029a86d02d5a95cc0bee15bd3063a1e1ec62b947de6"}, + {file = "simplejson-3.19.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f3c7363a8cb8c5238878ec96c5eb0fc5ca2cb11fc0c7d2379863d342c6ee367a"}, + {file = "simplejson-3.19.2-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:346820ae96aa90c7d52653539a57766f10f33dd4be609206c001432b59ddf89f"}, + {file = "simplejson-3.19.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:de9a2792612ec6def556d1dc621fd6b2073aff015d64fba9f3e53349ad292734"}, + {file = "simplejson-3.19.2-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:1c768e7584c45094dca4b334af361e43b0aaa4844c04945ac7d43379eeda9bc2"}, + {file = "simplejson-3.19.2-cp312-cp312-musllinux_1_1_ppc64le.whl", hash = "sha256:9652e59c022e62a5b58a6f9948b104e5bb96d3b06940c6482588176f40f4914b"}, + {file = "simplejson-3.19.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:9c1a4393242e321e344213a90a1e3bf35d2f624aa8b8f6174d43e3c6b0e8f6eb"}, + {file = "simplejson-3.19.2-cp312-cp312-win32.whl", hash = "sha256:7cb98be113911cb0ad09e5523d0e2a926c09a465c9abb0784c9269efe4f95917"}, + {file = "simplejson-3.19.2-cp312-cp312-win_amd64.whl", hash = "sha256:6779105d2fcb7fcf794a6a2a233787f6bbd4731227333a072d8513b252ed374f"}, + {file = "simplejson-3.19.2-py3-none-any.whl", hash = "sha256:bcedf4cae0d47839fee7de344f96b5694ca53c786f28b5f773d4f0b265a159eb"}, + {file = "simplejson-3.19.2.tar.gz", hash = "sha256:9eb442a2442ce417801c912df68e1f6ccfcd41577ae7274953ab3ad24ef7d82c"}, +] + [[package]] name = "six" version = "1.16.0" @@ -1891,6 +2075,16 @@ files = [ {file = "watchfiles-0.22.0.tar.gz", hash = "sha256:988e981aaab4f3955209e7e28c7794acdb690be1efa7f16f8ea5aba7ffdadacb"}, ] +[[package]] +name = "wcwidth" +version = "0.2.13" +summary = "Measures the displayed width of unicode strings in a terminal" +groups = ["default"] +files = [ + {file = "wcwidth-0.2.13-py2.py3-none-any.whl", hash = "sha256:3da69048e4540d84af32131829ff948f1e022c1c6bdb8d6102117aac784f6859"}, + {file = "wcwidth-0.2.13.tar.gz", hash = "sha256:72ea0c06399eb286d978fdedb6923a9eb47e1c486ce63e9b4e64fc18303972b5"}, +] + [[package]] name = "websockets" version = "12.0" diff --git a/pyproject.toml b/pyproject.toml index 8600a6e..8c8fdab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "nonebot_plugin_dialectlist" -version = "2.0.0" +version = "2.0.3" description = "Default template for PDM package" authors = [ {name = "Chen_Xu233", email = "woyerpa@outlook.com"}, @@ -14,6 +14,8 @@ dependencies = [ "nonebot-plugin-alconna>=0.46.6", "nonebot-plugin-cesaa>=0.4.0", "nonebot-plugin-userinfo>=0.2.4", + "pyecharts>=2.0.5", + "nonebot-plugin-htmlrender>=0.3.2", ] requires-python = ">=3.10,<4.0" readme = "README.md" From 471585beb015dec3ed2eba8371b40aca0d31f354 Mon Sep 17 00:00:00 2001 From: Chenric <91937041+ChenXu233@users.noreply.github.com> Date: Sat, 22 Jun 2024 00:10:19 +0800 Subject: [PATCH 2/2] =?UTF-8?q?:art:=20:construction:=20=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 1 + nonebot_plugin_dialectlist/__init__.py | 54 ++++++++------------------ nonebot_plugin_dialectlist/render.py | 1 + nonebot_plugin_dialectlist/storage.py | 1 + nonebot_plugin_dialectlist/time.py | 1 + nonebot_plugin_dialectlist/utils.py | 29 +++++++++++--- pyproject.toml | 17 +++++++- 7 files changed, 61 insertions(+), 43 deletions(-) create mode 100644 nonebot_plugin_dialectlist/render.py create mode 100644 nonebot_plugin_dialectlist/storage.py create mode 100644 nonebot_plugin_dialectlist/time.py diff --git a/.vscode/settings.json b/.vscode/settings.json index d99f56e..69e2b4b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,6 +9,7 @@ "chatrecorder", "dialectlist", "displayname", + "htmlrender", "parameterless", "pyecharts", "pygal", diff --git a/nonebot_plugin_dialectlist/__init__.py b/nonebot_plugin_dialectlist/__init__.py index 9be93f6..bc60cdb 100644 --- a/nonebot_plugin_dialectlist/__init__.py +++ b/nonebot_plugin_dialectlist/__init__.py @@ -8,11 +8,11 @@ require("nonebot_plugin_alconna") require("nonebot_plugin_cesaa") import re -import os import nonebot_plugin_saa as saa from pyecharts.charts import Bar -from pyecharts.render import make_snapshot +from pyecharts import options as opts +from pyecharts.globals import ThemeType from typing import Union, Optional, List from datetime import datetime, timedelta @@ -56,6 +56,7 @@ from .utils import ( got_rank, msg_counter, persist_id2user_id, + parse_datetime ) __plugin_meta__ = PluginMetadata( @@ -80,25 +81,25 @@ class SameTime(ArparmaBehavior): if type is None and time: interface.behave_fail() +def wrapper(slot: Union[int, str], content: Optional[str]) -> str: + if slot == "type" and content: + return content + return "" # pragma: no cover rank_cmd = on_alconna( Alconna( "B话榜", Args["type?", ["今日", "昨日", "本周", "上周", "本月", "上月", "年度", "历史"]][ - "time?", str + "time?", str, + "group_id?", int ], behaviors=[SameTime()], ), + aliases={"废话榜"}, use_cmd_start=True, ) -def wrapper(slot: Union[int, str], content: Optional[str]) -> str: - if slot == "type" and content: - return content - return "" # pragma: no cover - - rank_cmd.shortcut( r"(?P今日|昨日|本周|上周|本月|上月|年度|历史)B话榜", { @@ -109,41 +110,21 @@ rank_cmd.shortcut( }, ) - -def parse_datetime(key: str): - """解析数字,并将结果存入 state 中""" - - async def _key_parser( - matcher: AlconnaMatcher, - state: T_State, - input: Union[datetime, Message] = Arg(key), - ): - if isinstance(input, datetime): - return - - plaintext = input.extract_plain_text() - try: - state[key] = get_datetime_fromisoformat_with_timezone(plaintext) - except ValueError: - await matcher.reject_arg(key, "请输入正确的日期,不然我没法理解呢!") - - return _key_parser - - -# TODO 处理函数更新 -# 参考词云 - - # 这段函数完全抄的词云 @rank_cmd.handle() async def _group_message( state: T_State, + session: Session = Depends(extract_session), type: Optional[str] = None, time: Optional[str] = None, + group_id: Optional[int] = None, ): dt = get_datetime_now_with_timezone() + if not group_id: + state["group_id"] = session.id2 + if not type: await rank_cmd.finish(__plugin_meta__.usage) @@ -217,7 +198,6 @@ async def handle_rank( start: datetime = Arg(), stop: datetime = Arg(), ): - """生成词云""" messages = await get_message_records( session=session, id_type=SessionIdType.GROUP, @@ -258,12 +238,12 @@ async def handle_rank( ) string += str_example - bar = Bar() + bar = Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT)) bar.add_xaxis(nicknames) bar.add_yaxis("B话数量", [i[1] for i in rank]) # type: ignore bar.render(str(get_cache_file("nonebot_plugin_dialectlist","cache.html"))) with open(get_cache_file("nonebot_plugin_dialectlist","cache.html")) as f: a = f.read() - image = await html_to_pic(a) + image = await html_to_pic(a,device_scale_factor=3.2) await (saa.Text(string)+saa.Image(image)).finish(reply=True) diff --git a/nonebot_plugin_dialectlist/render.py b/nonebot_plugin_dialectlist/render.py new file mode 100644 index 0000000..3946f32 --- /dev/null +++ b/nonebot_plugin_dialectlist/render.py @@ -0,0 +1 @@ +# TODO 更好的图片渲染,支持自定义模板渲染。 \ No newline at end of file diff --git a/nonebot_plugin_dialectlist/storage.py b/nonebot_plugin_dialectlist/storage.py new file mode 100644 index 0000000..288968b --- /dev/null +++ b/nonebot_plugin_dialectlist/storage.py @@ -0,0 +1 @@ +# TODO 使用计数缓存进行数据库查询优化,避免一次性查询过多消息导致内存爆炸。 \ No newline at end of file diff --git a/nonebot_plugin_dialectlist/time.py b/nonebot_plugin_dialectlist/time.py new file mode 100644 index 0000000..86e4c40 --- /dev/null +++ b/nonebot_plugin_dialectlist/time.py @@ -0,0 +1 @@ +# TODO 时间处理模块,用于处理时间相关操作。 \ No newline at end of file diff --git a/nonebot_plugin_dialectlist/utils.py b/nonebot_plugin_dialectlist/utils.py index 347b1c0..2907243 100644 --- a/nonebot_plugin_dialectlist/utils.py +++ b/nonebot_plugin_dialectlist/utils.py @@ -1,4 +1,3 @@ -import contextlib from datetime import datetime, time, tzinfo from typing import Optional, Dict, List, Union from zoneinfo import ZoneInfo @@ -6,22 +5,42 @@ from sqlalchemy import or_, select from sqlalchemy.sql import ColumnElement from nonebot.log import logger -from nonebot.params import Depends +from nonebot.params import Arg, Depends +from nonebot.typing import T_State from nonebot.matcher import Matcher - -# from nonebot.permission import SUPERUSER +from nonebot.adapters import Message from nonebot_plugin_orm import get_session -from nonebot_plugin_saa import PlatformTarget, get_target from nonebot_plugin_session import Session, SessionLevel, extract_session from nonebot_plugin_session_orm import SessionModel from nonebot_plugin_userinfo import EventUserInfo, UserInfo from nonebot_plugin_apscheduler import scheduler from nonebot_plugin_chatrecorder import MessageRecord +from nonebot_plugin_alconna import AlconnaMatcher + from .config import plugin_config +def parse_datetime(key: str): + """解析数字,并将结果存入 state 中""" + + async def _key_parser( + matcher: AlconnaMatcher, + state: T_State, + input: Union[datetime, Message] = Arg(key), + ): + if isinstance(input, datetime): + return + + plaintext = input.extract_plain_text() + try: + state[key] = get_datetime_fromisoformat_with_timezone(plaintext) + except ValueError: + await matcher.reject_arg(key, "请输入正确的日期,不然我没法理解呢!") + + return _key_parser + def get_datetime_now_with_timezone() -> datetime: """获取当前时间,并包含时区信息""" diff --git a/pyproject.toml b/pyproject.toml index 8c8fdab..f8b2e0a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "nonebot_plugin_dialectlist" -version = "2.0.3" +version = "2.0.4" description = "Default template for PDM package" authors = [ {name = "Chen_Xu233", email = "woyerpa@outlook.com"}, @@ -37,3 +37,18 @@ line-length = 80 [tool.ruff.format] quote-style = "single" indent-style = "tab" + +[tool.pdm.scripts] + +build = 'pdm run setup.py sdist' +publish = 'pdm run python -m twine upload dist/*' + + +# 以下为智普 AI 生成,还不知道这玩意有啥用。 +# [tool.pdm.dev-dependencies] +# black = "^23.1.0" +# isort = "^5.10.1" +# pre-commit = "^2.20.0" + +# [tool.pdm.global-options] +# --no-pip-version-check = true \ No newline at end of file