Added Summary for Lagrange.Core APIs

This commit is contained in:
Linwenxuan 2023-10-16 21:41:16 +08:00
parent 28f039da4c
commit e0af29a5ce
5 changed files with 85 additions and 17 deletions

View File

@ -1,7 +1,13 @@
using Lagrange.Core.Internal.Event;
namespace Lagrange.Core.Common.Interface.Api;
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();
@ -17,14 +23,17 @@ public static class BotExt
public static async Task<bool> LoginByPassword(this BotContext bot)
=> await bot.ContextCollection.Business.WtExchangeLogic.LoginByPassword();
/// <summary>
/// Submit the captcha of the url given by the <see cref="EventInvoker.OnBotCaptchaEvent"/>
/// </summary>
/// <returns>Whether the captcha is submitted successfully</returns>
public static bool SubmitCaptcha(this BotContext bot, string ticket, string randStr)
=> bot.ContextCollection.Business.WtExchangeLogic.SubmitCaptcha(ticket, randStr);
/// <summary>
/// Use this method to update keystore, so EasyLogin may be preformed next time by using this keystore
/// </summary>
/// <param name="bot"></param>
/// <returns></returns>
/// <returns>BotKeystore instance</returns>
public static BotKeystore UpdateKeystore(this BotContext bot)
=> bot.ContextCollection.Keystore;
}

View File

@ -4,12 +4,35 @@ namespace Lagrange.Core.Common.Interface.Api;
public static class GroupExt
{
/// <summary>
/// Mute the member in the group, Bot must be admin
/// </summary>
/// <param name="bot">target BotContext</param>
/// <param name="groupUin">The uin for target group</param>
/// <param name="targetUin">The uin for target member in such group</param>
/// <param name="duration">The duration in seconds, 0 for unmute member</param>
/// <returns>Successfully muted or not</returns>
public static Task<bool> MuteGroupMember(this BotContext bot, uint groupUin, uint targetUin, uint duration)
=> bot.ContextCollection.Business.OperationLogic.MuteGroupMember(groupUin, targetUin, duration);
/// <summary>
/// Mute the group
/// </summary>
/// <param name="bot">target BotContext</param>
/// <param name="groupUin">The uin for target group</param>
/// <param name="isMute">true for mute and false for unmute</param>
/// <returns>Successfully muted or not</returns>
public static Task<bool> MuteGroupGlobal(this BotContext bot, uint groupUin, bool isMute)
=> bot.ContextCollection.Business.OperationLogic.MuteGroupGlobal(groupUin, isMute);
/// <summary>
///
/// </summary>
/// <param name="bot">target BotContext</param>
/// <param name="groupUin">The uin for target group</param>
/// <param name="targetUin">The uin for target member in such group</param>
/// <param name="rejectAddRequest">whether the kicked member can request</param>
/// <returns>Successfully kicked or not</returns>
public static Task<bool> KickGroupMember(this BotContext bot, uint groupUin, uint targetUin, bool rejectAddRequest)
=> bot.ContextCollection.Business.OperationLogic.KickGroupMember(groupUin, targetUin, rejectAddRequest);
@ -25,6 +48,8 @@ public static class GroupExt
public static Task<bool> RemarkGroup(this BotContext bot, uint groupUin, string targetRemark)
=> bot.ContextCollection.Business.OperationLogic.RemarkGroup(groupUin, targetRemark);
#region Group File System
public static Task<ulong> FetchGroupFSSpace(this BotContext bot, uint groupUin)
=> bot.ContextCollection.Business.OperationLogic.FetchGroupFSSpace(groupUin);
@ -39,4 +64,6 @@ public static class GroupExt
public static Task<bool> GroupFSMove(this BotContext bot, uint groupUin, string fileId, string parentDirectory, string targetDirectory)
=> bot.ContextCollection.Business.OperationLogic.GroupFSMove(groupUin, fileId, parentDirectory, targetDirectory);
#endregion
}

View File

