-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c56f286
commit 661e0cb
Showing
11 changed files
with
282 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
include nonebot/** | ||
|
||
exclude test/* | ||
exclude example/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.venv | ||
.git | ||
temp | ||
data | ||
__pycache__ | ||
|
||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
### Python ### | ||
__pycache__/ | ||
|
||
# Distribution / packaging | ||
build/ | ||
dist/ | ||
|
||
# Environments | ||
.env | ||
.venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# ---- 构建阶段 ---- | ||
FROM docker.proxy.yangrucheng.top/python:3.12-alpine AS builder | ||
|
||
# 安装必要的构建工具和依赖 | ||
RUN sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.tuna.tsinghua.edu.cn/alpine#g' /etc/apk/repositories \ | ||
&& apk add --no-cache gcc musl-dev libffi-dev sqlite-dev tzdata | ||
|
||
# 安装依赖 | ||
COPY ./requirements.txt /app/requirements.txt | ||
RUN pip config set global.index-url https://pypi.proxy.yangrucheng.top/simple \ | ||
&& pip config set global.trusted-host pypi.proxy.yangrucheng.top \ | ||
&& pip install --upgrade pip --break-system-packages \ | ||
&& pip install -r /app/requirements.txt --break-system-packages | ||
|
||
# ---- 生产阶段 ---- | ||
FROM docker.proxy.yangrucheng.top/python:3.12-alpine | ||
|
||
# 安装基础依赖 | ||
RUN apk add --no-cache \ | ||
tzdata | ||
|
||
# 设置时区 | ||
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone | ||
|
||
# 设置工作目录和数据卷 | ||
WORKDIR /app | ||
|
||
# 从构建阶段复制已安装的 Python 包 | ||
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages | ||
|
||
# 复制应用代码 | ||
COPY . /app | ||
|
||
# 设置启动命令 | ||
CMD ["python3", "bot.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from nonebot.adapters.wxmp import Adapter as WxmpAdapter | ||
|
||
import nonebot | ||
|
||
# 初始化 NoneBot | ||
nonebot.init() | ||
|
||
# 注册适配器 | ||
driver = nonebot.get_driver() | ||
driver.register_adapter(WxmpAdapter) | ||
|
||
# 在这里加载插件 | ||
nonebot.load_plugins("plugins") # 本地插件 | ||
|
||
if __name__ == "__main__": | ||
nonebot.run( | ||
forwarded_allow_ips="*", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
from nonebot import on_message, on_command | ||
from nonebot.plugin import PluginMetadata | ||
from nonebot.params import CommandArg | ||
from nonebot.adapters import Message | ||
from nonebot.matcher import Matcher | ||
from pathlib import Path | ||
import asyncio | ||
import os | ||
|
||
from nonebot.adapters.wxmp import OfficalEvent, MessageSegment, Bot, File | ||
|
||
|
||
async def rule_test( | ||
event: OfficalEvent | ||
): | ||
""" 公众号事件 """ | ||
return True | ||
|
||
|
||
@on_command("文本", rule=rule_test).handle() | ||
async def handle( | ||
bot: Bot, | ||
mather: Matcher, | ||
event: OfficalEvent, | ||
): | ||
await bot.send( | ||
event=event, | ||
message="测试文本(被动回复消息)") | ||
|
||
await asyncio.sleep(10) | ||
await bot.send( | ||
event=event, | ||
message="测试文本(客服消息)") | ||
|
||
|
||
@on_command("图片", rule=rule_test).handle() | ||
async def handle( | ||
bot: Bot, | ||
mather: Matcher, | ||
event: OfficalEvent, | ||
): | ||
media_id = await bot.upload_temp_media(File(file_path=Path(os.getcwd()) / "res/demo.png", file_type="image")) | ||
await bot.send( | ||
event=event, | ||
message=MessageSegment.image( | ||
media_id=media_id, | ||
) | ||
) | ||
|
||
await asyncio.sleep(10) | ||
await bot.send( | ||
event=event, | ||
message=MessageSegment.image( | ||
media_id=media_id, | ||
) | ||
) | ||
|
||
|
||
@on_command("音频", rule=rule_test).handle() | ||
async def handle( | ||
bot: Bot, | ||
mather: Matcher, | ||
event: OfficalEvent, | ||
): | ||
media_id = await bot.upload_temp_media(File(file_path=Path(os.getcwd()) / "res/demo.mp3", file_type="voice")) | ||
await bot.send( | ||
event=event, | ||
message=MessageSegment.voice( | ||
media_id=media_id, | ||
) | ||
) | ||
|
||
await asyncio.sleep(10) | ||
await bot.send( | ||
event=event, | ||
message=MessageSegment.voice( | ||
media_id=media_id, | ||
) | ||
) | ||
|
||
|
||
@on_command("视频", rule=rule_test).handle() | ||
async def handle( | ||
bot: Bot, | ||
mather: Matcher, | ||
event: OfficalEvent, | ||
): | ||
media_id = await bot.upload_temp_media(File(file_path=Path(os.getcwd()) / "res/demo.mp4", file_type="video")) | ||
await bot.send( | ||
event=event, | ||
message=MessageSegment.video( | ||
media_id=media_id, | ||
title="示例视频[被动消息]", | ||
description="这是一个示例视频", | ||
) | ||
) | ||
|
||
await asyncio.sleep(10) | ||
await bot.send( | ||
event=event, | ||
message=MessageSegment.video( | ||
media_id=media_id, | ||
title="示例视频[客服消息]", | ||
description="这是一个示例视频", | ||
) | ||
) | ||
|
||
|
||
@on_command("小程序", rule=rule_test).handle() | ||
async def handle( | ||
bot: Bot, | ||
mather: Matcher, | ||
event: OfficalEvent, | ||
): | ||
media_id = await bot.upload_temp_media(File(file_path=Path(os.getcwd()) / "res/demo.png", file_type="image")) | ||
await bot.send( | ||
event=event, | ||
message=MessageSegment.miniprogrampage( | ||
title="示例小程序", | ||
appid="wx0ba7981861be3afc", | ||
page_path="pages/home/home", | ||
thumb_media_id=media_id, | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from nonebot import on_message, on_command | ||
from nonebot.plugin import PluginMetadata | ||
from nonebot.params import CommandArg | ||
from nonebot.adapters import Message | ||
from nonebot.matcher import Matcher | ||
from pathlib import Path | ||
import asyncio | ||
import os | ||
|
||
from nonebot.adapters.wxmp import MiniprogramEvent, MessageSegment, Bot, File | ||
|
||
|
||
async def rule_test( | ||
event: MiniprogramEvent | ||
): | ||
""" 小程序测试 """ | ||
return True | ||
|
||
|
||
@on_command("文本2", rule=rule_test, priority=0).handle() | ||
async def handle( | ||
bot: Bot, | ||
mather: Matcher, | ||
event: MiniprogramEvent, | ||
): | ||
await bot.send( | ||
event=event, | ||
message=MessageSegment.text("Hello, world!"), | ||
) | ||
|
||
|
||
@on_command("链接2", rule=rule_test, priority=0).handle() | ||
async def handle( | ||
bot: Bot, | ||
mather: Matcher, | ||
event: MiniprogramEvent, | ||
): | ||
await bot.send( | ||
event=event, | ||
message=MessageSegment.link( | ||
title="Hello, world!", | ||
description="This is a test message.", | ||
url="https://github.com/YangRucheng/nonebot-adapter-wxmp", | ||
thumb_url="https://nonebot.dev/logo.png", | ||
) | ||
) | ||
|
||
|
||
@on_command("小程序2", rule=rule_test, priority=0).handle() | ||
async def handle_test( | ||
bot: Bot, | ||
mather: Matcher, | ||
event: MiniprogramEvent, | ||
): | ||
""" 测试发送消息 """ | ||
await bot.send( | ||
event=event, | ||
message=MessageSegment.miniprogrampage( | ||
title="Hello, world!", | ||
page_path="pages/home/home", | ||
thumb_media_path=Path("/app/res/demo.png"), | ||
) | ||
) | ||
|
||
|
||
@on_command("图片2", rule=rule_test, priority=0).handle() | ||
async def handle_test( | ||
bot: Bot, | ||
mather: Matcher, | ||
event: MiniprogramEvent, | ||
): | ||
""" 测试发送消息 """ | ||
await bot.send( | ||
event=event, | ||
message=MessageSegment.image( | ||
file_path=Path("/app/res/demo.png"), | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
httpx[http2] | ||
websockets | ||
xmltodict | ||
fastapi | ||
|
||
nonebot2[httpx,websockets,fastapi] | ||
|
||
nonebot-adapter-wxmp |
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.