diff --git a/.gitignore b/.gitignore index ed5f2c14d..aac031c3e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ obj/ /packages/ riderModule.iml /_ReSharper.Caches/ -Lagrange.Core/Utility/Crypto/Provider/Dandelion/*.cs \ No newline at end of file +Lagrange.Core/Utility/Crypto/Provider/Dandelion/*.cs +.vscode/ diff --git a/Lagrange.OneBot/Core/Entity/Action/OneBotResult.cs b/Lagrange.OneBot/Core/Entity/Action/OneBotResult.cs index a028a778b..8755fd2dc 100644 --- a/Lagrange.OneBot/Core/Entity/Action/OneBotResult.cs +++ b/Lagrange.OneBot/Core/Entity/Action/OneBotResult.cs @@ -10,6 +10,8 @@ public class OneBotResult(object? data, int retCode, string status, string echo) [JsonPropertyName("retcode")] public int RetCode { get; set; } = retCode; [JsonPropertyName("data")] public object? Data { get; set; } = data; - + [JsonPropertyName("echo")] public string Echo { get; set; } = echo; -} \ No newline at end of file + + [JsonIgnore] public string? Identifier { get; internal set; } +} diff --git a/Lagrange.OneBot/Core/Network/ForwardWSService.cs b/Lagrange.OneBot/Core/Network/ForwardWSService.cs new file mode 100644 index 000000000..d2fcf04bf --- /dev/null +++ b/Lagrange.OneBot/Core/Network/ForwardWSService.cs @@ -0,0 +1,116 @@ +using System.Text; +using System.Text.Json; +using Lagrange.OneBot.Core.Entity.Action; +using Lagrange.OneBot.Core.Entity.Meta; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using PHS.Networking.Enums; +using WebsocketsSimple.Server; +using WebsocketsSimple.Server.Events.Args; +using WebsocketsSimple.Server.Models; +using Timer = System.Threading.Timer; + +namespace Lagrange.OneBot.Core.Network; + +public sealed class ForwardWSService : ILagrangeWebService +{ + public event EventHandler OnMessageReceived = delegate { }; + + private readonly WebsocketServer _server; + + private readonly IConfiguration _config; + + private readonly ILogger _logger; + + private readonly Timer _timer; + + private readonly bool _shouldAuthenticate; + + private static readonly Encoding _utf8 = new UTF8Encoding(false); + + public ForwardWSService(IConfiguration config, ILogger logger) + { + _config = config; + _logger = logger; + + var ws = _config.GetSection("Implementation").GetSection("ForwardWebSocket"); + + _timer = new Timer(OnHeartbeat, null, int.MaxValue, ws.GetValue("HeartBeatInterval")); + _shouldAuthenticate = !string.IsNullOrEmpty(_config["AccessToken"]); + + _server = new WebsocketServer(new ParamsWSServer(ws.GetValue("Port"))); + _server.MessageEvent += OnMessage; + + if (_shouldAuthenticate) + _server.ConnectionEvent += OnConnection; + } + + public async Task StartAsync(CancellationToken cancellationToken) + { + await _server.StartAsync(cancellationToken); + var lifecycle = new OneBotLifecycle(_config.GetValue("Account:Uin"), "connect"); + await SendJsonAsync(lifecycle, cancellationToken); + } + + public Task StopAsync(CancellationToken cancellationToken) + { + _timer.Dispose(); + _server.Dispose(); + + return Task.CompletedTask; + } + + public async Task SendJsonAsync(T json, CancellationToken cancellationToken = default) + { + var payload = JsonSerializer.Serialize(json); + + if (json is OneBotResult oneBotResult) + { + var connection = _server.Connections.FirstOrDefault( + (c) => c.ConnectionId == oneBotResult.Identifier + ); + + if (connection is not null) + await _server.SendToConnectionAsync(payload, connection); + } + else + await _server.BroadcastToAllConnectionsAsync(payload, cancellationToken); + } + + private void OnHeartbeat(object? sender) + { + var status = new OneBotStatus(true, true); + var heartBeat = new OneBotHeartBeat( + _config.GetValue("Account:Uin"), + _config.GetValue("Implementation:ForwardWebSocket:HeartBeatInterval"), + status + ); + + SendJsonAsync(heartBeat).GetAwaiter().GetResult(); + } + + private void OnConnection(object sender, WSConnectionServerEventArgs e) + { + if ( + _shouldAuthenticate + && e.ConnectionEventType == ConnectionEventType.Connected + && ( + e.RequestHeaders is null + || !e.RequestHeaders.TryGetValue("Authorization", out string? authorization) + || authorization != $"Bearer {_config["AccessToken"]}" + ) + ) + { + e.Connection.Websocket.Abort(); + } + } + + private void OnMessage(object sender, WSMessageServerEventArgs e) + { + if (e.MessageEventType == MessageEventType.Receive) + { + string text = _utf8.GetString(e.Bytes); + OnMessageReceived.Invoke(this, new(e.Message ?? "", e.Connection.ConnectionId)); + } + } +} diff --git a/Lagrange.OneBot/Core/Network/HttpPostService.cs b/Lagrange.OneBot/Core/Network/HttpPostService.cs index 4cf536531..a055d224e 100644 --- a/Lagrange.OneBot/Core/Network/HttpPostService.cs +++ b/Lagrange.OneBot/Core/Network/HttpPostService.cs @@ -8,7 +8,7 @@ namespace Lagrange.OneBot.Core.Network; public sealed class HttpPostService : ILagrangeWebService { - public event EventHandler? OnMessageReceived = delegate { }; + public event EventHandler? OnMessageReceived = delegate { }; private readonly HttpClient _client; diff --git a/Lagrange.OneBot/Core/Network/ILagrangeWebService.cs b/Lagrange.OneBot/Core/Network/ILagrangeWebService.cs index 15a4781e3..c4f75b610 100644 --- a/Lagrange.OneBot/Core/Network/ILagrangeWebService.cs +++ b/Lagrange.OneBot/Core/Network/ILagrangeWebService.cs @@ -4,7 +4,7 @@ namespace Lagrange.OneBot.Core.Network; public interface ILagrangeWebService : IHostedService { - public event EventHandler OnMessageReceived; + public event EventHandler OnMessageReceived; public Task SendJsonAsync(T json, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Network/MsgRecvEventArgs.cs b/Lagrange.OneBot/Core/Network/MsgRecvEventArgs.cs new file mode 100644 index 000000000..9cbccfd98 --- /dev/null +++ b/Lagrange.OneBot/Core/Network/MsgRecvEventArgs.cs @@ -0,0 +1,10 @@ +using Microsoft.Extensions.Hosting; + +namespace Lagrange.OneBot.Core.Network; + +public class MsgRecvEventArgs(string data, string? identifier) : EventArgs +{ + public string? Identifier { get; init; } = identifier; + + public string Data { get; init; } = data; +} diff --git a/Lagrange.OneBot/Core/Network/ReverseWSService.cs b/Lagrange.OneBot/Core/Network/ReverseWSService.cs index 9b123927e..eb7a1e4e2 100644 --- a/Lagrange.OneBot/Core/Network/ReverseWSService.cs +++ b/Lagrange.OneBot/Core/Network/ReverseWSService.cs @@ -1,88 +1,88 @@ -using System.Net.WebSockets; using System.Text.Json; using Lagrange.OneBot.Core.Entity.Meta; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; -using Websocket.Client; +using WebsocketsSimple.Client; +using WebsocketsSimple.Client.Models; using Timer = System.Threading.Timer; namespace Lagrange.OneBot.Core.Network; public sealed class ReverseWSService : ILagrangeWebService { - public event EventHandler OnMessageReceived = delegate { }; - - private readonly WebsocketClient _socket; + public event EventHandler OnMessageReceived = delegate { }; + + private readonly WebsocketClient _websocketClient; private readonly IConfiguration _config; - + private readonly ILogger _logger; - + private readonly Timer _timer; - + public ReverseWSService(IConfiguration config, ILogger logger) { _config = config; _logger = logger; - + var ws = _config.GetSection("Implementation").GetSection("ReverseWebSocket"); - string url = $"ws://{ws["Host"]}:{ws["Port"]}{ws["Suffix"]}"; - _socket = new WebsocketClient(new Uri(url), () => + var headers = new Dictionary() { - var socket = new ClientWebSocket(); - - SetRequestHeader(socket, new Dictionary - { - { "X-Client-Role", "Universal" }, - { "X-Self-ID", _config.GetValue("Account:Uin").ToString() }, - { "User-Agent", Constant.OneBotImpl } - }); - socket.Options.KeepAliveInterval = TimeSpan.FromSeconds(5); - if (_config["AccessToken"] != null) socket.Options.SetRequestHeader("Authorization", $"Bearer {_config["AccessToken"]}"); - - return socket; - }); - - _timer = new Timer(OnHeartbeat, null, int.MaxValue, config.GetValue("Implementation:ReverseWebSocket:HeartBeatInterval")); - _socket.MessageReceived.Subscribe(resp => OnMessageReceived.Invoke(this, resp.Text ?? "")); + { "X-Client-Role", "Universal" }, + { "X-Self-ID", _config.GetValue("Account:Uin").ToString() }, + { "User-Agent", Constant.OneBotImpl } + }; + + if (_config["AccessToken"] != null) + headers.Add("Authorization", $"Bearer {_config["AccessToken"]}"); + + _websocketClient = new WebsocketClient( + new ParamsWSClient( + ws["Host"], + ws.GetValue("Port"), + false, + string.Empty, + ws["Suffix"], + keepAliveIntervalSec: ws.GetValue("ReconnectInterval") / 1000, + requestHeaders: headers + ) + ); + _websocketClient.MessageEvent += (_, e) => + OnMessageReceived.Invoke(this, new(e.Message ?? "", null)); + + _timer = new Timer(OnHeartbeat, null, int.MaxValue, ws.GetValue("HeartBeatInterval")); } - + public async Task StartAsync(CancellationToken cancellationToken) { - await _socket.Start(); - + await _websocketClient.ConnectAsync(); + var lifecycle = new OneBotLifecycle(_config.GetValue("Account:Uin"), "connect"); await SendJsonAsync(lifecycle, cancellationToken); } - public Task StopAsync(CancellationToken cancellationToken) + public async Task StopAsync(CancellationToken cancellationToken) { _timer.Dispose(); - _socket.Dispose(); - - return Task.CompletedTask; + await _websocketClient.DisconnectAsync(); } - + public Task SendJsonAsync(T json, CancellationToken cancellationToken = default) { var payload = JsonSerializer.SerializeToUtf8Bytes(json); - return _socket.SendInstant(payload); + return _websocketClient.SendAsync(payload); } private void OnHeartbeat(object? sender) { var status = new OneBotStatus(true, true); var heartBeat = new OneBotHeartBeat( - _config.GetValue("Account:Uin"), - _config.GetValue("Implementation:ReverseWebSocket:HeartBeatInterval"), - status); - - SendJsonAsync(heartBeat); - } + _config.GetValue("Account:Uin"), + _config.GetValue("Implementation:ReverseWebSocket:HeartBeatInterval"), + status + ); - private static void SetRequestHeader(ClientWebSocket webSocket, Dictionary headers) - { - foreach (var (key, value) in headers) webSocket.Options.SetRequestHeader(key, value); + SendJsonAsync(heartBeat); } -} \ No newline at end of file +} diff --git a/Lagrange.OneBot/Core/Operation/OperationService.cs b/Lagrange.OneBot/Core/Operation/OperationService.cs index 0e59fa26d..da6be2ac0 100644 --- a/Lagrange.OneBot/Core/Operation/OperationService.cs +++ b/Lagrange.OneBot/Core/Operation/OperationService.cs @@ -17,25 +17,30 @@ public OperationService(BotContext bot, ILagrangeWebService service) { _bot = bot; _service = service; - _operations = new Dictionary(); - + _operations = []; + foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) { var attribute = type.GetCustomAttribute(); - if (attribute != null) _operations[attribute.Api] = (IOperation)type.CreateInstance(false); + if (attribute != null) + _operations[attribute.Api] = (IOperation)type.CreateInstance(false); } - service.OnMessageReceived += async (_, s) => await HandleOperation(s); + service.OnMessageReceived += async (_, e) => await HandleOperation(e); } - private async Task HandleOperation(string data) + private async Task HandleOperation(MsgRecvEventArgs e) { - var action = JsonSerializer.Deserialize(data); - + var action = JsonSerializer.Deserialize(e.Data); + if (action != null) { var handler = _operations[action.Action]; var result = await handler.HandleOperation(action.Echo, _bot, action.Params); + + if (!string.IsNullOrEmpty(e.Identifier)) // add an identifier for `ForwardWSService` + result.Identifier = e.Identifier; + await _service.SendJsonAsync(result); } else @@ -43,4 +48,4 @@ private async Task HandleOperation(string data) throw new Exception("action deserialized failed"); } } -} \ No newline at end of file +} diff --git a/Lagrange.OneBot/Lagrange.OneBot.csproj b/Lagrange.OneBot/Lagrange.OneBot.csproj index ce70ff129..45cbb6190 100644 --- a/Lagrange.OneBot/Lagrange.OneBot.csproj +++ b/Lagrange.OneBot/Lagrange.OneBot.csproj @@ -9,10 +9,11 @@ - - - - + + + + + diff --git a/Lagrange.OneBot/LagrangeAppBuilder.cs b/Lagrange.OneBot/LagrangeAppBuilder.cs index 60bb1dbd8..7be94e9f1 100644 --- a/Lagrange.OneBot/LagrangeAppBuilder.cs +++ b/Lagrange.OneBot/LagrangeAppBuilder.cs @@ -1,10 +1,7 @@ using System.Text.Json; using Lagrange.Core.Common; using Lagrange.Core.Common.Interface; -using Lagrange.OneBot.Core; -using Lagrange.OneBot.Core.Message; using Lagrange.OneBot.Core.Network; -using Lagrange.OneBot.Core.Operation; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -76,6 +73,7 @@ public LagrangeAppBuilder ConfigureBots() public LagrangeAppBuilder ConfigureOneBot() { Services.AddSingleton(); + Services.AddSingleton(); return this; } diff --git a/README.md b/README.md index f45d0bbe4..fce559b60 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,16 @@ # Lagrange.Core -[![Core](https://img.shields.io/badge/Lagrange-Core-blue)](#) -[![C#](https://img.shields.io/badge/.NET-%207-blue)](#) -[![License](https://img.shields.io/static/v1?label=LICENSE&message=MIT&color=lightrey)](#) +[![Core](https://img.shields.io/badge/Lagrange-Core-blue)](https://github.com/Linwenxuan05/Lagrange.Core/tree/main/Lagrange.Core) +[![C#](https://img.shields.io/badge/.NET-%207-blue)](https://dotnet.microsoft.com/zh-cn/download/dotnet/7.0) +[![License](https://img.shields.io/static/v1?label=LICENSE&message=MIT&color=lightrey)](https://github.com/Linwenxuan05/Lagrange.Core/blob/main/LICENSE) [![QQ](https://img.shields.io/static/v1?label=QQGroup&message=348981074&color=red)](#) An Implementation of NTQQ Protocol, with Pure C#, Derived from Konata.Core -## Disclaimer: +## Disclaimer The Lagrange.Core project, including its developers, contributors, and affiliated individuals or entities, hereby explicitly disclaim any association with, support for, or endorsement of any form of illegal behavior. This disclaimer extends to any use or application of the Lagrange.Core project that may be contrary to local, national, or international laws, regulations, or ethical guidelines. @@ -26,22 +26,23 @@ By using or accessing Lagrange.Core, the user acknowledges and agrees to release Please use Lagrange.Core responsibly and in accordance with the law. ## Features List -| Protocol | Support | Login | Support | Messages | Support | Operations | Support | Events | Support | -|----------|---------|---------------------------|---------|:-----------------|:-----------|:------------------|:-----------|:-----------------------|:--------| -| Windows | 🟢 | QrCode | 🟢 | Images | 🟢 | ~~Poke~~ | 🔴 | Captcha | 🟢 | -| macOS | 🟢 | Password | 🟢 | Text / At | 🟢 | Recall | 🟡 | BotOnline | 🟢 | -| Linux | 🟢 | EasyLogin | 🟢 | ~~Records~~ | 🔴 | Leave Group | 🟢 | BotOffline | 🟢 | -| | | UnusalDevice
Password | 🔴 | QFace | 🟢 | ~~Special Title~~ | 🔴 | Message | 🟢 | -| | | UnusalDevice
Easy | 🟢 | Json | 🟡 | Kick Member | 🟢 | ~~Poke~~ | 🔴 | -| | | NewDeviceVerify | 🔴 | Xml | 🟢 | Mute Member | 🟢 | MessageRecall | 🔴 | -| | | | | Forward | 🟢 | Set Admin | 🟢 | GroupMemberDecrease | 🟢 | -| | | | | Video | 🔴 | Friend Request | 🔴 | GroupMemberIncrease | 🟢 | -| | | | | ~~Flash Image~~ | 🔴 | Group Request | 🔴 | GroupPromoteAdmin | 🟢 | -| | | | | Reply | 🟢 | ~~Voice Call~~ | 🔴 | GroupInvite | 🟢 | -| | | | | File | 🟡 | Client Key | 🟢 | GroupRequestJoin | 🔴 | -| | | | | | | Cookies | 🟢 | FriendRequest | 🔴 | -| | | | | | | Send Message | 🟢 | ~~FriendTyping~~ | 🔴 | -| | | | | | | | | ~~FriendVoiceCall~~ | 🔴 | + +| Protocol | Support | Login | Support | Messages | Support | Operations | Support | Events | Support | +| -------- | :-----: | ------------------------- | :-----: | :-------------- | :-----: | :---------------- | :-----: | :------------------ | :-----: | +| Windows | 🟢 | QrCode | 🟢 | Images | 🟢 | ~~Poke~~ | 🔴 | Captcha | 🟢 | +| macOS | 🟢 | Password | 🟢 | Text / At | 🟢 | Recall | 🟡 | BotOnline | 🟢 | +| Linux | 🟢 | EasyLogin | 🟢 | ~~Records~~ | 🔴 | Leave Group | 🟢 | BotOffline | 🟢 | +| | | UnusalDevice
Password | 🔴 | QFace | 🟢 | ~~Special Title~~ | 🔴 | Message | 🟢 | +| | | UnusalDevice
Easy | 🟢 | Json | 🟡 | Kick Member | 🟢 | ~~Poke~~ | 🔴 | +| | | NewDeviceVerify | 🔴 | Xml | 🟢 | Mute Member | 🟢 | MessageRecall | 🔴 | +| | | | | Forward | 🟢 | Set Admin | 🟢 | GroupMemberDecrease | 🟢 | +| | | | | Video | 🔴 | Friend Request | 🔴 | GroupMemberIncrease | 🟢 | +| | | | | ~~Flash Image~~ | 🔴 | Group Request | 🔴 | GroupPromoteAdmin | 🟢 | +| | | | | Reply | 🟢 | ~~Voice Call~~ | 🔴 | GroupInvite | 🟢 | +| | | | | File | 🟡 | Client Key | 🟢 | GroupRequestJoin | 🔴 | +| | | | | | | Cookies | 🟢 | FriendRequest | 🔴 | +| | | | | | | Send Message | 🟢 | ~~FriendTyping~~ | 🔴 | +| | | | | | | | | ~~FriendVoiceCall~~ | 🔴 | ## Lagrange.OneBot @@ -50,28 +51,28 @@ Please use Lagrange.Core responsibly and in accordance with the law.
Message Segement -| Message Segement| Support | -| ------------ | ------------| -| [Text] | 🟢 | -| [Face] | 🟢 | -| [Image] | 🟢 | -| [Record] | 🔴 | -| [Video] | 🔴 | -| [At] | 🟢 | -| [Rps] | 🔴 | -| [Dice] | 🔴 | -| [Shake] | 🔴 | -| [Poke] | 🔴 | -| [Anonymous] | 🔴 | -| [Share] | 🔴 | -| [Contact] | 🔴 | -| [Location] | 🔴 | -| [Music] | 🔴 | -| [Reply] | 🔴 | -| [Forward] | 🔴 | -| [Node] | 🔴 | -| [Xml] | 🔴 | -| [Json] | 🔴 | +| Message Segement | Support | +| ---------------- | :-----: | +| [Text] | 🟢 | +| [Face] | 🟢 | +| [Image] | 🟢 | +| [Record] | 🔴 | +| [Video] | 🔴 | +| [At] | 🟢 | +| [Rps] | 🔴 | +| [Dice] | 🔴 | +| [Shake] | 🔴 | +| [Poke] | 🔴 | +| [Anonymous] | 🔴 | +| [Share] | 🔴 | +| [Contact] | 🔴 | +| [Location] | 🔴 | +| [Music] | 🔴 | +| [Reply] | 🔴 | +| [Forward] | 🔴 | +| [Node] | 🔴 | +| [Xml] | 🔴 | +| [Json] | 🔴 | [Text]: https://github.com/botuniverse/onebot-11/blob/master/message/segment.md#qq-%E8%A1%A8%E6%83%85 [Record]: https://github.com/botuniverse/onebot-11/blob/master/message/segment.md#%E8%AF%AD%E9%9F%B3 @@ -99,46 +100,46 @@ Please use Lagrange.Core responsibly and in accordance with the law.
API -| API | Support | -| ------------------------ | -------- | -| [/send_private_msg] | 🔴 | -| [/send_group_msg] | 🔴 | -| [/send_msg] | 🟢 | -| [/delete_msg] | 🔴 | -| [/get_msg] | 🔴 | -| [/get_forward_msg] | 🔴 | -| ~~[/send_like]~~ | 🔴 | -| [/set_group_kick] | 🟢 | -| [/set_group_ban] | 🟢 | -| [/set_group_anonymous_ban] | 🔴 | -| [/set_group_whole_ban] | 🟢 | -| [/set_group_admin] | 🟢 | -| [/set_group_anonymous] | 🔴 | -| [/set_group_card] | 🟢 | -| [/set_group_name] | 🟢 | -| [/set_group_leave] | 🟢 | -| [/set_group_special_title] | 🔴 | -| [/set_friend_add_request] | 🔴 | -| [/set_group_add_request] | 🔴 | -| [/get_login_info] | 🟢 | -| [/get_stranger_info] | 🔴 | -| [/get_friend_list] | 🔴 | -| [/get_group_info] | 🟢 | -| [/get_group_list] | 🟢 | -| [/get_group_member_info] | 🔴 | -| [/get_group_member_list] | 🔴 | -| [/get_group_honor_info] | 🔴 | -| [/get_cookies] | 🔴 | -| [/get_csrf_token] | 🔴 | -| [/get_credentials] | 🔴 | -| [/get_record] | 🔴 | -| [/get_image] | 🔴 | -| [/can_send_image] | 🔴 | -| [/can_send_record] | 🔴 | -| [/get_status] | 🔴 | -| [/get_version_info] | 🟢 | -| [/set_restart] | 🔴 | -| [/clean_cache] | 🔴 | +| API | Support | +| -------------------------- | ------- | +| [/send_private_msg] | 🔴 | +| [/send_group_msg] | 🔴 | +| [/send_msg] | 🟢 | +| [/delete_msg] | 🔴 | +| [/get_msg] | 🔴 | +| [/get_forward_msg] | 🔴 | +| ~~[/send_like]~~ | 🔴 | +| [/set_group_kick] | 🟢 | +| [/set_group_ban] | 🟢 | +| [/set_group_anonymous_ban] | 🔴 | +| [/set_group_whole_ban] | 🟢 | +| [/set_group_admin] | 🟢 | +| [/set_group_anonymous] | 🔴 | +| [/set_group_card] | 🟢 | +| [/set_group_name] | 🟢 | +| [/set_group_leave] | 🟢 | +| [/set_group_special_title] | 🔴 | +| [/set_friend_add_request] | 🔴 | +| [/set_group_add_request] | 🔴 | +| [/get_login_info] | 🟢 | +| [/get_stranger_info] | 🔴 | +| [/get_friend_list] | 🔴 | +| [/get_group_info] | 🟢 | +| [/get_group_list] | 🟢 | +| [/get_group_member_info] | 🔴 | +| [/get_group_member_list] | 🔴 | +| [/get_group_honor_info] | 🔴 | +| [/get_cookies] | 🔴 | +| [/get_csrf_token] | 🔴 | +| [/get_credentials] | 🔴 | +| [/get_record] | 🔴 | +| [/get_image] | 🔴 | +| [/can_send_image] | 🔴 | +| [/can_send_record] | 🔴 | +| [/get_status] | 🔴 | +| [/get_version_info] | 🟢 | +| [/set_restart] | 🔴 | +| [/clean_cache] | 🔴 | [/send_private_msg]: https://github.com/botuniverse/onebot-11/blob/master/api/public.md#send_private_msg-%E5%8F%91%E9%80%81%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF [/send_group_msg]: https://github.com/botuniverse/onebot-11/blob/master/api/public.md#send_group_msg-%E5%8F%91%E9%80%81%E7%BE%A4%E6%B6%88%E6%81%AF @@ -184,25 +185,25 @@ Please use Lagrange.Core responsibly and in accordance with the law.
Event -| PostType| EventName | Support | -| --------| -----------------------------|----------| -| Message | [Private Message] | 🔴 | -| Message | [Group Message] | 🟢 | -| Notice | [Group File Upload] | 🔴 | -| Notice | [Group Admin Change] | 🔴 | -| Notice | [Group Member Decrease] | 🔴 | -| Notice | [Group Member Increase] | 🔴 | -| Notice | [Group Mute] | 🔴 | -| Notice | [Friend Add] | 🔴 | -| Notice | [Group Recall Message] | 🔴 | -| Notice | [Friend Recall Message] | 🔴 | -| Notice | [Group Poke] | 🔴 | -| Notice | [Group red envelope luck king]| 🔴 | -| Notice | [Group Member Honor Changed] | 🔴 | -| Request| [Add Friend Request] | 🔴 | -| Request| [Group Request/Invitations] | 🔴 | -| Meta | [LifeCycle] | 🟢 | -| Meta | [Heartbeat] | 🟢 | +| PostType | EventName | Support | +| -------- | ------------------------------ | :-----: | +| Message | [Private Message] | 🔴 | +| Message | [Group Message] | 🟢 | +| Notice | [Group File Upload] | 🔴 | +| Notice | [Group Admin Change] | 🔴 | +| Notice | [Group Member Decrease] | 🔴 | +| Notice | [Group Member Increase] | 🔴 | +| Notice | [Group Mute] | 🔴 | +| Notice | [Friend Add] | 🔴 | +| Notice | [Group Recall Message] | 🔴 | +| Notice | [Friend Recall Message] | 🔴 | +| Notice | [Group Poke] | 🔴 | +| Notice | [Group red envelope luck king] | 🔴 | +| Notice | [Group Member Honor Changed] | 🔴 | +| Request | [Add Friend Request] | 🔴 | +| Request | [Group Request/Invitations] | 🔴 | +| Meta | [LifeCycle] | 🟢 | +| Meta | [Heartbeat] | 🟢 | [Private Message]: https://github.com/botuniverse/onebot-11/blob/master/event/message.md#%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF [Group Message]: https://github.com/botuniverse/onebot-11/blob/master/event/message.md#%E7%BE%A4%E6%B6%88%E6%81%AF @@ -224,8 +225,26 @@ Please use Lagrange.Core responsibly and in accordance with the law.
+
+Communication + +| CommunicationType | Support | +| ------------------ | :-----: | +| [Http] | 🔴 | +| [Http-Post] | 🟢 | +| [ForwardWebSocket] | 🟢 | +| [ReverseWebSocket] | 🟢 | + +[Http]: https://github.com/botuniverse/onebot-11/blob/master/communication/http.md +[Http-Post]: https://github.com/botuniverse/onebot-11/blob/master/communication/http-post.md +[ForwardWebSocket]: https://github.com/botuniverse/onebot-11/blob/master/communication/ws.md +[ReverseWebSocket]: https://github.com/botuniverse/onebot-11/blob/master/communication/ws-reverse.md + +
+ #### appsettings.json Example -```C# + +```json { "Logging": { "LogLevel": { @@ -244,15 +263,14 @@ Please use Lagrange.Core responsibly and in accordance with the law. }, "Implementation": { "ForwardWebSocket": { - "Host": "", - "Port": 0, - "HeartBeatIntetval": 0 + "Port": 8081, + "HeartBeatIntetval": 5000 }, "ReverseWebSocket": { "Host": "127.0.0.1", "Port": 8080, "Suffix": "/onebot/v11/ws", - "ReconnectInterval": 0, + "ReconnectInterval": 3000, "HeartBeatInterval": 5000 }, "Http": { @@ -269,11 +287,13 @@ Please use Lagrange.Core responsibly and in accordance with the law. } } ``` -- Create a file named 'appsettings.json' under Lagrange.OneBot executable directory + +- Create a file named 'appsettings.json' under Lagrange.OneBot executable directory - As the Uin is 0 here, this indicates that QRCode login is used - After the QRCode Login, write Uin back to perform EasyLogin ## 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.~~ Thanks KonataDev/TheSnowfield for Provision of Signature API