⬆️ update dependencies

This commit is contained in:
yanyongyu
2021-12-06 23:00:10 +08:00
parent d80c02ae46
commit 47d4909b31
68 changed files with 690 additions and 8964 deletions

View File

@ -1,4 +0,0 @@
ENVIRONMENT=dev
LOG_LEVEL=25
CUSTOM_CONFIG=common
# FASTAPI_RELOAD_DIRS=["test_plugins"]

View File

@ -1,24 +0,0 @@
DRIVER=nonebot.drivers.fastapi:FullDriver
HOST=0.0.0.0
PORT=2333
DEBUG=true
LOG_LEVEL=DEBUG
SUPERUSERS=["123123123"]
NICKNAME=["bot"]
COMMAND_START=["", "/", "#"]
COMMAND_SEP=["/", "."]
CUSTOM_CONFIG1=config in env
CUSTOM_CONFIG3=
# CQHTTP_WS_URLS={"123123123": "ws://127.0.0.1:6700/"}
MIRAI_AUTH_KEY=12345678
MIRAI_HOST=127.0.0.1
MIRAI_PORT=8080
APP_ID=111111111111
APP_SECRET=222222222222222222
VERIFICATION_TOKEN=3333333333333333333333333333

View File

@ -1,37 +0,0 @@
import os
import sys
sys.path.insert(0, os.path.abspath(".."))
import nonebot
from nonebot.log import logger, default_format
from nonebot.adapters.ding import Bot as DingBot
from nonebot.adapters.mirai import Bot as MiraiBot
from nonebot.adapters.feishu import Bot as FeishuBot
# test custom log
logger.add(
"error.log", rotation="00:00", diagnose=False, level="ERROR", format=default_format
)
nonebot.init(custom_config2="config on init")
app = nonebot.get_asgi()
driver = nonebot.get_driver()
driver.register_adapter("ding", DingBot)
driver.register_adapter("mirai", MiraiBot)
driver.register_adapter("feishu", FeishuBot)
# load builtin plugin
nonebot.load_builtin_plugins()
# load all plugins
nonebot.load_from_toml("plugins.toml")
# modify some config / config depends on loaded configs
config = driver.config
config.custom_config3 = config.custom_config1
config.custom_config4 = "New custom config"
if __name__ == "__main__":
nonebot.run(app="__mp_main__:app")
# nonebot.run()

View File

@ -1,3 +0,0 @@
[tool.nonebot]
plugins = ["nonebot_plugin_test"]
plugin_dirs = ["test_plugins"]

View File

@ -1,6 +0,0 @@
from nonebot.adapters import Bot
@Bot.on_calling_api
async def call(bot: Bot, api: str, data: dict):
print(type(bot), api, data)

View File

@ -1,32 +0,0 @@
import asyncio
from nonebot import on_message
from nonebot.typing import T_State
from nonebot.permission import USER
from nonebot.adapters import Bot, Event
a = on_message(priority=0, permission=USER("123123123"), temp=True)
@a.handle()
async def test_a(bot: Bot, event: Event, state: T_State):
print("======== A Received ========")
print("======== A Running Completed ========")
b = on_message(priority=0, permission=USER("123456789"), temp=True)
@b.handle()
async def test_b(bot: Bot, event: Event, state: T_State):
print("======== B Received ========")
await asyncio.sleep(10)
print("======== B Running Completed ========")
c = on_message(priority=0, permission=USER("1111111111"))
@c.handle()
async def test_c(bot: Bot, event: Event, state: T_State):
print("======== C Received ========")

View File

@ -1,28 +0,0 @@
from nonebot.log import logger
from nonebot.dependencies import Depends
from nonebot import on_command, on_message
test = on_command("123")
def depend(state: dict):
print("==== depends running =====")
return state
@test.got("a", prompt="a")
@test.got("b", prompt="b")
@test.receive()
@test.got("c", prompt="c")
async def _(x: dict = Depends(depend)):
logger.info(f"=======, {x}")
test_cache1 = on_message()
test_cache2 = on_message()
@test_cache1.handle()
@test_cache2.handle()
async def _(x: dict = Depends(depend)):
logger.info(f"======= test, {x}")

