Skip to content

Commit

Permalink
Merge branch 'LagrangeDev:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
sisi0318 authored Aug 28, 2024
2 parents c5e51bc + aa7ca60 commit 82c33bb
Show file tree
Hide file tree
Showing 31 changed files with 626 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Lagrange.Core/Common/Entity/BotFileEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Lagrange.Core.Common.Entity;
[Serializable]
public class BotFileEntry : IBotFSEntry
{
internal string FileId { get; }
public string FileId { get; }

public string FileName { get; }

Expand Down
52 changes: 52 additions & 0 deletions Lagrange.Core/Common/Entity/BotGroupClockInResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace Lagrange.Core.Common.Entity;

[Serializable]
public class BotGroupClockInResult
{
public BotGroupClockInResult() { }

public BotGroupClockInResult(bool isSuccess)
{
IsSuccess = isSuccess;
}

/// <summary>
/// Is the clock in successful
/// </summary>
public bool IsSuccess { get; set; } = false;

/// <summary>
/// Maybe "今日已成功打卡"
/// </summary>
public string Title { get; set; } = string.Empty;

/// <summary>
/// Maybe "已打卡N天"
/// </summary>
public string KeepDayText { get; set; } = string.Empty;

/// <summary>
/// Maybe "群内排名第N位"
/// </summary>
public string GroupRankText { get; set; } = string.Empty;

/// <summary>
/// The utc time of clock in
/// </summary>
public DateTime ClockInUtcTime { get; set; } = DateTime.UnixEpoch; // 打卡时间

/// <summary>
/// Detail info url
/// </summary>
public string DetailUrl { get; set; } = string.Empty; // https://qun.qq.com/v2/signin/detail?...

public static BotGroupClockInResult Fail() => new BotGroupClockInResult()
{
IsSuccess = false
};

public static BotGroupClockInResult Success() => new BotGroupClockInResult()
{
IsSuccess = true
};
}
12 changes: 9 additions & 3 deletions Lagrange.Core/Common/Interface/Api/GroupExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public static Task<ulong> FetchGroupFSSpace(this BotContext bot, uint groupUin)
public static Task<uint> FetchGroupFSCount(this BotContext bot, uint groupUin)
=> bot.ContextCollection.Business.OperationLogic.FetchGroupFSCount(groupUin);

public static Task<List<IBotFSEntry>> FetchGroupFSList(this BotContext bot, uint groupUin, string targetDirectory = "/", uint startIndex = 0)
=> bot.ContextCollection.Business.OperationLogic.FetchGroupFSList(groupUin, targetDirectory, startIndex);
public static Task<List<IBotFSEntry>> FetchGroupFSList(this BotContext bot, uint groupUin, string targetDirectory = "/")
=> bot.ContextCollection.Business.OperationLogic.FetchGroupFSList(groupUin, targetDirectory);

public static Task<string> FetchGroupFSDownload(this BotContext bot, uint groupUin, string fileId)
=> bot.ContextCollection.Business.OperationLogic.FetchGroupFSDownload(groupUin, fileId);
Expand All @@ -107,9 +107,15 @@ public static Task<bool> GroupFSMove(this BotContext bot, uint groupUin, string
public static Task<bool> GroupFSDelete(this BotContext bot, uint groupUin, string fileId)
=> bot.ContextCollection.Business.OperationLogic.GroupFSDelete(groupUin, fileId);

public static Task<bool> GroupFSCreateFolder(this BotContext bot, uint groupUin, string name)
public static Task<(int, string)> GroupFSCreateFolder(this BotContext bot, uint groupUin, string name)
=> bot.ContextCollection.Business.OperationLogic.GroupFSCreateFolder(groupUin, name);

public static Task<(int, string)> GroupFSDeleteFolder(this BotContext bot, uint groupUin, string folderId)
=> bot.ContextCollection.Business.OperationLogic.GroupFSDeleteFolder(groupUin, folderId);

public static Task<(int, string)> GroupFSRenameFolder(this BotContext bot, uint groupUin, string folderId, string newFolderName)
=> bot.ContextCollection.Business.OperationLogic.GroupFSRenameFolder(groupUin, folderId, newFolderName);

public static Task<bool> GroupFSUpload(this BotContext bot, uint groupUin, FileEntity fileEntity, string targetDirectory = "/")
=> bot.ContextCollection.Business.OperationLogic.GroupFSUpload(groupUin, fileEntity, targetDirectory);

Expand Down
9 changes: 9 additions & 0 deletions Lagrange.Core/Common/Interface/Api/OperationExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ public static Task<bool> Like(this BotContext bot, uint targetUin, uint count =
return bot.ContextCollection.Business.OperationLogic.GetRoamMessage(targetChain.FriendUin, timestamp, count);
}

/// <summary>
/// Do group clock in (群打卡)
/// </summary>
/// <param name="bot">target BotContext</param>
/// <param name="groupUin">target groupUin</param>
/// <returns></returns>
public static Task<BotGroupClockInResult> ClockInGroup(this BotContext bot, uint groupUin)
=> bot.ContextCollection.Business.OperationLogic.ClockInGroup(groupUin);

public static Task<BotUserInfo?> FetchUserInfo(this BotContext bot, uint uin, bool refreshCache = false)
=> bot.ContextCollection.Business.OperationLogic.FetchUserInfo(uin, refreshCache);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,20 @@ public async Task<uint> FetchGroupFSCount(uint groupUin)
return ((GroupFSCountEvent)events[0]).FileCount;
}

public async Task<List<IBotFSEntry>> FetchGroupFSList(uint groupUin, string targetDirectory, uint startIndex)
public async Task<List<IBotFSEntry>> FetchGroupFSList(uint groupUin, string targetDirectory)
{
var groupFSListEvent = GroupFSListEvent.Create(groupUin, targetDirectory, startIndex);
var events = await Collection.Business.SendEvent(groupFSListEvent);
return ((GroupFSListEvent)events[0]).FileEntries;
uint startIndex = 0;
var entries = new List<IBotFSEntry>();
while (true)
{
var groupFSListEvent = GroupFSListEvent.Create(groupUin, targetDirectory, startIndex, 20);
var events = await Collection.Business.SendEvent(groupFSListEvent);
if (events.Count == 0) break;
entries.AddRange(((GroupFSListEvent)events[0]).FileEntries);
if (((GroupFSListEvent)events[0]).IsEnd) break;
startIndex += 20;
}
return entries;
}

public async Task<string> FetchGroupFSDownload(uint groupUin, string fileId)
Expand All @@ -164,11 +173,31 @@ public async Task<bool> GroupFSDelete(uint groupUin, string fileId)
return events.Count != 0 && ((GroupFSDeleteEvent)events[0]).ResultCode == 0;
}

