Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] write qrcode to local file #718

Merged
merged 5 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lagrange.OneBot/Core/Login/LoginService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public async Task StartAsync(CancellationToken token)
{
(string Url, byte[] QrCode)? qrcode = await _lagrange.FetchQrCode().WaitAsync(token);
if (!qrcode.HasValue) return false;

await File.WriteAllBytesAsync($"qr-{configuration["Account:Uin"]}.png", qrcode.Value.QrCode, token);
QrCodeHelper.Output(qrcode.Value.Url, _isCompatibility);

return await (Task<bool>)_lagrange.LoginByQrCode(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static HostApplicationBuilder ConfigureOneBot(this HostApplicationBuilder
LiteDbUtility.IMessageEntityDeserialize
);

string path = configuration["ConfigPath:Database"] ?? "lagrange.db";
string path = configuration["ConfigPath:Database"] ?? $"lagrange-{configuration["Account:Uin"]}.db";

bool isFirstCreate = false;
if (!File.Exists(path)) isFirstCreate = true;
Expand Down
1 change: 0 additions & 1 deletion Lagrange.OneBot/Resources/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"MusicSignServerUrl": "",
"Account": {
"Uin": 0,
"Password": "",
"Protocol": "Linux",
"AutoReconnect": true,
"GetOptimumServer": true
Expand Down
149 changes: 74 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,20 @@ Thanks for 外国热心网友 for Provision of Azure Servlet

| Protocol | Support | Login | Support | Messages | Support | Operations | Support | Events | Support |
| -------- | :-----: | ------------------------- | :-----: | :-------- | :-----: | :---------------- | :-----: | :------------------ | :-----: |
| Windows | 🟢 | QrCode | 🟢 | Images | 🟢 | Poke | 🟢 | Captcha | 🟢 |
| macOS | 🟢 | Password | 🟢 | Text / At | 🟢 | Recall | 🟢 | BotOnline | 🟢 |
| Windows | 🟢 | QrCode | 🟢 | Images | 🟢 | Poke | 🟢 | Captcha | 🟢 |
| macOS | 🟢 | Password | 🔴 | Text / At | 🟢 | Recall | 🟢 | BotOnline | 🟢 |
| Linux | 🟢 | EasyLogin | 🟢 | Records | 🟢 | Leave Group | 🟢 | BotOffline | 🟢 |
| | | UnusalDevice<br/>Password | 🔴 | QFace | 🟢 | Set Special Title | 🟢 | Message | 🟢 |
| | | UnusalDevice<br/>Easy | 🟢 | Json | 🟢 | Kick Member | 🟢 | Poke | 🟢 |
| | | NewDeviceVerify | 🟢 | Xml | 🟢 | Mute Member | 🟢 | MessageRecall | 🟢 |
| | | | | Forward | 🟢 | Set Admin | 🟢 | GroupMemberDecrease | 🟢 |
| | | | | Video | 🟢 | Friend Request | 🟢 | GroupMemberIncrease | 🟢 |
| | | | | Reply | 🟢 | Group Request | 🟢 | GroupPromoteAdmin | 🟢 |
| | | | | File | 🟢 | ~~Voice Call~~ | 🔴 | GroupInvite | 🟢 |
| | | | | Poke | 🟢 | Client Key | 🟢 | GroupRequestJoin | 🟢 |
| | | | | LightApp | 🟢 | Cookies | 🟢 | FriendRequest | 🟢 |
| | | | | | | Send Message | 🟢 | ~~FriendTyping~~ | 🔴 |
| | | | | | | | | ~~FriendVoiceCall~~ | 🔴 |
| | | UnusalDevice<br/>Password | 🔴 | QFace | 🟢 | Set Special Title | 🟢 | Message | 🟢 |
| | | UnusalDevice<br/>Easy | 🟢 | Json | 🟢 | Kick Member | 🟢 | Poke | 🟢 |
| | | NewDeviceVerify | 🔴 | Xml | 🟢 | Mute Member | 🟢 | MessageRecall | 🟢 |
| | | | | Forward | 🟢 | Set Admin | 🟢 | GroupMemberDecrease | 🟢 |
| | | | | Video | 🟢 | Friend Request | 🟢 | GroupMemberIncrease | 🟢 |
| | | | | Reply | 🟢 | Group Request | 🟢 | GroupPromoteAdmin | 🟢 |
| | | | | File | 🟢 | ~~Voice Call~~ | 🔴 | GroupInvite | 🟢 |
| | | | | Poke | 🟢 | Client Key | 🟢 | GroupRequestJoin | 🟢 |
| | | | | LightApp | 🟢 | Cookies | 🟢 | FriendRequest | 🟢 |
| | | | | | | Send Message | 🟢 | ~~FriendTyping~~ | 🔴 |
| | | | | | | | | ~~FriendVoiceCall~~ | 🔴 |

## Lagrange.OneBot

Expand Down Expand Up @@ -144,7 +144,7 @@ Thanks for 外国热心网友 for Provision of Azure Servlet
<Summary>API</Summary>

| API | Support |
|--------------------------------| :-----: |
| ------------------------------ | :-----: |
| [/send_private_msg] | 🟢 |
| [/send_group_msg] | 🟢 |
| [/send_msg] | 🟢 |
Expand Down Expand Up @@ -291,86 +291,85 @@ Thanks for 外国热心网友 for Provision of Azure Servlet

```json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"SignServerUrl": "",
"Account": {
"Uin": 0,
"Password": "",
"Protocol": "Linux",
"AutoReconnect": true,
"GetOptimumServer": true
},
"Message": {
"IgnoreSelf": true,
"StringPost": false
},
"QrCode": {
"ConsoleCompatibilityMode": false
},
"Implementations": [
{
"Type": "ReverseWebSocket",
"Host": "127.0.0.1",
"Port": 8080,
"Suffix": "/onebot/v11/ws",
"ReconnectInterval": 5000,
"HeartBeatInterval": 5000,
"HeartBeatEnable": true,
"AccessToken": ""
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
{
"Type": "ForwardWebSocket",
"Host": "*",
"Port": 8081,
"HeartBeatInterval": 5000,
"HeartBeatEnable": true,
"AccessToken": ""
"SignServerUrl": "",
"Account": {
"Uin": 0, // Only used to create lagrange-{uin}.db and qr-{uin}.png
"Protocol": "Linux",
"AutoReconnect": true,
"GetOptimumServer": true
},
{
"Type": "HttpPost",
"Host": "127.0.0.1",
"Port": 8082,
"Suffix": "/",
"HeartBeatInterval": 5000,
"HeartBeatEnable": true,
"AccessToken": ""
"Message": {
"IgnoreSelf": true,
"StringPost": false
},
{
"Type": "Http",
"Host": "*",
"Port": 8083,
"AccessToken": ""
}
]
"QrCode": {
"ConsoleCompatibilityMode": false
},
"Implementations": [
{
"Type": "ReverseWebSocket",
"Host": "127.0.0.1",
"Port": 8080,
"Suffix": "/onebot/v11/ws",
"ReconnectInterval": 5000,
"HeartBeatInterval": 5000,
"HeartBeatEnable": true,
"AccessToken": ""
},
{
"Type": "ForwardWebSocket",
"Host": "*",
"Port": 8081,
"HeartBeatInterval": 5000,
"HeartBeatEnable": true,
"AccessToken": ""
},
{
"Type": "HttpPost",
"Host": "127.0.0.1",
"Port": 8082,
"Suffix": "/",
"HeartBeatInterval": 5000,
"HeartBeatEnable": true,
"AccessToken": ""
},
{
"Type": "Http",
"Host": "*",
"Port": 8083,
"AccessToken": ""
}
]
}
```

> [!WARNING]
> Currently, `ForwardWebSocket` and `Http` are implemented based on `HttpListener`, which has the following problems:
>
>
> 1. On Linux, the `Host` header of an Http request must match the value of `Prefix` unless it is `+` or `*`, so configure the `Host` of `ForwardWebSocket` and `Http` to be the domain name or IP you are using to access it.
>
>
> 2. On Windows, the `HttpListener` is based on the `http.sys` implementation, so you need to register `urlacl` before using it. see [netsh](https://learn.microsoft.com/en-us/windows-server/networking/technologies/netsh/netsh-http). You can also start `Lagrange.OneBot` using the administrator, at which point `HttpListener` will automatically register the required `urlacl`.

## NOTICE BEFORE LOGIN

- The NewDeviceLogin feature has not been implemented yet. It is recommended to use QRCode login for now.
- Currently, only the signature server implementation for Linux protocol is available. It is recommended to use the Linux protocol.
- The NewDeviceLogin feature has not been implemented yet. It is recommended to use QRCode login for now.
- Currently, only the signature server implementation for Linux protocol is available. It is recommended to use the Linux protocol.

## Known Problem

- ~~[ ] Signature Service is currently not established, so the login tend to be failed and return code may be 45, you can establish your own sign service by rewriting the `Signature` static class.~~
- ~~[ ] Signature Service is currently not established, so the login tend to be failed and return code may be 45, you can establish your own sign service by rewriting the `Signature` static class.~~

~~Thanks KonataDev/TheSnowfield for Provision of Signature API~~

~~Signature API is now not provided, you may need to find it somewhere and inherit `SignProvider` class for `CustomSignProvider` in `BotConfig`~~

- ~~Built-in SignServer is now provided, Enjoy!~~
- ~~Built-in SignServer is now provided, Enjoy!~~

- Signature of Windows and macOS is missing, you need to figure out by your self
- Signature of Windows and macOS is missing, you need to figure out by your self
7 changes: 3 additions & 4 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ Please use Lagrange.Core responsibly and in accordance with the law.
| 协议 | 支持情况 | 登录类型 | 支持情况 | 消息段 | 支持情况 | 操作 | 支持情况 | 事件 | 支持情况 |
| ------- | :------: | ----------------- | :------: | :--------------- | :------: | :--------------- | :------: | :--------------- | :------: |
| Windows | 🟢 | 扫码登录 | 🟢 | 图片 | 🟢 | 戳一戳 | 🟢 | 验证码 | 🟢 |
| macOS | 🟢 | 密码登录 | 🟢 | 文本 / At | 🟢 | 撤回消息 | 🟢 | 机器人在线 | 🟢 |
| macOS | 🟢 | 密码登录 | 🔴 | 文本 / At | 🟢 | 撤回消息 | 🟢 | 机器人在线 | 🟢 |
| Linux | 🟢 | 快速登录 | 🟢 | 语音 | 🟢 | 退出群组 | 🟢 | 机器人离线 | 🟢 |
| | | 异常设备<br/>密码 | 🔴 | QQ 黄脸表情 | 🟢 | 特殊头衔 | 🟢 | 消息事件 | 🟢 |
| | | 异常设备<br/>快速 | 🟢 | Json | 🟢 | 移除群成员 | 🟢 | 戳一戳事件 | 🟢 |
| | | 新设备验证 | 🟢 | Xml | 🟢 | 禁言群成员 | 🟢 | 消息撤回事件 | 🟢 |
| | | 新设备验证 | 🔴 | Xml | 🟢 | 禁言群成员 | 🟢 | 消息撤回事件 | 🟢 |
| | | | | 合并转发 | 🟢 | 设置管理员 | 🟢 | 群成员减少 | 🟢 |
| | | | | 视频 | 🟢 | 处理添加好友请求 | 🟢 | 群成员增加 | 🟢 |
| | | | | 回复 | 🟢 | 处理加群请求 | 🟢 | 群管理员变动 | 🟢 |
Expand Down Expand Up @@ -296,8 +296,7 @@ Please use Lagrange.Core responsibly and in accordance with the law.
},
"SignServerUrl": "",
"Account": {
"Uin": 0,
"Password": "",
"Uin": 0, // 仅用于创建 lagrange-{uin}.db 和 qr-{uin}.png
"Protocol": "Linux",
"AutoReconnect": true,
"GetOptimumServer": true
Expand Down
Loading