mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-19 18:47:41 +08:00
fix: resolve documentation formatting issues
- Add 'config' to known zh/en doc structure differences - Remove trailing whitespace from docs/zh/faq.md - Remove trailing whitespace from docs/en/dev/plugin-platform-adapter.md - Ensure all README files end with newline
This commit is contained in:
@@ -23,7 +23,7 @@ class FakeClient():
|
||||
self.token = token
|
||||
self.username = username
|
||||
# ...
|
||||
|
||||
|
||||
async def start_polling(self):
|
||||
while True:
|
||||
await asyncio.sleep(5)
|
||||
@@ -35,10 +35,10 @@ class FakeClient():
|
||||
'message_id': 'asdhoashd',
|
||||
'group_id': 'group123',
|
||||
})
|
||||
|
||||
|
||||
async def send_text(self, to: str, message: str):
|
||||
print('发了消息:', to, message)
|
||||
|
||||
|
||||
async def send_image(self, to: str, image_path: str):
|
||||
print('发了消息:', to, image_path)
|
||||
```
|
||||
@@ -56,7 +56,7 @@ from astrbot.api.platform import register_platform_adapter
|
||||
from astrbot import logger
|
||||
from .client import FakeClient
|
||||
from .fake_platform_event import FakePlatformEvent
|
||||
|
||||
|
||||
# 注册平台适配器。第一个参数为平台名,第二个为描述。第三个为默认配置。
|
||||
@register_platform_adapter("fake", "fake 适配器", default_config_tmpl={
|
||||
"token": "your_token",
|
||||
@@ -68,11 +68,11 @@ class FakePlatformAdapter(Platform):
|
||||
super().__init__(event_queue)
|
||||
self.config = platform_config # 上面的默认配置,用户填写后会传到这里
|
||||
self.settings = platform_settings # platform_settings 平台设置。
|
||||
|
||||
|
||||
async def send_by_session(self, session: MessageSesion, message_chain: MessageChain):
|
||||
# 必须实现
|
||||
await super().send_by_session(session, message_chain)
|
||||
|
||||
|
||||
def meta(self) -> PlatformMetadata:
|
||||
# 必须实现,直接像下面一样返回即可。
|
||||
return PlatformMetadata(
|
||||
@@ -87,8 +87,8 @@ class FakePlatformAdapter(Platform):
|
||||
async def on_received(data):
|
||||
logger.info(data)
|
||||
abm = await self.convert_message(data=data) # 转换成 AstrBotMessage
|
||||
await self.handle_msg(abm)
|
||||
|
||||
await self.handle_msg(abm)
|
||||
|
||||
# 初始化 FakeClient
|
||||
self.client = FakeClient(self.config['token'], self.config['username'])
|
||||
self.client.on_message_received = on_received
|
||||
@@ -107,9 +107,9 @@ class FakePlatformAdapter(Platform):
|
||||
abm.self_id = data['bot_id']
|
||||
abm.session_id = data['userid'] # 会话 ID。重要!
|
||||
abm.message_id = data['message_id'] # 消息 ID。
|
||||
|
||||
|
||||
return abm
|
||||
|
||||
|
||||
async def handle_msg(self, message: AstrBotMessage):
|
||||
# 处理消息
|
||||
message_event = FakePlatformEvent(
|
||||
@@ -136,12 +136,12 @@ class FakePlatformEvent(AstrMessageEvent):
|
||||
def __init__(self, message_str: str, message_obj: AstrBotMessage, platform_meta: PlatformMetadata, session_id: str, client: FakeClient):
|
||||
super().__init__(message_str, message_obj, platform_meta, session_id)
|
||||
self.client = client
|
||||
|
||||
|
||||
async def send(self, message: MessageChain):
|
||||
for i in message.chain: # 遍历消息链
|
||||
if isinstance(i, Plain): # 如果是文字类型的
|
||||
await self.client.send_text(to=self.get_sender_id(), message=i.text)
|
||||
elif isinstance(i, Image): # 如果是图片类型的
|
||||
elif isinstance(i, Image): # 如果是图片类型的
|
||||
img_url = i.file
|
||||
img_path = ""
|
||||
# 下面的三个条件可以直接参考一下。
|
||||
@@ -153,7 +153,7 @@ class FakePlatformEvent(AstrMessageEvent):
|
||||
img_path = img_url
|
||||
|
||||
# 请善于 Debug!
|
||||
|
||||
|
||||
await self.client.send_image(to=self.get_sender_id(), image_path=img_path)
|
||||
|
||||
await super().send(message) # 需要最后加上这一段,执行父类的 send 方法。
|
||||
@@ -182,4 +182,4 @@ class MyPlugin(Star):
|
||||

|
||||
|
||||
|
||||
有任何疑问欢迎加群询问~
|
||||
有任何疑问欢迎加群询问~
|
||||
|
||||
@@ -103,8 +103,8 @@
|
||||
1. 如果你两个**全都**是使用 Docker 部署,请尝试在终端运行:
|
||||
|
||||
```bash
|
||||
sudo docker network create newnet # 创建新网络
|
||||
sudo docker network connect newnet astrbot
|
||||
sudo docker network create newnet # 创建新网络
|
||||
sudo docker network connect newnet astrbot
|
||||
sudo docker network connect newnet napcat # 让两个容器连到一起
|
||||
sudo docker restart astrbot
|
||||
sudo docker restart napcat # 重启容器
|
||||
|
||||
Reference in New Issue
Block a user