public async Task<bool> GroupFSCreateFolder(uint groupUin, string name)
public async Task<(int, string)> GroupFSCreateFolder(uint groupUin, string name)
{
var groupFSCreateFolderEvent = GroupFSCreateFolderEvent.Create(groupUin, name);
var events = await Collection.Business.SendEvent(groupFSCreateFolderEvent);
return events.Count != 0 && ((GroupFSCreateFolderEvent)events[0]).ResultCode == 0;
var retCode = events.Count > 0 ? ((GroupFSCreateFolderEvent)events[0]).ResultCode : -1;
var retMsg = events.Count > 0 ? ((GroupFSCreateFolderEvent)events[0]).RetMsg : "";
return new(retCode, retMsg);
}

public async Task<(int, string)> GroupFSDeleteFolder(uint groupUin, string folderId)
{
var groupFSDeleteFolderEvent = GroupFSDeleteFolderEvent.Create(groupUin, folderId);
var events = await Collection.Business.SendEvent(groupFSDeleteFolderEvent);
var retCode = events.Count > 0 ? ((GroupFSDeleteFolderEvent)events[0]).ResultCode : -1;
var retMsg = events.Count > 0 ? ((GroupFSDeleteFolderEvent)events[0]).RetMsg : "";
return new(retCode, retMsg);
}

public async Task<(int, string)> GroupFSRenameFolder(uint groupUin, string folderId, string newFolderName)
{
var groupFSDeleteFolderEvent = GroupFSRenameFolderEvent.Create(groupUin, folderId, newFolderName);
var events = await Collection.Business.SendEvent(groupFSDeleteFolderEvent);
var retCode = events.Count > 0 ? ((GroupFSRenameFolderEvent)events[0]).ResultCode : -1;
var retMsg = events.Count > 0 ? ((GroupFSRenameFolderEvent)events[0]).RetMsg : "";
return new(retCode, retMsg);
}

