From 9062298220f1ef65ad16e2be189b26225b2b4518 Mon Sep 17 00:00:00 2001 From: TheSnowfield <17957399+TheSnowfield@users.noreply.github.com> Date: Tue, 17 Oct 2023 12:09:56 +0800 Subject: [PATCH 1/3] Expose qrcode url to user --- Lagrange.Core.Test/Tests/WtLoginTest.cs | 2 +- Lagrange.Core/Common/Interface/Api/BotExt.cs | 10 +++++----- .../Context/Logic/Implementation/WtExchangeLogic.cs | 4 ++-- Lagrange.OneBot/LagrangeApp.cs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Lagrange.Core.Test/Tests/WtLoginTest.cs b/Lagrange.Core.Test/Tests/WtLoginTest.cs index 95a6aba37..08d519c55 100644 --- a/Lagrange.Core.Test/Tests/WtLoginTest.cs +++ b/Lagrange.Core.Test/Tests/WtLoginTest.cs @@ -36,7 +36,7 @@ public async Task FetchQrCode() var qrCode = await bot.FetchQrCode(); if (qrCode != null) { - await File.WriteAllBytesAsync("qr.png", qrCode); + await File.WriteAllBytesAsync("qr.png", qrCode.Value.QrCode); await bot.LoginByQrCode(); } } diff --git a/Lagrange.Core/Common/Interface/Api/BotExt.cs b/Lagrange.Core/Common/Interface/Api/BotExt.cs index d1cb145bb..213b527c0 100644 --- a/Lagrange.Core/Common/Interface/Api/BotExt.cs +++ b/Lagrange.Core/Common/Interface/Api/BotExt.cs @@ -7,9 +7,9 @@ public static class BotExt /// /// Fetch the qrcode for QRCode Login /// - /// the byte of QRCode, usually in the form of PNG - public static async Task FetchQrCode(this BotContext bot) - => await bot.ContextCollection.Business.WtExchangeLogic.FetchQrCode(); + /// return url and qrcode image in PNG format + public static Task<(string Url, byte[] QrCode)?> FetchQrCode(this BotContext bot) + => bot.ContextCollection.Business.WtExchangeLogic.FetchQrCode(); /// /// Use this method to login by QrCode, you should call first @@ -20,8 +20,8 @@ public static Task LoginByQrCode(this BotContext bot) /// /// Use this method to login by password, EasyLogin may be preformed if there is sig in /// - public static async Task LoginByPassword(this BotContext bot) - => await bot.ContextCollection.Business.WtExchangeLogic.LoginByPassword(); + public static Task LoginByPassword(this BotContext bot) + => bot.ContextCollection.Business.WtExchangeLogic.LoginByPassword(); /// /// Submit the captcha of the url given by the diff --git a/Lagrange.Core/Internal/Context/Logic/Implementation/WtExchangeLogic.cs b/Lagrange.Core/Internal/Context/Logic/Implementation/WtExchangeLogic.cs index bfc96521a..fde5b1251 100644 --- a/Lagrange.Core/Internal/Context/Logic/Implementation/WtExchangeLogic.cs +++ b/Lagrange.Core/Internal/Context/Logic/Implementation/WtExchangeLogic.cs @@ -56,7 +56,7 @@ public override async Task Incoming(ProtocolEvent e) /// 1. resolve wtlogin.trans_emp CMD0x31 packet /// 2. Schedule wtlogin.trans_emp CMD0x12 Task /// - public async Task FetchQrCode() + public async Task<(string, byte[])?> FetchQrCode() { Collection.Log.LogInfo(Tag, "Connecting Servers..."); if (!await Collection.Socket.Connect()) return null; @@ -73,7 +73,7 @@ public override async Task Incoming(ProtocolEvent e) Collection.Keystore.Session.QrUrl = @event.Url; Collection.Log.LogInfo(Tag, $"QrCode Fetched, Expiration: {@event.Expiration} seconds"); - return @event.QrCode; + return (@event.Url, @event.QrCode); } return null; } diff --git a/Lagrange.OneBot/LagrangeApp.cs b/Lagrange.OneBot/LagrangeApp.cs index 1d723ec20..c9e335f97 100644 --- a/Lagrange.OneBot/LagrangeApp.cs +++ b/Lagrange.OneBot/LagrangeApp.cs @@ -72,7 +72,7 @@ internal LagrangeApp(IHost host) var qrCode = await Instance.FetchQrCode(); if (qrCode != null) { - QrCodeHelper.Output(Instance.ContextCollection.Keystore.Session.QrUrl ?? ""); + QrCodeHelper.Output(qrCode.Value.Url ?? ""); await Instance.LoginByQrCode(); } } From 2da9647e13b0c4190aea20927c7fedf73c018055 Mon Sep 17 00:00:00 2001 From: TheSnowfield <17957399+TheSnowfield@users.noreply.github.com> Date: Tue, 17 Oct 2023 12:12:25 +0800 Subject: [PATCH 2/3] Add IMessageEntity to chain directly --- Lagrange.Core/Message/MessageBuilder.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lagrange.Core/Message/MessageBuilder.cs b/Lagrange.Core/Message/MessageBuilder.cs index 8ccdb8a81..6abc15288 100644 --- a/Lagrange.Core/Message/MessageBuilder.cs +++ b/Lagrange.Core/Message/MessageBuilder.cs @@ -81,6 +81,12 @@ public MessageBuilder Image(byte[] file) return this; } + + public MessageBuilder Add(IMessageEntity entity) + { + _chain.Add(entity); + return this; + } public MessageChain Build() => _chain; } \ No newline at end of file From e87772630a35964ffe810516ea2e8fb72f3d4c2a Mon Sep 17 00:00:00 2001 From: TheSnowfield <17957399+TheSnowfield@users.noreply.github.com> Date: Tue, 17 Oct 2023 12:14:14 +0800 Subject: [PATCH 3/3] Update .gitignore --- .gitignore | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ed5f2c14d..3fbf0d356 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,12 @@ +# .net build artiifacts bin/ 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 + +# rider files +.idea/ +*.DotSettings.user