-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
test-nbbridge.py
75 lines (55 loc) · 1.9 KB
/
test-nbbridge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from avilla.core import Avilla, Context, MessageReceived
from avilla.console.element import Markdown
from avilla.nonebridge.service import NoneBridgeService
from avilla.onebot.v11.protocol import OneBot11Protocol, OneBot11ReverseConfig
from graia.amnesia.builtins.asgi import UvicornASGIService
import nonebot
from avilla.core.elements import Face
avilla = Avilla()
config = OneBot11ReverseConfig("/ob", "dfawdfafergergeaar")
avilla.apply_protocols(OneBot11Protocol().configure(config))
avilla.launch_manager.add_component(UvicornASGIService("127.0.0.1", 9090))
avilla.launch_manager.add_component(NoneBridgeService(avilla))
nonebot.load_plugin("nonebot_world")
#@avilla.listen(MessageReceived)
async def on_message_received(ctx: Context, event: MessageReceived):
msg = str(event.message.content)
if msg == "/help":
await ctx.scene.send_message(
[Markdown("""\
## 菜单
- /help
- /echo
- /md
- /emoji
"""
)])
elif msg == "/md":
await ctx.scene.send_message(
[Markdown("""\
# Avilla-Console
`avilla` 的 `Console` 适配,使用 `Textual`
参考: [`nonebot-adapter-console`](https://github.com/nonebot/adapter-console)
## 样例
```python
from creart import create
from launart import Launart
from graia.broadcast import Broadcast
from avilla.core import Avilla, Context, MessageReceived
from avilla.console.protocol import ConsoleProtocol
broadcast = create(Broadcast)
launart = Launart()
avilla = Avilla(broadcast, launart, [ConsoleProtocol()])
@broadcast.receiver(MessageReceived)
async def on_message_received(ctx: Context):
await ctx.scene.send_message("Hello, Avilla!")
launart.launch_blocking(loop=broadcast.loop)
```
"""
)]
)
elif msg == "/emoji":
await ctx.scene.send_message([Face("art"), " | this is apple -> ", Face("apple")])
else:
await ctx.scene.send_message("Hello, Avilla!")
avilla.launch()