View File

@ -1,233 +0,0 @@
from nonebot.rule import to_me
from nonebot.plugin import on_command
from nonebot.adapters.ding import Bot as DingBot
from nonebot.adapters.ding import MessageEvent, MessageSegment
from nonebot.adapters.ding.event import GroupMessageEvent, PrivateMessageEvent
helper = on_command("ding_helper", to_me())
@helper.handle()
async def ding_helper(bot: DingBot, event: MessageEvent):
message = MessageSegment.markdown(
"Hello, This is NoneBot",
"""帮助信息如下:\n
[ding_helper](dtmd://dingtalkclient/sendMessage?content=ding_helper) 查看帮助\n
[markdown](dtmd://dingtalkclient/sendMessage?content=markdown) 发送 markdown\n
[actionCardSingleBtn](dtmd://dingtalkclient/sendMessage?content=actionCardSingleBtn)\n
[actionCard](dtmd://dingtalkclient/sendMessage?content=actionCard)\n
[feedCard](dtmd://dingtalkclient/sendMessage?content=feedCard)\n
[atme](dtmd://dingtalkclient/sendMessage?content=atme)\n
[image](dtmd://dingtalkclient/sendMessage?content=image)\n
[t](dtmd://dingtalkclient/sendMessage?content=t)\n
[code](dtmd://dingtalkclient/sendMessage?content=code) 发送代码\n
[test_message](dtmd://dingtalkclient/sendMessage?content=test_message)\n
[hello](dtmd://dingtalkclient/sendMessage?content=hello)\n
[webhook](dtmd://dingtalkclient/sendMessage?content=webhook)""",
)
await markdown.finish(message)
markdown = on_command("markdown", to_me())
@markdown.handle()
async def markdown_handler(bot: DingBot):
message = MessageSegment.markdown(
"Hello, This is NoneBot",
"#### NoneBot \n> Nonebot 是一款高性能的 Python 机器人框架\n> ![screenshot](https://v2.nonebot.dev/logo.png)\n> [GitHub 仓库地址](https://github.com/nonebot/nonebot2) \n",
)
await markdown.finish(message)
actionCardSingleBtn = on_command("actionCardSingleBtn", to_me())
@actionCardSingleBtn.handle()
async def actionCardSingleBtn_handler(bot: DingBot):
message = MessageSegment.actionCardSingleBtn(
title="打造一间咖啡厅",
text="![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png) \n #### 乔布斯 20 年前想打造的苹果咖啡厅 \n\n Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划",
singleTitle="阅读全文",
singleURL="https://www.dingtalk.com/",
)
await actionCardSingleBtn.finish(message)
actionCard = on_command("actionCard", to_me())
@actionCard.handle()
async def actionCard_handler(bot: DingBot):
message = MessageSegment.raw(
{
"msgtype": "actionCard",
"actionCard": {
"title": "乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身",
"text": "![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png) \n\n #### 乔布斯 20 年前想打造的苹果咖啡厅 \n\n Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划",
"hideAvatar": "0",
"btnOrientation": "0",
"btns": [
{"title": "内容不错", "actionURL": "https://www.dingtalk.com/"},
{"title": "不感兴趣", "actionURL": "https://www.dingtalk.com/"},
],
},
}
)
await actionCard.finish(message, at_sender=True)
feedCard = on_command("feedCard", to_me())
@feedCard.handle()
async def feedCard_handler(bot: DingBot):
message = MessageSegment.raw(
{
"msgtype": "feedCard",
"feedCard": {
"links": [
{
"title": "时代的火车向前开1",
"messageURL": "https://www.dingtalk.com/",
"picURL": "https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png",
},
{
"title": "时代的火车向前开2",
"messageURL": "https://www.dingtalk.com/",
"picURL": "https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png",
},
]
},
}
)
await feedCard.finish(message)
atme = on_command("atme", to_me())
@atme.handle()
async def atme_handler(bot: DingBot, event: MessageEvent):
message = f"@{event.senderId} manually at you" + MessageSegment.atDingtalkIds(
event.senderId
)
await atme.send("matcher send auto at you", at_sender=True)
await bot.send(event, "bot send auto at you", at_sender=True)
await atme.finish(message)
image = on_command("image", to_me())
@image.handle()
async def image_handler(bot: DingBot, event: MessageEvent):
message = MessageSegment.image(
"https://static-aliyun-doc.oss-accelerate.aliyuncs.com/assets/img/zh-CN/0634199951/p158167.png"
)
await image.finish(message)
textAdd = on_command("t", to_me())
@textAdd.handle()
async def textAdd_handler(bot: DingBot, event: MessageEvent):
message = "第一段消息\n" + MessageSegment.text("asdawefaefa\n")
await textAdd.send(message)
message = message + MessageSegment.text("第二段消息\n")
await textAdd.send(message)
message = (
message + MessageSegment.text("\n第三段消息\n") + "adfkasfkhsdkfahskdjasdashdkjasdf"
)
message = message + MessageSegment.extension(
{"text_type": "code_snippet", "code_language": "C#"}
)
await textAdd.send(message)
code = on_command("code", to_me())
@code.handle()
async def code_handler(bot: DingBot, event: MessageEvent):
raw = MessageSegment.code("Python", 'print("hello world")')
await code.send(raw)
message = MessageSegment.text(
"""using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}"""
)
message += MessageSegment.extension(
{"text_type": "code_snippet", "code_language": "C#"}
)
await code.finish(message)
test_message = on_command("test_message", to_me())
@test_message.handle()
async def test_message_handler1(bot: DingBot, event: PrivateMessageEvent):
await test_message.finish("PrivateMessageEvent")
@test_message.handle()
async def test_message_handler2(bot: DingBot, event: GroupMessageEvent):
await test_message.finish("GroupMessageEvent")
hello = on_command("hello", to_me())
@hello.handle()
async def hello_handler(bot: DingBot, event: MessageEvent):
message = MessageSegment.raw(
{
"msgtype": "text",
"text": {"content": "hello "},
}
)
message += MessageSegment.atDingtalkIds(event.senderId)
await hello.send(message)
message = MessageSegment.text(f"@{event.senderId},你好")
message += MessageSegment.atDingtalkIds(event.senderId)
await hello.finish(message)
hello = on_command("webhook", to_me())
@hello.handle()
async def webhook_handler(bot: DingBot, event: MessageEvent):
print(event)
message = MessageSegment.raw(
{
"msgtype": "text",
"text": {"content": "hello from webhook,一定要注意安全方式的鉴权哦,否则可能发送失败的"},
}
)
message += MessageSegment.atDingtalkIds(event.senderId)
await hello.send(
message,
webhook="https://oapi.dingtalk.com/robot/send?access_token=XXXXXXXXXXXXXX",
secret="SECXXXXXXXXXXXXXXXXXXXXXXXXX",
)
message = MessageSegment.text("TEST 123123 S")
await hello.send(
message,
webhook="https://oapi.dingtalk.com/robot/send?access_token=XXXXXXXXXXXXXX",
)