@ -5,30 +5,76 @@ namespace Lagrange.Core.Common.Interface.Api;
public static class OperationExt
{
/// <summary>
/// Fetch the friend list of account from server or cache
/// </summary>
/// <param name="bot">target BotContext</param>
/// <param name="refreshCache">force the cache to be refreshed</param>
/// <returns></returns>
public static Task<List<BotFriend>> FetchFriends(this BotContext bot, bool refreshCache = false)
=> bot.ContextCollection.Business.OperationLogic.FetchFriends(refreshCache);
/// <summary>
/// Fetch the member list of the group from server or cache
/// </summary>
/// <param name="bot">target BotContext</param>
/// <param name="groupUin"></param>
/// <param name="refreshCache">force the cache to be refreshed</param>
/// <returns></returns>
public static Task<List<BotGroupMember>> FetchMembers(this BotContext bot, uint groupUin, bool refreshCache = false)
=> bot.ContextCollection.Business.OperationLogic.FetchMembers(groupUin, refreshCache);
/// <summary>
/// Fetch the group list of the account from server or cache
/// </summary>
/// <param name="bot">target BotContext</param>
/// <param name="refreshCache">force the cache to be refreshed</param>
/// <returns></returns>
public static Task<List<BotGroup>> FetchGroups(this BotContext bot, bool refreshCache = false)
=> bot.ContextCollection.Business.OperationLogic.FetchGroups(refreshCache);
/// <summary>
/// Fetch the cookies/pskey for accessing other site
/// </summary>
/// <param name="bot">target BotContext</param>
/// <param name="domains">the domain for the cookie to be valid</param>
/// <returns>the list of cookies</returns>
public static Task<List<string>> FetchCookies(this BotContext bot, List<string> domains)
=> bot.ContextCollection.Business.OperationLogic.GetCookies(domains);
/// <summary>
/// Send the message
/// </summary>
/// <param name="bot">target BotContext</param>
/// <param name="chain">the chain constructed by <see cref="MessageBuilder"/></param>
public static Task<MessageResult> SendMessage(this BotContext bot, MessageChain chain)
=> bot.ContextCollection.Business.OperationLogic.SendMessage(chain);
/// <summary>
/// Recall the group message from Bot itself by <see cref="MessageResult"/>
/// </summary>
/// <param name="bot">target BotContext</param>
/// <param name="groupUin">The uin for target group of the message</param>
/// <param name="result">The return value for <see cref="SendMessage"/></param>
/// <returns>Successfully recalled or not</returns>
public static Task<bool> RecallGroupMessage(this BotContext bot, uint groupUin, MessageResult result)
=> bot.ContextCollection.Business.OperationLogic.RecallGroupMessage(groupUin, result);
/// <summary>
/// Recall the group message by <see cref="MessageChain"/>
/// </summary>
/// <param name="bot">target BotContext</param>
/// <param name="chain">target MessageChain, must be Group</param>
/// <returns>Successfully recalled or not</returns>
public static Task<bool> RecallGroupMessage(this BotContext bot, MessageChain chain)
=> bot.ContextCollection.Business.OperationLogic.RecallGroupMessage(chain);
public static Task<bool> RequestFriend(this BotContext bot, uint targetUin, string message = "", string question = "")
=> bot.ContextCollection.Business.OperationLogic.RequestFriend(targetUin, message, question);
/// <summary>
/// Get the client key for all sites
/// </summary>
public static Task<string?> GetClientKey(this BotContext bot)
=> bot.ContextCollection.Business.OperationLogic.GetClientKey();
}

View File

@ -1,7 +0,0 @@
namespace Lagrange.Core.Common.Interface.Api;
internal static class TestExt
{
public static async Task<bool> GetHighwayAddress(this BotContext bot)
=> await bot.ContextCollection.Business.OperationLogic.GetHighwayAddress();
}

View File

@ -137,14 +137,7 @@ internal class OperationLogic : LogicBase
var events = await Collection.Business.SendEvent(groupFSMoveEvent);
return events.Count != 0 && ((GroupFSMoveEvent)events[0]).ResultCode == 0;
}
public async Task<bool> GetHighwayAddress()
{
var highwayUrlEvent = HighwayUrlEvent.Create();
var events = await Collection.Business.SendEvent(highwayUrlEvent);
return events.Count != 0 && ((HighwayUrlEvent)events[0]).ResultCode == 0;
}
public async Task<bool> RecallGroupMessage(uint groupUin, MessageResult result)
{
if (result.Sequence == null) return false;