Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a3dd2dbbda | |||
| 8d4f74dafe | |||
| 7c1bac64c9 | |||
| e09fa13d0f |
1
bot.py
1
bot.py
@ -42,6 +42,7 @@ def main():
|
||||
|
||||
# nonebot.load_builtin_plugin("echo")
|
||||
nonebot.load_plugins("konabot/plugins")
|
||||
nonebot.load_plugin("nonebot_plugin_analysis_bilibili")
|
||||
|
||||
nonebot.run()
|
||||
|
||||
|
||||
25
konabot/plugins/bilibili_fetch_fix.py
Normal file
25
konabot/plugins/bilibili_fetch_fix.py
Normal file
@ -0,0 +1,25 @@
|
||||
import re
|
||||
from loguru import logger
|
||||
from nonebot import on_message
|
||||
from nonebot_plugin_alconna import Reference, Reply, UniMsg
|
||||
|
||||
from nonebot.adapters import Event
|
||||
|
||||
|
||||
matcher_fix = on_message()
|
||||
|
||||
pattern = (
|
||||
r"^(?:(?:av|cv)\d+|BV[a-zA-Z0-9]{10})|"
|
||||
r"(?:b23\.tv|bili(?:22|23|33|2233)\.cn|\.bilibili\.com|QQ小程序(?:]|]|\])哔哩哔哩).{0,500}"
|
||||
)
|
||||
|
||||
|
||||
@matcher_fix.handle()
|
||||
async def _(msg: UniMsg, event: Event):
|
||||
to_search = msg.exclude(Reply, Reference).dump(json=True)
|
||||
if not re.search(pattern, to_search):
|
||||
return
|
||||
logger.info("检测到有 Bilibili 相关的消息,直接进行一个调用")
|
||||
_module = __import__("nonebot_plugin_analysis_bilibili")
|
||||
await _module.handle_analysis(event)
|
||||
|
||||
@ -115,7 +115,7 @@ def create_notify_task(notify: Notify, fail2remove: bool = True):
|
||||
else:
|
||||
logger.warning(
|
||||
f"期望在 {notify.notify_time} 在平台 {notify.platform} {notify.target_env}"
|
||||
f"{notify.target} 的代办通知 {notify.notify_msg} 已经超时,将会直接通知!"
|
||||
f" {notify.target} 的代办通知 {notify.notify_msg} 已经超时,将会直接通知!"
|
||||
)
|
||||
res = await notify_now(notify)
|
||||
if fail2remove or res:
|
||||
@ -148,6 +148,7 @@ async def _(msg: UniMsg, mEvt: Event):
|
||||
# target_time = get_target_time(notify_time)
|
||||
try:
|
||||
target_time = ptimeparse.parse(notify_time)
|
||||
logger.info(f"从 {notify_time} 解析出了时间:{target_time}")
|
||||
except Exception:
|
||||
logger.info(f"无法从 {notify_time} 中解析出时间")
|
||||
return
|
||||
@ -159,7 +160,7 @@ async def _(msg: UniMsg, mEvt: Event):
|
||||
|
||||
await DATA_FILE_LOCK.acquire()
|
||||
cfg = load_notify_config()
|
||||
|
||||
|
||||
if isinstance(mEvt, ConsoleMessageEvent):
|
||||
platform = "console"
|
||||
target = mEvt.get_user_id()
|
||||
@ -186,7 +187,7 @@ async def _(msg: UniMsg, mEvt: Event):
|
||||
notify_time=target_time,
|
||||
notify_msg=notify_text,
|
||||
)
|
||||
await create_notify_task(notify)
|
||||
create_notify_task(notify)
|
||||
|
||||
cfg.notifies.append(notify)
|
||||
save_notify_config(cfg)
|
||||
@ -194,6 +195,7 @@ async def _(msg: UniMsg, mEvt: Event):
|
||||
|
||||
await evt.send(await UniMessage().at(mEvt.get_user_id()).text(
|
||||
f" 了解啦!将会在 {notify.notify_time} 提醒你哦~").export())
|
||||
logger.info(f"创建了一条于 {notify.notify_time} 的代办提醒")
|
||||
|
||||
|
||||
driver = nonebot.get_driver()
|
||||
@ -209,20 +211,27 @@ async def _():
|
||||
return
|
||||
|
||||
NOTIFIED_FLAG["task_added"] = True
|
||||
logger.info("第一次探测到 Bot 连接,等待 10 秒后开始通知")
|
||||
|
||||
await asyncio.sleep(10)
|
||||
DELTA = 2
|
||||
logger.info(f"第一次探测到 Bot 连接,等待 {DELTA} 秒后开始通知")
|
||||
await asyncio.sleep(DELTA)
|
||||
|
||||
await DATA_FILE_LOCK.acquire()
|
||||
|
||||
tasks: set[asyncio.Task[Any]] = set()
|
||||
cfg = load_notify_config()
|
||||
if cfg.version == 1:
|
||||
logger.info("将配置文件的版本升级为 2")
|
||||
cfg.version = 2
|
||||
else:
|
||||
for notify in cfg.notifies:
|
||||
counter = 0
|
||||
for notify in [*cfg.notifies]:
|
||||
task = create_notify_task(notify, fail2remove=False)
|
||||
tasks.add(task)
|
||||
task.add_done_callback(lambda self: tasks.remove(self))
|
||||
counter += 1
|
||||
logger.info(f"成功创建了 {counter} 条代办事项")
|
||||
save_notify_config(cfg)
|
||||
DATA_FILE_LOCK.release()
|
||||
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
67
poetry.lock
generated
67
poetry.lock
generated
@ -748,6 +748,18 @@ all = ["email-validator (>=2.0.0)", "fastapi-cli[standard] (>=0.0.8)", "httpx (>
|
||||
standard = ["email-validator (>=2.0.0)", "fastapi-cli[standard] (>=0.0.8)", "httpx (>=0.23.0,<1.0.0)", "jinja2 (>=3.1.5)", "python-multipart (>=0.0.18)", "uvicorn[standard] (>=0.12.0)"]
|
||||
standard-no-fastapi-cloud-cli = ["email-validator (>=2.0.0)", "fastapi-cli[standard-no-fastapi-cloud-cli] (>=0.0.8)", "httpx (>=0.23.0,<1.0.0)", "jinja2 (>=3.1.5)", "python-multipart (>=0.0.18)", "uvicorn[standard] (>=0.12.0)"]
|
||||
|
||||
[[package]]
|
||||
name = "filetype"
|
||||
version = "1.2.0"
|
||||
description = "Infer file type and MIME type of any file/buffer. No external dependencies."
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "filetype-1.2.0-py2.py3-none-any.whl", hash = "sha256:7ce71b6880181241cf7ac8697a2f1eb6a8bd9b429f7ad6d27b8db9ba5f1c2d25"},
|
||||
{file = "filetype-1.2.0.tar.gz", hash = "sha256:66b56cd6474bf41d8c54660347d37afcc3f7d1970648de365c102ef77548aadb"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "frozenlist"
|
||||
version = "1.7.0"
|
||||
@ -1630,6 +1642,23 @@ nonebot-plugin-waiter = ">=0.6.0"
|
||||
nonebot2 = ">=2.3.0"
|
||||
tarina = ">=0.6.8,<0.7"
|
||||
|
||||
[[package]]
|
||||
name = "nonebot-plugin-analysis-bilibili"
|
||||
version = "2.8.1"
|
||||
description = "nonebot2解析bilibili插件"
|
||||
optional = false
|
||||
python-versions = "<4.0,>=3.8"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "nonebot_plugin_analysis_bilibili-2.8.1-py3-none-any.whl", hash = "sha256:f882a0428ca87fc77a56fae6013607f6b286d8ae0ed46a1a87b4a1a6d3f4d011"},
|
||||
{file = "nonebot_plugin_analysis_bilibili-2.8.1.tar.gz", hash = "sha256:17c2c15a1783a2e1075638861384bd55b3fef09c0c7eb94857f811f60dbb446a"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
aiohttp = ">=3.7,<4.0"
|
||||
nonebot-plugin-send-anything-anywhere = ">=0,<1"
|
||||
nonebot2 = ">=2.1.1,<3.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "nonebot-plugin-apscheduler"
|
||||
version = "0.5.0"
|
||||
@ -1647,6 +1676,25 @@ apscheduler = ">=3.7.0,<4.0.0"
|
||||
nonebot2 = ">=2.2.0,<3.0.0"
|
||||
pydantic = ">=1.10.0,<2.5.0 || >2.5.0,<2.5.1 || >2.5.1,<3.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "nonebot-plugin-send-anything-anywhere"
|
||||
version = "0.7.1"
|
||||
description = "An adaptor for nonebot2 adaptors"
|
||||
optional = false
|
||||
python-versions = "<4.0,>=3.9"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "nonebot_plugin_send_anything_anywhere-0.7.1-py3-none-any.whl", hash = "sha256:b52044272be9a7bc77bd7a53ef700481c071fd4e889ae21a0411d0df22d13c16"},
|
||||
{file = "nonebot_plugin_send_anything_anywhere-0.7.1.tar.gz", hash = "sha256:ec9c7ba59c824238b812950146a894acc88ca8da98f500de15217feebcd5e868"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
anyio = ">=3.3.0,<5.0.0"
|
||||
filetype = ">=1.2.0,<2.0.0"
|
||||
nonebot2 = ">=2.3.0,<3.0.0"
|
||||
pydantic = ">=1.10.0,<2.5.0 || >2.5.0,<2.5.1 || >2.5.1,<3.0.0"
|
||||
strenum = ">=0.4.8,<0.5.0"
|
||||
|
||||
[[package]]
|
||||
name = "nonebot-plugin-waiter"
|
||||
version = "0.8.1"
|
||||
@ -2620,6 +2668,23 @@ typing-extensions = {version = ">=4.10.0", markers = "python_version < \"3.13\""
|
||||
[package.extras]
|
||||
full = ["httpx (>=0.27.0,<0.29.0)", "itsdangerous", "jinja2", "python-multipart (>=0.0.18)", "pyyaml"]
|
||||
|
||||
[[package]]
|
||||
name = "strenum"
|
||||
version = "0.4.15"
|
||||
description = "An Enum that inherits from str."
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "StrEnum-0.4.15-py3-none-any.whl", hash = "sha256:a30cda4af7cc6b5bf52c8055bc4bf4b2b6b14a93b574626da33df53cf7740659"},
|
||||
{file = "StrEnum-0.4.15.tar.gz", hash = "sha256:878fb5ab705442070e4dd1929bb5e2249511c0bcf2b0eeacf3bcd80875c82eff"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
docs = ["myst-parser[linkify]", "sphinx", "sphinx-rtd-theme"]
|
||||
release = ["twine"]
|
||||
test = ["pylint", "pytest", "pytest-black", "pytest-cov", "pytest-pylint"]
|
||||
|
||||
[[package]]
|
||||
name = "tarina"
|
||||
version = "0.6.8"
|
||||
@ -3260,4 +3325,4 @@ type = ["pytest-mypy"]
|
||||
[metadata]
|
||||
lock-version = "2.1"
|
||||
python-versions = ">=3.12,<4.0"
|
||||
content-hash = "0c7709438b8eb3d468b775417b8ef642cd7a8c1031805fdc71fec32c48346e54"
|
||||
content-hash = "013942994a91012f285305194d73b6609fe71bbd214a63dce443877853dcd764"
|
||||
|
||||
@ -24,6 +24,7 @@ dependencies = [
|
||||
"returns (>=0.26.0,<0.27.0)",
|
||||
"ptimeparse (>=0.1.1,<0.2.0)",
|
||||
"skia-python (>=138.0,<139.0)",
|
||||
"nonebot-plugin-analysis-bilibili (>=2.8.1,<3.0.0)",
|
||||
]
|
||||
|
||||
[build-system]
|
||||
|
||||
Reference in New Issue
Block a user