Skip to content

Commit

Permalink
Added Summary for Lagrange.Core APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan authored and Linwenxuan committed Oct 16, 2023
1 parent 28f039d commit e0af29a
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 17 deletions.
13 changes: 11 additions & 2 deletions Lagrange.Core/Common/Interface/Api/BotExt.cs
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -17,14 +23,17 @@ public static Task LoginByQrCode(this BotContext bot)
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;
}
27 changes: 27 additions & 0 deletions Lagrange.Core/Common/Interface/Api/GroupExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -25,6 +48,8 @@ public static Task<bool> RenameGroup(this BotContext bot, uint groupUin, string
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);

Expand All @@ -39,4 +64,6 @@ public static Task<string> FetchGroupFSDownload(this BotContext bot, uint groupU

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
}
46 changes: 46 additions & 0 deletions Lagrange.Core/Common/Interface/Api/OperationExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
7 changes: 0 additions & 7 deletions Lagrange.Core/Common/Interface/Api/TestExt.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,7 @@ public async Task<bool> GroupFSMove(uint groupUin, string fileId, string parentD
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;
Expand Down

0 comments on commit e0af29a

Please sign in to comment.