Skip to content

Commit

Permalink
Merge pull request #25 from TheSnowfield/main
Browse files Browse the repository at this point in the history
Several updates
  • Loading branch information
Linwenxuan authored Oct 17, 2023
2 parents 9967ee1 + e877726 commit e226a84
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# .net build artiifacts
bin/
obj/
/packages/

riderModule.iml
/_ReSharper.Caches/
Lagrange.Core/Utility/Crypto/Provider/Dandelion/*.cs
Lagrange.Core/Utility/Crypto/Provider/Dandelion/*.cs

# rider files
.idea/
*.DotSettings.user
2 changes: 1 addition & 1 deletion Lagrange.Core.Test/Tests/WtLoginTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
10 changes: 5 additions & 5 deletions Lagrange.Core/Common/Interface/Api/BotExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public static class BotExt
/// <summary>
/// Fetch the qrcode for QRCode Login
/// </summary>
/// <returns>the byte of QRCode, usually in the form of PNG</returns>
public static async Task<byte[]?> FetchQrCode(this BotContext bot)
=> await bot.ContextCollection.Business.WtExchangeLogic.FetchQrCode();
/// <returns>return url and qrcode image in PNG format</returns>
public static Task<(string Url, byte[] QrCode)?> FetchQrCode(this BotContext bot)
=> bot.ContextCollection.Business.WtExchangeLogic.FetchQrCode();

/// <summary>
/// Use this method to login by QrCode, you should call <see cref="FetchQrCode"/> first
Expand All @@ -20,8 +20,8 @@ public static Task LoginByQrCode(this BotContext bot)
/// <summary>
/// Use this method to login by password, EasyLogin may be preformed if there is sig in <see cref="BotKeystore"/>
/// </summary>
public static async Task<bool> LoginByPassword(this BotContext bot)
=> await bot.ContextCollection.Business.WtExchangeLogic.LoginByPassword();
public static Task<bool> LoginByPassword(this BotContext bot)
=> bot.ContextCollection.Business.WtExchangeLogic.LoginByPassword();

/// <summary>
/// Submit the captcha of the url given by the <see cref="EventInvoker.OnBotCaptchaEvent"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override async Task Incoming(ProtocolEvent e)
/// <para>1. resolve wtlogin.trans_emp CMD0x31 packet</para>
/// <para>2. Schedule wtlogin.trans_emp CMD0x12 Task</para>
/// </summary>
public async Task<byte[]?> FetchQrCode()
public async Task<(string, byte[])?> FetchQrCode()
{
Collection.Log.LogInfo(Tag, "Connecting Servers...");
if (!await Collection.Socket.Connect()) return null;
Expand All @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions Lagrange.Core/Message/MessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion Lagrange.OneBot/LagrangeApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down

0 comments on commit e226a84

Please sign in to comment.