Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] get_stranger_info 补充业务信息 #683

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Lagrange.Core/Common/Entity/BotBusiness.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Lagrange.Core.Common.Entity
{
public class BusinessCustom
{
public uint Type;

public uint Level;

public string? Icon;

public uint IsYear;

public uint IsPro;
}

public class BusinessCustomList
{
public List<BusinessCustom> BusinessLists { get; set; }

public BusinessCustomList(List<BusinessCustom> businessLists)
{
BusinessLists = businessLists;
}
}
}
5 changes: 4 additions & 1 deletion Lagrange.Core/Common/Entity/BotUserInfo.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 BotUserInfo
{
internal BotUserInfo(uint uin, string nickname, string avatar, DateTime birthday, string city, string country, string school, uint age, DateTime registerTime, GenderInfo gender, string? qid, uint level, string sign, BotStatus status)
internal BotUserInfo(uint uin, string nickname, string avatar, DateTime birthday, string city, string country, string school, uint age, DateTime registerTime, GenderInfo gender, string? qid, uint level, string sign, BotStatus status, List<BusinessCustom> business)
{
Uin = uin;
Avatar = avatar;
Expand All @@ -20,6 +20,7 @@ internal BotUserInfo(uint uin, string nickname, string avatar, DateTime birthday
Level = level;
Sign = sign;
Status = status;
Business = business;
}

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

public BotStatus Status { get; set; }

public List<BusinessCustom> Business { get; set; }

public enum GenderInfo
{
Unset = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,39 @@ public class CustomStatus
public class Avatar
{
[ProtoMember(5)] public string? Url { get; set; }
}

[ProtoContract]
public class Business
{
[ProtoMember(3)] public BusinessBody? Body { get; set; }
}

[ProtoContract]
public class BusinessBody
{
[ProtoMember(1)] public string? Msg { get; set; }

[ProtoMember(3)] public List<BusinessList>? Lists { get; set; }
}

[ProtoContract]
public class BusinessList
{
[ProtoMember(1)] public uint Type { get; set; }

[ProtoMember(2)] internal uint Field2 { get; set; }

[ProtoMember(3)] public uint IsYear { get; set; } // 是否年费

[ProtoMember(4)] public uint Level { get; set; }

[ProtoMember(5)] public uint IsPro { get; set; } // 是否为超级

[ProtoMember(6)] internal string? Icon1 { get; set; }

[ProtoMember(7)] internal string? Icon2 { get; set; }

public string? Icon => !string.IsNullOrEmpty(Icon1) ? Icon1 : Icon2;

}
67 changes: 35 additions & 32 deletions Lagrange.Core/Internal/Service/System/FetchUserInfoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ internal class FetchUserInfoService : BaseService<FetchUserInfoEvent>
{
private static readonly List<OidbSvcTrpcTcp0xFE1_2Key> _keys = new()
{
new() { Key = 20002 },
new() { Key = 27394 },
new() { Key = 20009 },
new() { Key = 20031 },
new() { Key = 101 },
new() { Key = 20002 }, //昵称
new() { Key = 27394 }, //QID
new() { Key = 20009 }, //性别
new() { Key = 20031 }, //生日
new() { Key = 101 }, //头像
new() { Key = 103 },
new() { Key = 102 },
new() { Key = 102 }, //简介/签名
new() { Key = 20022 },
new() { Key = 20023 },
new() { Key = 20024 },
Expand All @@ -34,36 +34,34 @@ internal class FetchUserInfoService : BaseService<FetchUserInfoEvent>
new() { Key = 27049 },
new() { Key = 20011 },
new() { Key = 20016 },
new() { Key = 20021 },
new() { Key = 20003 },
new() { Key = 20021 }, //学校
new() { Key = 20003 }, //国家
new() { Key = 20004 },
new() { Key = 20005 },
new() { Key = 20006 },
new() { Key = 20020 },
new() { Key = 20026 },
new() { Key = 20020 }, //城市
new() { Key = 20026 }, //注册时间
new() { Key = 24007 },
new() { Key = 104 },
new() { Key = 105 },
new() { Key = 105 }, //等级
new() { Key = 42432 },
new() { Key = 42362 },
new() { Key = 41756 },
new() { Key = 41757 },
new() { Key = 42257 },
new() { Key = 27372 },
new() { Key = 27372 }, //状态
new() { Key = 42315 },
new() { Key = 107 },
new() { Key = 107 }, //业务列表
new() { Key = 45160 },
new() { Key = 45161 },
new() { Key = 27406 },
new() { Key = 27406 }, //自定义状态文本
new() { Key = 62026 },
new() { Key = 20037 }
new() { Key = 20037 } //年龄
};

protected override bool Build(FetchUserInfoEvent input, BotKeystore keystore, BotAppInfo appInfo,
BotDeviceInfo device, out Span<byte> output, out List<Memory<byte>>? extraPackets)
{
// 27406 自定义状态文本
// 27372 状态

output = input.Uid == null
? new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0xFE1_2Uin>(new OidbSvcTrpcTcp0xFE1_2Uin
Expand Down Expand Up @@ -100,19 +98,23 @@ protected override bool Parse(Span<byte> input, BotKeystore keystore, BotAppInfo
mask = (uint)((int)mask >> 31);
statusId -= 268435456 & mask;

CustomStatus? customs = null;
if (bytesProperties[27406].Length != 0)
{
using var stream = new MemoryStream(bytesProperties[27406]);
customs = Serializer.Deserialize<CustomStatus>(stream);
}

Avatar avatars;
using (var stream = new MemoryStream(bytesProperties[101]))
{
avatars = Serializer.Deserialize<Avatar>(stream);
}
string? avatarurl = avatars.Url + "0";
var customs = bytesProperties[27406].Length != 0
? Serializer.Deserialize<CustomStatus>(new MemoryStream(bytesProperties[27406]))
: null;

var avatars = Serializer.Deserialize<Avatar>(new MemoryStream(bytesProperties[101]));

var business = Serializer.Deserialize<Business>(new MemoryStream(bytesProperties[107]));
var businessA = (business.Body?.Lists ?? new())
.Select(b => new BusinessCustom
{
Type = b.Type,
Level = b.Level,
Icon = b.Icon,
IsPro = b.IsPro,
IsYear = b.IsYear
})
.ToList();

string? nickname = Encoding.UTF8.GetString(bytesProperties[20002]);
string? city = Encoding.UTF8.GetString(bytesProperties[20020]);
Expand All @@ -123,7 +125,7 @@ protected override bool Parse(Span<byte> input, BotKeystore keystore, BotAppInfo
var info = new BotUserInfo(
payload.Body.Body.Uin,
nickname,
avatarurl,
$"{avatars.Url}640",
birthday,
city,
country,
Expand All @@ -139,7 +141,8 @@ protected override bool Parse(Span<byte> input, BotKeystore keystore, BotAppInfo
StatusId = statusId,
FaceId = customs?.FaceId ?? 0,
Msg = customs?.Msg
}
},
businessA
);

output = FetchUserInfoEvent.Result(0, info);
Expand Down
3 changes: 3 additions & 0 deletions Lagrange.OneBot/Core/Entity/OneBotStranger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using Lagrange.Core.Common.Entity;

namespace Lagrange.OneBot.Core.Entity;

Expand All @@ -24,4 +25,6 @@ public class OneBotStranger
[JsonPropertyName("status")] public OneBotFriendStatus Status { get; set; } = new();

[JsonPropertyName("RegisterTime")] public DateTime RegisterTime { get; set; }

[JsonPropertyName("Business")] public List<OneBotBusiness> Business { get; set; } = new();
}
20 changes: 20 additions & 0 deletions Lagrange.OneBot/Core/Entity/OnebotBusiness.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Text.Json.Serialization;
using Lagrange.Core.Common.Entity;

namespace Lagrange.OneBot.Core.Entity;

[Serializable]
public class OneBotBusiness
{
[JsonPropertyName("type")] public uint Type { get; set; }

[JsonPropertyName("name")] public string? Name { get; set; }

[JsonPropertyName("level")] public uint Level { get; set; }

[JsonPropertyName("icon")] public string? Icon { get; set; }

[JsonPropertyName("ispro")] public uint IsPro { get; set; }

[JsonPropertyName("isyear")] public uint IsYear { get; set; }
}
35 changes: 34 additions & 1 deletion Lagrange.OneBot/Core/Operation/Info/GetStrangerInfoOperation.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Text.Json;
using System.Text.Json.Nodes;
using Lagrange.Core;
using Lagrange.Core.Common.Entity;
using Lagrange.Core.Common.Interface.Api;
using Lagrange.OneBot.Core.Entity;
using Lagrange.OneBot.Core.Entity.Action;
Expand Down Expand Up @@ -58,6 +59,24 @@ public class GetStrangerInfoOperation : IOperation
{ 13633281, "自定义状态"}
};

private static readonly Dictionary<uint, string> _BusinessName = new()
{
{ 113, "QQ大会员" },
{ 1, "QQ会员" },
{ 102, "黄钻" },
{ 117, "QQ集卡" },
{ 119, "情侣会员" },
{ 103, "绿钻" },
{ 4, "腾讯视频" },
{ 108, "大王超级会员" },
{ 104, "情侣个性钻" },
{ 105, "微云会员"},
{ 101, "红钻"},
{ 115, "cf游戏特权"},
{ 118, "蓝钻"},
{ 107, "SVIP+腾讯视频"}
};

public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
{
if (payload.Deserialize<OneBotGetStrangerInfo>(SerializerOptions.DefaultOptions) is { } stranger)
Expand All @@ -82,12 +101,26 @@ public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? pa
? _statusMessage.GetValueOrDefault(info.Status.StatusId)
: info.Status.Msg
},
RegisterTime = info.RegisterTime
RegisterTime = info.RegisterTime,
Business = BusinessList(info.Business)
}, 0, "ok");
}

return new OneBotResult(null, -1, "failed");
}
throw new Exception();
}

private List<OneBotBusiness> BusinessList(List<BusinessCustom> businessCustomList)
{
return businessCustomList.Select(b => new OneBotBusiness
{
Type = b.Type,
Name = (b.IsPro == 1 ? "超级" : "") + (_BusinessName.GetValueOrDefault(b.Type) ?? "未知"),
Level = b.Level,
Icon = b.Icon,
IsPro = b.IsPro,
IsYear = b.IsYear
}).ToList();
}
}
Loading