View File

@ -1,15 +0,0 @@
import nonebot
export = nonebot.export()
export.foo = "bar"
export["bar"] = "foo"
@export
def a():
pass
@export.sub
def b():
pass

View File

@ -1,12 +0,0 @@
from nonebot.typing import T_State
from nonebot.plugin import on_command
from nonebot.adapters.feishu import MessageEvent
from nonebot.adapters.feishu import Bot as FeishuBot
helper = on_command("say")
@helper.handle()
async def feishu_helper(bot: FeishuBot, event: MessageEvent, state: T_State):
message = event.get_message()
await helper.finish(message, at_sender=True)

View File

@ -1,4 +0,0 @@
import nonebot
from .test_export import export
print(export, nonebot.require("test_export"))

View File

@ -1,7 +0,0 @@
from nonebot.rule import to_me
from nonebot import CommandGroup, MatcherGroup
cmd = CommandGroup("test", rule=to_me())
match = MatcherGroup(priority=2)
from . import commands

View File

@ -1,9 +0,0 @@
from . import cmd
from nonebot.adapters import Bot, Event
test_1 = cmd.command("1", aliases={"test"})
@test_1.handle()
async def test1(bot: Bot, event: Event):
await test_1.finish(event.get_message())

View File

@ -1,20 +0,0 @@
from nonebot.rule import to_me
from nonebot.plugin import on_command, on_keyword
from nonebot.adapters.mirai import Bot, MessageEvent
message_test = on_keyword({"reply"}, rule=to_me())
@message_test.handle()
async def _message(bot: Bot, event: MessageEvent):
text = event.get_plaintext()
await bot.send(event, text, at_sender=True)
command_test = on_command("miecho")
@command_test.handle()
async def _echo(bot: Bot, event: MessageEvent):
text = event.get_plaintext()
await bot.send(event, text, at_sender=True)

