Skip to content

Commit

Permalink
[upd] 更新README
Browse files Browse the repository at this point in the history
  • Loading branch information
XeronOwO committed Oct 29, 2024
1 parent f3c5454 commit da5d04e
Showing 1 changed file with 80 additions and 2 deletions.
82 changes: 80 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,86 @@ Makabaka 已发布到 [NuGet](https://www.nuget.org/packages/Makabaka "前往NuG

</Details>

## 代码示例
[Program.cs](Makabaka.Test/Program.cs)
## 快速上手

### 配置文件

```json
{
"Logging": {
"LogLevel": {
"Default": "Information" // 日志等级,如果需要看到详细的收发数据包内容(例如提出 issue),请改成 Trace ,一般情况下用 Information 就行
}
},
"Bot": {
"ForwardWebSocket": { // 正向 WebSocket
"Enabled": true, // 是否启用。注意:一般情况下 ForwardWebSocket 与 ReverseWebSocket 同一时间只能存在一个
"Url": "ws://127.0.0.1:8081", // 远程 Lagrange.Onebot 的 ws 服务器地址
"AccessToken": "", // 鉴权密钥
"ReconnectInterval": 1000,
"ConnectionTimeout": 5000,
"ApiTimeout": 10000
},
"ReverseWebSocket": { // 反向 WebSocket
"Enabled": false, // 是否启用
"Url": "http://127.0.0.1:8082/onebot/v11/ws/", // 本地开启的 ws 服务器地址
"AccessToken": "", // 鉴权密钥
"RestartInterval": 1000
}
}
}
```

无注释版本见 [appsettings.json](Makabaka/appsettings.json)

### 代码

```csharp
using Makabaka;
using Makabaka.Events;
using Makabaka.Messages;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace MyApp
{
internal class Program
{
private static ILogger<Program> _logger = null!;

static void Main(string[] args)
{
var builder = new MakabakaAppBuilder(args);
var app = builder.Build();

_logger = app.Services.GetRequiredService<ILogger<Program>>();
app.BotContext.OnPrivateMessage += OnPrivateMessage;
app.BotContext.OnGroupMessage += OnGroupMessage;

app.Run();
}

private static Task OnPrivateMessage(object sender, PrivateMessageEventArgs e)
{
return OnMessage(e.Message, e);
}

private static Task OnGroupMessage(object sender, GroupMessageEventArgs e)
{
return OnMessage(e.Message, e);
}

private static async Task OnMessage(Message message, IMessageHandler reply)
{
if (message.ToString() == "文本测试")
{
await reply.ReplyAsync([new TextSegment("Hello, world!")]);
}
}
}
}
```

## 开源协议
[GPL-3.0 license](https://github.com/XeronOwO/Makabaka/blob/main/LICENSE.txt)
Expand Down

0 comments on commit da5d04e

Please sign in to comment.