public Task<bool> GroupFSUpload(uint groupUin, FileEntity fileEntity, string targetDirectory)
Expand Down Expand Up @@ -453,4 +482,11 @@ public async Task<bool> SetNeedToConfirmSwitch(bool enableNoNeed)
var results = await Collection.Business.SendEvent(fetchMarketFaceKeyEvent);
return results.Count != 0 ? ((FetchMarketFaceKeyEvent)results[0]).Keys : null;
}

public async Task<BotGroupClockInResult> ClockInGroup(uint groupUin)
{
var groupClockInEvent = GroupClockInEvent.Create(groupUin);
var results = await Collection.Business.SendEvent(groupClockInEvent);
return ((GroupClockInEvent)results[0]).ResultInfo ?? new BotGroupClockInResult(false);
}
}
24 changes: 24 additions & 0 deletions Lagrange.Core/Internal/Event/Action/GroupClockInEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Lagrange.Core.Common.Entity;

namespace Lagrange.Core.Internal.Event.Action;

internal class GroupClockInEvent : ProtocolEvent
{
public uint GroupUin { get; set; }
public BotGroupClockInResult? ResultInfo { get; set; }

private GroupClockInEvent(uint groupUin) : base(true)
{
GroupUin = groupUin;
ResultInfo = null;
}

private GroupClockInEvent(int resultCode, BotGroupClockInResult result) : base(resultCode)
{
ResultInfo = result;
}

public static GroupClockInEvent Create(uint groupUin) => new(groupUin);

public static GroupClockInEvent Result(int resultCode, BotGroupClockInResult result) => new(resultCode, result);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ internal class GroupFSCreateFolderEvent : ProtocolEvent
public uint GroupUin { get; }

public string Name { get; } = string.Empty;

public string RetMsg { get; set; } = string.Empty;

private GroupFSCreateFolderEvent(uint groupUin, string name) : base(true)
{
GroupUin = groupUin;
Name = name;
}

private GroupFSCreateFolderEvent(int resultCode) : base(resultCode) { }
private GroupFSCreateFolderEvent(int resultCode, string retMsg) : base(resultCode)
{
RetMsg = retMsg;
}

public static GroupFSCreateFolderEvent Create(uint groupUin, string name) => new(groupUin, name);

public static GroupFSCreateFolderEvent Result(int resultCode) => new(resultCode);
public static GroupFSCreateFolderEvent Result(int resultCode, string retMsg) => new(resultCode, retMsg);
}
25 changes: 25 additions & 0 deletions Lagrange.Core/Internal/Event/Action/GroupFSDeleteFolderEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Lagrange.Core.Internal.Event.Action;

internal class GroupFSDeleteFolderEvent : ProtocolEvent
{
public uint GroupUin { get; }

public string FolderId { get; } = string.Empty;

public string RetMsg { get; set; } = string.Empty;

private GroupFSDeleteFolderEvent(uint groupUin, string folderId) : base(true)
{
GroupUin = groupUin;
FolderId = folderId;
}

private GroupFSDeleteFolderEvent(int resultCode, string retMsg) : base(resultCode)
{
RetMsg = retMsg;
}

public static GroupFSDeleteFolderEvent Create(uint groupUin, string folderId) => new(groupUin, folderId);

public static GroupFSDeleteFolderEvent Result(int resultCode, string retMsg) => new(resultCode, retMsg);
}
19 changes: 13 additions & 6 deletions Lagrange.Core/Internal/Event/Action/GroupFSListEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,29 @@ internal class GroupFSListEvent : GroupFSViewEvent

public uint StartIndex { get; set; }

public uint FileCount { get; set; }

public bool IsEnd { get; set; }

public List<IBotFSEntry> FileEntries { get; set; }

private GroupFSListEvent(uint groupUin, string targetDirectory, uint startIndex) : base(groupUin)
private GroupFSListEvent(uint groupUin, string targetDirectory, uint startIndex, uint fileCount) : base(groupUin)
{
TargetDirectory = targetDirectory;
StartIndex = startIndex;
FileCount = fileCount;
IsEnd = false;
}