View File

@ -1 +0,0 @@
from . import test_command

View File

@ -1,24 +0,0 @@
from nonebot.rule import to_me
from nonebot.typing import T_State
from nonebot.plugin import on_command
from nonebot.adapters import Bot, Event
test_command = on_command("帮助", to_me())
@test_command.handle()
async def test_handler1(bot: Bot, event: Event, state: T_State):
args = str(event.get_message()).strip()
print("[!] Command:", state["_prefix"], "Args:", args)
if args:
state["help"] = args
else:
await bot.send(message="命令:\n1. test1\n2. test2", event=event)
@test_command.got("help", prompt="你要帮助的命令是?")
async def test_handler2(bot: Bot, event: Event, state: T_State):
print("[!] Command 帮助:", state["help"])
if state["help"] not in ["test1", "test2"]:
await test_command.reject(f"{state['help']} 不支持,请重新输入!")
await bot.send(message=f"{state['help']} 帮助:\n...", event=event)

View File

@ -1,15 +0,0 @@
from nonebot.adapters import Event
from nonebot.typing import T_State
from nonebot.matcher import Matcher
from nonebot.message import run_preprocessor, event_preprocessor
@event_preprocessor
async def handle(event: Event, state: T_State):
state["preprocessed"] = True
print(type(event), event)
@run_preprocessor
async def run(matcher: Matcher):
print(matcher)

View File

@ -1,15 +0,0 @@
from nonebot.adapters import Bot
from nonebot.typing import T_State
from nonebot import on_shell_command
from nonebot.rule import ArgumentParser, to_me
parser = ArgumentParser()
parser.add_argument("-a", action="store_true")
shell = on_shell_command("ls", to_me(), parser=parser)
@shell.handle()
async def _(bot: Bot, state: T_State):
print(state["argv"])
print(state["args"])

View File

@ -1,25 +0,0 @@
from nonebot import on_command
from nonebot.rule import to_me
from nonebot.typing import T_State
from nonebot.adapters import Bot, Event
weather = on_command("天气", rule=to_me(), priority=1)
@weather.handle()
async def handle_first_receive(bot: Bot, event: Event, state: T_State):
args = str(event.get_message()).strip() # 首次发送命令时跟随的参数,例:/天气 上海则args为上海
print(f"==={args}===")
if args:
state["city"] = args # 如果用户发送了参数则直接赋值
@weather.got("city", prompt="你想查询哪个城市的天气呢?")
async def handle_city(bot: Bot, state: T_State):
city = state["city"]
if city not in ["上海", "北京"]:
await weather.reject("你想查询的城市暂不支持,请重新输入!")
# weather = await get_weather_from_xxx(city)
city_weather = "晴天"
# await bot.send(city_weather)
await weather.finish(city_weather)

View File

@ -1,14 +0,0 @@
import nonebot
from nonebot.adapters import Bot
driver = nonebot.get_driver()
@driver.on_bot_connect
async def connect(bot: Bot) -> None:
print("Connect", bot)
@driver.on_bot_disconnect
async def disconnect(bot: Bot) -> None:
print("Disconnect", bot)