Skip to content

Commit

Permalink
feat: 合并上游最新代码,同时支持25765版本的签名
Browse files Browse the repository at this point in the history
feat: 合并上游最新代码,同时支持25765版本的签名
  • Loading branch information
JustAnotherID authored Jul 30, 2024
2 parents 9011d85 + d06e343 commit 07b9b60
Show file tree
Hide file tree
Showing 106 changed files with 936 additions and 2,564 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/Lagrange.OneBot-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ jobs:
uses: actions/upload-artifact@v4
if: github.event_name != 'pull_request'
with:
name: Lagrange.OneBot_${{ matrix.runtimeIdentifier }}_7.0
name: Lagrange.OneBot_${{ matrix.runtimeIdentifier }}_net7.0_NoSelfContained
path: Lagrange.OneBot/bin/Debug/net7.0/${{ matrix.runtimeIdentifier }}/publish

- name: Upload binary files(${{ matrix.runtimeIdentifier }}) for .NET 8.0
uses: actions/upload-artifact@v4
if: github.event_name != 'pull_request'
with:
name: Lagrange.OneBot_${{ matrix.runtimeIdentifier }}_8.0
name: Lagrange.OneBot_${{ matrix.runtimeIdentifier }}_net8.0_NoSelfContained
path: Lagrange.OneBot/bin/Release/net8.0/${{ matrix.runtimeIdentifier }}/publish
6 changes: 0 additions & 6 deletions Lagrange.Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "SolutionI
LICENSE = LICENSE
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lagrange.Kritor", "Lagrange.Kritor\Lagrange.Kritor.csproj", "{FD0A15C0-600E-44A9-BAA8-6FAE0A1CA7EE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -38,10 +36,6 @@ Global
{37AEDD3B-9B9F-4782-ADD5-BA2436FB2507}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37AEDD3B-9B9F-4782-ADD5-BA2436FB2507}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37AEDD3B-9B9F-4782-ADD5-BA2436FB2507}.Release|Any CPU.Build.0 = Release|Any CPU
{FD0A15C0-600E-44A9-BAA8-6FAE0A1CA7EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD0A15C0-600E-44A9-BAA8-6FAE0A1CA7EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD0A15C0-600E-44A9-BAA8-6FAE0A1CA7EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD0A15C0-600E-44A9-BAA8-6FAE0A1CA7EE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
37 changes: 9 additions & 28 deletions Lagrange.Core/Common/BotAppInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,18 @@ public class BotAppInfo
public string VendorOs { get; private set; }

public string Kernel { get; private set; }

public string BaseVersion { get; private set; }


public string CurrentVersion { get; private set; }

public int BuildVersion { get; private set; }


public int MiscBitmap { get; private set; }

public string PtVersion { get; private set; }

public int PtOsVersion { get; private set; }
public int SsoVersion { get; private set; }

public string PackageName { get; private set; }

public string WtLoginSdk { get; private set; }

/// <summary>Or Known as QUA</summary>
public string PackageSign { get; private set; }

public int AppId { get; private set; }

Expand All @@ -49,20 +42,16 @@ public class BotAppInfo
Os = "Linux",
Kernel = "Linux",
VendorOs = "linux",

BaseVersion = "3.1.1-11223",
CurrentVersion = "3.1.2-13107",
BuildVersion = 13107,
CurrentVersion = "3.2.10-25765",
MiscBitmap = 32764,
PtVersion = "2.0.0",
PtOsVersion = 19,
SsoVersion = 19,
PackageName = "com.tencent.qq",
WtLoginSdk = "nt.wtlogin.0.0.1",
PackageSign = "V1_LNX_NQ_3.1.2-13107_RDM_B",
AppId = 1600001615,
SubAppId = 537146866,
SubAppId = 537234773,
AppIdQrCode = 13697054,
AppClientVersion = 13172,
AppClientVersion = 25765,

MainSigMap = 169742560,
SubSigMap = 0,
Expand All @@ -74,16 +63,12 @@ public class BotAppInfo
Os = "Mac",
Kernel = "Darwin",
VendorOs = "mac",

BaseVersion = "6.9.17-12118",
CurrentVersion = "6.9.23-20139",
BuildVersion = 20139,
PtVersion = "2.0.0",
MiscBitmap = 32764,
PtOsVersion = 23,
SsoVersion = 23,
PackageName = "com.tencent.qq",
WtLoginSdk = "nt.wtlogin.0.0.1",
PackageSign = "V1_MAC_NQ_6.9.23-20139_RDM_B",
AppId = 1600001602,
SubAppId = 537200848,
AppIdQrCode = 537200848,
Expand All @@ -99,16 +84,12 @@ public class BotAppInfo
Os = "Windows",
Kernel = "Windows_NT",
VendorOs = "win32",

BaseVersion = "9.9.1-15489",
CurrentVersion = "9.9.2-15962",
BuildVersion = 15962,
PtVersion = "2.0.0",
MiscBitmap = 32764,
PtOsVersion = 23,
SsoVersion = 23,
PackageName = "com.tencent.qq",
WtLoginSdk = "nt.wtlogin.0.0.1",
PackageSign = "V1_WIN_NQ_9.9.2-15962_RDM_B",
AppId = 1600001604,
SubAppId = 537138217,
AppIdQrCode = 537138217,
Expand Down
6 changes: 5 additions & 1 deletion Lagrange.Core/Common/Entity/BotFriend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ internal BotFriend()
Nickname = string.Empty;
Remarks = string.Empty;
PersonalSign = string.Empty;
Qid = string.Empty;
}