private GroupFSListEvent(int resultCode, List<IBotFSEntry> fileEntries) : base(resultCode)
private GroupFSListEvent(int resultCode, List<IBotFSEntry> fileEntries, bool isEnd) : base(resultCode)
{
FileEntries = fileEntries;
IsEnd = isEnd;
}

public static GroupFSListEvent Create(uint groupUin, string targetDirectory, uint startIndex)
=> new(groupUin, targetDirectory, startIndex);
public static GroupFSListEvent Create(uint groupUin, string targetDirectory, uint startIndex, uint fileCount)
=> new(groupUin, targetDirectory, startIndex, fileCount);

public static GroupFSListEvent Result(int resultCode, List<IBotFSEntry> fileEntries)
=> new(resultCode, fileEntries);
public static GroupFSListEvent Result(int resultCode, List<IBotFSEntry> fileEntries, bool isEnd)
=> new(resultCode, fileEntries, isEnd);
}
28 changes: 28 additions & 0 deletions Lagrange.Core/Internal/Event/Action/GroupFSRenameFolderEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Lagrange.Core.Internal.Event.Action;

internal class GroupFSRenameFolderEvent : ProtocolEvent
{
public uint GroupUin { get; }

public string FolderId { get; } = string.Empty;

public string NewFolderName { get; } = string.Empty;

public string RetMsg { get; set; } = string.Empty;

private GroupFSRenameFolderEvent(uint groupUin, string folderId, string newFolderName) : base(true)
{
GroupUin = groupUin;
FolderId = folderId;
NewFolderName = newFolderName;
}

private GroupFSRenameFolderEvent(int resultCode, string retMsg) : base(resultCode)
{
RetMsg = retMsg;
}

public static GroupFSRenameFolderEvent Create(uint groupUin, string folderId, string newFolderName) => new(groupUin, folderId, newFolderName);

public static GroupFSRenameFolderEvent Result(int resultCode, string retMsg) => new(resultCode, retMsg);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ProtoBuf;
using ProtoBuf;

namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request;

Expand All @@ -9,14 +9,14 @@ namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request;
/// Create Folder
/// </summary>
[ProtoContract]
[OidbSvcTrpcTcp(0x6D7, 9)]
[OidbSvcTrpcTcp(0x6D7, 0)]
internal class OidbSvcTrpcTcp0x6D7_0
{
[ProtoMember(1)] public OidbSvcTrpcTcp0x6D7_0Folder Folder { get; set; }
[ProtoMember(1)] public OidbSvcTrpcTcp0x6D7_0Create Create { get; set; }
}

[ProtoContract]
internal class OidbSvcTrpcTcp0x6D7_0Folder
internal class OidbSvcTrpcTcp0x6D7_0Create
{
[ProtoMember(1)] public uint GroupUin { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using ProtoBuf;

namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request;

#pragma warning disable CS8618
// ReSharper disable InconsistentNaming

/// <summary>
/// Delete Folder
/// </summary>
[ProtoContract]
[OidbSvcTrpcTcp(0x6D7, 1)]
internal class OidbSvcTrpcTcp0x6D7_1
{
[ProtoMember(2)] public OidbSvcTrpcTcp0x6D7_1Delete Delete { get; set; }
}

[ProtoContract]
internal class OidbSvcTrpcTcp0x6D7_1Delete
{
[ProtoMember(1)] public uint GroupUin { get; set; }

[ProtoMember(3)] public string FolderId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using ProtoBuf;

namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request;

#pragma warning disable CS8618
// ReSharper disable InconsistentNaming

/// <summary>
/// Delete Folder
/// </summary>
[ProtoContract]
[OidbSvcTrpcTcp(0x6D7, 2)]
internal class OidbSvcTrpcTcp0x6D7_2
{
[ProtoMember(3)] public OidbSvcTrpcTcp0x6D7_2Rename Rename { get; set; }
}

[ProtoContract]
internal class OidbSvcTrpcTcp0x6D7_2Rename
{
[ProtoMember(1)] public uint GroupUin { get; set; }

[ProtoMember(3)] public string FolderId { get; set; }

[ProtoMember(4)] public string NewFolderName { get; set; }
}
Loading

0 comments on commit 82c33bb

Please sign in to comment.