Skip to content

Commit

Permalink
修正自定义状态
Browse files Browse the repository at this point in the history
  • Loading branch information
sisi0318 committed Oct 11, 2024
1 parent 99f2b2e commit 45d216d
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 13 deletions.
8 changes: 6 additions & 2 deletions Lagrange.Core/Common/Entity/BotUserInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ namespace Lagrange.Core.Common.Entity;
[Serializable]
public class BotUserInfo
{
internal BotUserInfo(uint uin, string nickname, DateTime birthday, string city, string country, string school, uint age, DateTime registerTime, uint gender, string? qid, uint level, string sign,uint status)
internal BotUserInfo(uint uin, string nickname, string avatar, DateTime birthday, string city, string country, string school, uint age, DateTime registerTime, uint gender, string? qid, uint level, string sign, uint status, object[] customarray)
{
Uin = uin;
Avatar = $"https://q1.qlogo.cn/g?b=qq&nk={Uin}&s=640";
Avatar = avatar;
// Avatar = $"https://q1.qlogo.cn/g?b=qq&nk={Uin}&s=640";
Nickname = nickname;
Birthday = birthday;
City = city;
Expand All @@ -19,6 +20,7 @@ internal BotUserInfo(uint uin, string nickname, DateTime birthday, string city,
Level = level;
Sign = sign;
Status = status;
Customarray = customarray;
}

public uint Uin { get; set; }
Expand Down Expand Up @@ -49,6 +51,8 @@ internal BotUserInfo(uint uin, string nickname, DateTime birthday, string city,

public uint Status { get; set; }

public object[] Customarray { get; set; }

public enum GenderInfo
{
Unset = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ internal class OidbFriendProperty
[ProtoMember(1)] public uint Code { get; set; }

[ProtoMember(2)] public string Value { get; set; }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using ProtoBuf;

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

#pragma warning disable CS8618

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

[ProtoMember(2)] public byte[] Value { get; set; }

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ internal class OidbSvcTrpcTcp0xFE1_2ResponseProperty
{
[ProtoMember(1)] public List<OidbTwoNumber> NumberProperties { get; set; }

[ProtoMember(2)] public List<OidbFriendProperty> StringProperties { get; set; }
}
[ProtoMember(2)] public List<OidbFriendPropertybyte> StringProperties { get; set; }

}

66 changes: 57 additions & 9 deletions Lagrange.Core/Internal/Service/System/FetchUserInfoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ protected override bool Build(FetchUserInfoEvent input, BotKeystore keystore, Bo
{
var keys = new List<uint> { 20002, 27394, 20009, 20031, 101, 103, 102, 20022, 20023, 20024, 24002, 27037, 27049, 20011, 20016, 20021, 20003, 20004, 20005, 20006, 20020, 20026, 24007, 104, 105, 42432, 42362, 41756, 41757, 42257, 27372, 42315, 107, 45160, 45161, 27406, 62026, 20037 };

// 27406 自定义状态文本
// 27372 状态

object packet = input.Uid == null
? new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0xFE1_2Uin>(new OidbSvcTrpcTcp0xFE1_2Uin
{
Uin = input.Uin,
Field2 = 0,
Keys = keys.Select(x => new OidbSvcTrpcTcp0xFE1_2Key { Key = x }).ToList()
}, 0xfe1, 2, false, true)
}, 0xfe1, 2, false, true)
: new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0xFE1_2>(new OidbSvcTrpcTcp0xFE1_2
{
Uid = input.Uid,
Expand All @@ -44,14 +47,44 @@ protected override bool Parse(Span<byte> input, BotKeystore keystore, BotAppInfo
out FetchUserInfoEvent output, out List<ProtocolEvent>? extraEvents)
{
var payload = Serializer.Deserialize<OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0xFE1_2Response>>(input);

var str = GetStringProperties(payload.Body.Body.Properties);
var num = GetNumberProperties(payload.Body.Body.Properties);

var birthday = GetBirthday(str[20031]);
//如果是嵌套proto就Serializer.Deserialize(Value)如果是String就Encoding.UTF8.GetString(Value)

var birthday = GetBirthday(Encoding.UTF8.GetString(str[20031]));
var reg = DateTime.UnixEpoch.AddSeconds(num[20026]);
string? qid = str.GetValueOrDefault<uint, string>(27394);
var info = new BotUserInfo(payload.Body.Body.Uin, str[20002], birthday, str[20020], str[20003], str[20021], num[20037], reg, num[20009], qid, num[105] , str[102] , num[27372]);

string? qid = Encoding.UTF8.GetString(str[27394]);

byte[] custom = str[27406];

CustomStatus customs;
using (var stream = new MemoryStream(custom))
{
customs = Serializer.Deserialize<CustomStatus>(stream);
}
object[] customarray = new object[] { customs.FaceId, customs.Msg ?? "" };

byte[] avatar = str[101];
Avatar avatars;
using (var stream = new MemoryStream(avatar))
{
avatars = Serializer.Deserialize<Avatar>(stream);
}
string? avatarurl = avatars.Url + "640";


string? nickname = Encoding.UTF8.GetString(str[20002]);
string? city = Encoding.UTF8.GetString(str[20020]);
string? country = Encoding.UTF8.GetString(str[20003]);
string? school = Encoding.UTF8.GetString(str[20021]);
string? sign = Encoding.UTF8.GetString(str[102]);



var info = new BotUserInfo(payload.Body.Body.Uin, nickname, avatarurl, birthday, city, country, school, num[20037], reg, num[20009], qid, num[105], sign, num[27372], customarray);

output = FetchUserInfoEvent.Result(0, info);
extraEvents = null;
Expand All @@ -70,18 +103,18 @@ private static DateTime GetBirthday(String birthday)
}
return new DateTime(1970, 1, 1);
}
private static Dictionary<uint, string> GetStringProperties(OidbSvcTrpcTcp0xFE1_2ResponseProperty properties)

private static Dictionary<uint, byte[]> GetStringProperties(OidbSvcTrpcTcp0xFE1_2ResponseProperty properties)
{
var result = new Dictionary<uint, string>();
var result = new Dictionary<uint, byte[]>();
foreach (var property in properties.StringProperties)
{
result[property.Code] = property.Value;
}

return result;
}

private static Dictionary<uint, uint> GetNumberProperties(OidbSvcTrpcTcp0xFE1_2ResponseProperty properties)
{
var result = new Dictionary<uint, uint>();
Expand All @@ -92,4 +125,19 @@ private static Dictionary<uint, uint> GetNumberProperties(OidbSvcTrpcTcp0xFE1_2R

return result;
}

[ProtoContract]
public class CustomStatus
{
[ProtoMember(1)] public uint FaceId { get; set; }

[ProtoMember(2)] public string? Msg { get; set; }
}

[ProtoContract]
public class Avatar
{
[ProtoMember(5)] public string? Url { get; set; }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? pa
mask = (uint)((int)mask >> 31);
status -= 268435456 & mask;
string? Statusmsg = StatusArray.TryGetValue(status, out string? value) ? value : "未知状态";

if (status == 13633281)
{
Statusmsg = "[自定义状态]" + info.Customarray[1];
}
return new OneBotResult(new OneBotStranger
{
UserId = info.Uin,
Expand Down

0 comments on commit 45d216d

Please sign in to comment.