internal BotFriend(uint uin,string uid, string nickname, string remarks, string personalSign)
internal BotFriend(uint uin,string uid, string nickname, string remarks, string personalSign, string qid)
{
Uin = uin;
Uid = uid;
Nickname = nickname;
Remarks = remarks;
PersonalSign = personalSign;
Qid = qid;
}

public uint Uin { get; set; }
Expand All @@ -32,6 +34,8 @@ internal BotFriend(uint uin,string uid, string nickname, string remarks, string
public string Remarks { get; set; }

public string PersonalSign { get; set; }

public string Qid { get; set; }

public string Avatar => $"https://q1.qlogo.cn/g?b=qq&nk={Uin}&s=640";
}
11 changes: 7 additions & 4 deletions Lagrange.Core/Common/Entity/BotUserInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ namespace Lagrange.Core.Common.Entity;

public class BotUserInfo
{
internal BotUserInfo(uint uin, string uid, string nickname, DateTime birthday, string city, string country, string school, uint age, DateTime registerTime, uint gender)
internal BotUserInfo(uint uin, string nickname, DateTime birthday, string city, string country, string school, uint age, DateTime registerTime, uint gender, string? qid, uint level)
{
Uin = uin;
Uid = uid;
Avatar = $"https://q1.qlogo.cn/g?b=qq&nk={Uin}&s=640";
Nickname = nickname;
Birthday = birthday;
Expand All @@ -15,12 +14,12 @@ internal BotUserInfo(uint uin, string uid, string nickname, DateTime birthday, s
Age = age;
RegisterTime = registerTime;
Gender = (GenderInfo)gender;
Qid = qid;
Level = level;
}

public uint Uin { get; set; }

internal string Uid { get; set; }

public string Avatar { get; set; }

public string Nickname { get; set; }
Expand All @@ -38,6 +37,10 @@ internal BotUserInfo(uint uin, string uid, string nickname, DateTime birthday, s
public DateTime RegisterTime { get; set; }

public GenderInfo Gender { get; set; }

public string? Qid { get; set; }

public uint Level { get; set; }

public enum GenderInfo
{
Expand Down
6 changes: 6 additions & 0 deletions Lagrange.Core/Common/Interface/Api/GroupExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public static Task<bool> KickGroupMember(this BotContext bot, uint groupUin, uin

public static Task<bool> SetGroupAdmin(this BotContext bot, uint groupUin, uint targetUin, bool isAdmin)
=> bot.ContextCollection.Business.OperationLogic.SetGroupAdmin(groupUin, targetUin, isAdmin);

public static Task<bool> SetGroupBot(this BotContext bot, uint targetUin, uint On, uint groupUin)
=> bot.ContextCollection.Business.OperationLogic.SetGroupBot(targetUin, On, groupUin);

public static Task<bool> SetGroupBotHD(this BotContext bot, uint targetUin, uint groupUin)
=> bot.ContextCollection.Business.OperationLogic.SetGroupBotHD(targetUin, groupUin);

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

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

public static Task<List<string>?> FetchCustomFace(this BotContext bot)
=> bot.ContextCollection.Business.OperationLogic.FetchCustomFace();
Expand Down
21 changes: 15 additions & 6 deletions Lagrange.Core/Event/EventArg/FriendPokeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@ namespace Lagrange.Core.Event.EventArg;

public class FriendPokeEvent : EventBase
{
public uint FriendUin { get; }

public FriendPokeEvent(uint friendUin)
{
FriendUin = friendUin;
public uint OperatorUin { get; }

public uint TargetUin { get; }

public string Action { get; }

public string Suffix { get; }

public FriendPokeEvent(uint operatorUin, uint targetUin, string action, string suffix)
{
OperatorUin = operatorUin;
TargetUin = targetUin;
Action = action;
Suffix = suffix;

EventMessage = $"{nameof(FriendPokeEvent)}: {FriendUin}";
EventMessage = $"{nameof(FriendPokeEvent)}: OperatorUin: {OperatorUin} | TargetUin: {TargetUin} | Action: {Action} | Suffix: {Suffix}";
}
}
5 changes: 4 additions & 1 deletion Lagrange.Core/Event/EventArg/GroupEssenceEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ public class GroupEssenceEvent : EventBase

public uint Sequence { get; }

public uint Random { get; }

public bool IsSet { get; } // 1 设置精华消息, 2 移除精华消息

public uint FromUin { get; }

public uint OperatorUin { get; }

public GroupEssenceEvent(uint groupUin, uint sequence, uint setFlag, uint fromUin, uint operatorUin)
public GroupEssenceEvent(uint groupUin, uint sequence,uint random, uint setFlag, uint fromUin, uint operatorUin)
{
GroupUin = groupUin;
Sequence = sequence;
Random = random;
IsSet = setFlag == 1;
FromUin = fromUin;
OperatorUin = operatorUin;
Expand Down
25 changes: 25 additions & 0 deletions Lagrange.Core/Event/EventArg/GroupPokeEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Lagrange.Core.Event.EventArg;

public class GroupPokeEvent : EventBase
{
public uint GroupUin { get; }

public uint OperatorUin { get; }

public uint TargetUin { get; }

public string Action { get; }

public string Suffix { get; }

public GroupPokeEvent(uint groupUin, uint operatorUin, uint targetUin, string action, string suffix)
{
GroupUin = groupUin;
OperatorUin = operatorUin;
TargetUin = targetUin;
Action = action;
Suffix = suffix;

EventMessage = $"{nameof(GroupPokeEvent)}: GroupUin: {GroupUin} | OperatorUin: {OperatorUin} | TargetUin: {TargetUin} | Action: {Action} | Suffix: {Suffix}";
}
}
4 changes: 4 additions & 0 deletions Lagrange.Core/Event/EventInvoker.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ public partial class EventInvoker
public event LagrangeEvent<DeviceLoginEvent>? OnDeviceLoginEvent;

public event LagrangeEvent<FriendPokeEvent>? OnFriendPokeEvent;

public event LagrangeEvent<GroupPokeEvent>? OnGroupPokeEvent;

public event LagrangeEvent<GroupEssenceEvent>? OnGroupEssenceEvent;
}
2 changes: 2 additions & 0 deletions Lagrange.Core/Event/EventInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ internal EventInvoker(BotContext context)
RegisterEvent((FriendRecallEvent e) => OnFriendRecallEvent?.Invoke(context, e));
RegisterEvent((DeviceLoginEvent e) => OnDeviceLoginEvent?.Invoke(context, e));
RegisterEvent((FriendPokeEvent e) => OnFriendPokeEvent?.Invoke(context, e));
RegisterEvent((GroupPokeEvent e) => OnGroupPokeEvent?.Invoke(context, e));
RegisterEvent((GroupEssenceEvent e) => OnGroupEssenceEvent?.Invoke(context, e));
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Concurrent;
using Lagrange.Core.Common.Entity;
using Lagrange.Core.Internal.Context.Attributes;
using Lagrange.Core.Internal.Event;
Expand All @@ -22,6 +23,8 @@ internal class CachingLogic : LogicBase
private readonly List<BotFriend> _cachedFriends;
private readonly Dictionary<uint, List<BotGroupMember>> _cachedGroupMembers;

private readonly ConcurrentDictionary<uint, BotUserInfo> _cacheUsers;

internal CachingLogic(ContextCollection collection) : base(collection)
{
_uinToUid = new Dictionary<uint, string>();
Expand All @@ -30,6 +33,8 @@ internal CachingLogic(ContextCollection collection) : base(collection)

_cachedFriends = new List<BotFriend>();
_cachedGroupMembers = new Dictionary<uint, List<BotGroupMember>>();

_cacheUsers = new();
}

public override Task Incoming(ProtocolEvent e)
Expand Down Expand Up @@ -96,6 +101,13 @@ public async Task<List<BotFriend>> GetCachedFriends(bool refreshCache)
return _cachedFriends;
}

public async Task<BotUserInfo?> GetCachedUsers(uint uin, bool refreshCache)
{
if (!_cacheUsers.ContainsKey(uin) || refreshCache) await ResolveUser(uin);
if (!_cacheUsers.TryGetValue(uin, out BotUserInfo? info)) return null;
return info;
}

private async Task CacheUid(uint groupUin, bool force = false)
{
if (!_cachedGroups.Contains(groupUin) || force)
Expand All @@ -110,7 +122,7 @@ private async Task ResolveFriendsUid()
{
var fetchFriendsEvent = FetchFriendsEvent.Create();
var events = await Collection.Business.SendEvent(fetchFriendsEvent);

if (events.Count != 0)
{
var @event = (FetchFriendsEvent)events[0];
Expand All @@ -123,7 +135,7 @@ private async Task ResolveFriendsUid()
@event.Friends.AddRange(((FetchFriendsEvent)results[0]).Friends);
nextUin = ((FetchFriendsEvent)results[0]).NextUin;
}

foreach (var friend in @event.Friends) _uinToUid.TryAdd(friend.Uin, friend.Uid);
_cachedFriends.Clear();
_cachedFriends.AddRange(@event.Friends);
Expand Down Expand Up @@ -161,4 +173,14 @@ private async Task ResolveMembersUid(uint groupUin)
Collection.Log.LogWarning(Tag, $"Failed to resolve group {groupUin} members uid and cache.");
}
}

private async Task ResolveUser(uint uin)
{
var events = await Collection.Business.SendEvent(FetchUserInfoEvent.Create(uin));

if (events.Count != 0 && events[0] is FetchUserInfoEvent { } @event)
{
_cacheUsers.AddOrUpdate(uin, @event.UserInfo, (_key, _value) => @event.UserInfo);
}
}
}
Loading

0 comments on commit 07b9b60

Please sign in to comment.