Skip to content

Commit

Permalink
完善 get_stranger_info
Browse files Browse the repository at this point in the history
  • Loading branch information
sisi0318 committed Oct 10, 2024
1 parent 796dd7c commit b017d29
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 26 deletions.
30 changes: 18 additions & 12 deletions 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, DateTime birthday, string city, string country, string school, uint age, DateTime registerTime, uint gender, string? qid, uint level)
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)
{
Uin = uin;
Avatar = $"https://q1.qlogo.cn/g?b=qq&nk={Uin}&s=640";
Expand All @@ -17,32 +17,38 @@ internal BotUserInfo(uint uin, string nickname, DateTime birthday, string city,
Gender = (GenderInfo)gender;
Qid = qid;
Level = level;
Sign = sign;
Status = status;
}

public uint Uin { get; set; }

public string Avatar { get; set; }

public string Nickname { get; set; }

public DateTime Birthday { get; set; }

public string City { get; set; }

public string Country { get; set; }

public string School { get; set; }

public uint Age { get; set; }

public DateTime RegisterTime { get; set; }

public GenderInfo Gender { get; set; }

public string? Qid { get; set; }

public uint Level { get; set; }

public string Sign { get; set; }

public uint Status { get; set; }

public enum GenderInfo
{
Unset = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected override bool Parse(Span<byte> input, BotKeystore keystore, BotAppInfo
var birthday = GetBirthday(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]);
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]);

output = FetchUserInfoEvent.Result(0, info);
extraEvents = null;
Expand Down
17 changes: 13 additions & 4 deletions Lagrange.Core/Message/Entity/GreyTipEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@ namespace Lagrange.Core.Message.Entity;
public class GreyTipEntity : IMessageEntity
{
public string GreyTip { get; }
public uint ObjectType { get; } = 3;
public uint SubType { get; } = 2;
public uint Type { get; } = 4;

public GreyTipEntity(string greyTip) => GreyTip = greyTip;
public GreyTipEntity(string greyTip , uint objectType, uint subType, uint type)
{
GreyTip = greyTip;
ObjectType = objectType;
SubType = subType;
Type = type;
}

public GreyTipEntity() => GreyTip = string.Empty;

Expand All @@ -20,9 +29,9 @@ IEnumerable<Elem> IMessageEntity.PackElement()
var content = new GreyTipContent
{
GrayTip = GreyTip,
ObjectType = 3,
SubType = 2,
Type = 4
ObjectType = ObjectType,
SubType = SubType,
Type = Type
};

var extra = new GreyTipExtra
Expand Down
6 changes: 3 additions & 3 deletions Lagrange.Core/Message/MessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ public MessageBuilder MarketFace(string faceId, int tabId, string key, string su
return this;
}

public MessageBuilder GeryTip(string greyTip)
public MessageBuilder greytip(string greyTip, uint objectType = 3, uint subType = 2, uint type = 4)
{
var greyTipEntity = new GreyTipEntity(greyTip);
var greyTipEntity = new GreyTipEntity(greyTip, objectType, subType, type);
_chain.Add(greyTipEntity);

return this;
}

Expand Down
12 changes: 12 additions & 0 deletions Lagrange.OneBot/Core/Entity/OneBotStranger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@ public class OneBotStranger
{
[JsonPropertyName("user_id")] public uint UserId { get; set; }

[JsonPropertyName("avatar")] public string Avatar { get; set; } = string.Empty;

[JsonPropertyName("q_id")] public string? QId { get; set; }

[JsonPropertyName("nickname")] public string NickName { get; set; } = string.Empty;

[JsonPropertyName("sign")] public string Sign { get; set; } = string.Empty;

[JsonPropertyName("sex")] public string Sex { get; set; } = "unknown";

[JsonPropertyName("age")] public uint Age { get; set; }

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

[JsonPropertyName("status")] public uint Status { get; set; }

[JsonPropertyName("status_msg")] public string StatusMsg { get; set; } = "未知状态";

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


}
59 changes: 58 additions & 1 deletion Lagrange.OneBot/Core/Operation/Info/GetStrangerInfoOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,75 @@ public class GetStrangerInfoOperation : IOperation
{
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
{
var StatusArray = new Dictionary<uint, string>
{
{ 1, "在线" },
{ 3, "离开" },
{ 4, "隐身/离线" },
{ 5, "忙碌" },
{ 6, "Q我吧" },
{ 7, "请勿打扰" },
{ 263169, "听歌中" },
{ 15205121, "我的电量" },
{ 16713473, "做好事" },
{ 13829889, "出去浪" },
{ 14616321, "去旅行" },
{ 14550785, "被掏空" },
{ 14747393, "今日步数" },
{ 394241, "今日天气" },
{ 14878465, "我crush了" },
{ 14026497, "爱你" },
{ 1770497, "恋爱中" },
{ 3081217, "好运锦鲤" },
{ 11600897, "水逆退散" },
{ 2098177, "嗨到飞起" },
{ 2229249, "元气满满" },
{ 2556929, "一言难尽" },
{ 13698817, "难得糊涂" },
{ 7931137, "emo中" },
{ 2491393, "我太难了" },
{ 14485249, "我想开了" },
{ 1836033, "我没事" },
{ 2425857, "想静静" },
{ 2294785, "悠哉哉" },
{ 15926017, "信号弱" },
{ 16253697, "睡觉中" },
{ 14419713, "肝作业" },
{ 16384769, "学习中" },
{ 15140609, "搬砖中" },
{ 1312001, "摸鱼中" },
{ 2360321, "无聊中" },
{ 197633, "timi中" },
{ 15271681, "一起元梦" },
{ 15337217, "求星搭子" },
{ 525313, "熬夜中" },
{ 16581377, "追剧中" },
{ 13633281, "自定义状态"}
};
if (payload.Deserialize<OneBotGetStrangerInfo>(SerializerOptions.DefaultOptions) is { } stranger)
{
if (await context.FetchUserInfo(stranger.UserId, stranger.NoCache) is { } info)
{

uint status = info.Status;
if (status >= 268435456)
{
status -= 268435456;
}
string? Statusmsg = StatusArray.TryGetValue(status, out string? value) ? value : "未知状态";
return new OneBotResult(new OneBotStranger
{
UserId = info.Uin,
Avatar = info.Avatar,
QId = info.Qid,
NickName = info.Nickname,
Sex = info.Gender.ToOneBotString(),
Age = info.Age,
Level = info.Level
Level = info.Level,
Sign = info.Sign ?? string.Empty,
Status = info.Status,
StatusMsg = Statusmsg,
RegisterTime = info.RegisterTime
}, 0, "ok");
}

Expand Down
14 changes: 9 additions & 5 deletions Lagrange.OneBot/Message/Entity/GreyTipSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
namespace Lagrange.OneBot.Message.Entity;

[Serializable]
public partial class GreyTipSegment(string content)
public partial class GreyTipSegment(string content, uint objectType, uint subType, uint type)
{
public GreyTipSegment(): this("") {}

[JsonPropertyName("content")] [CQProperty] public string Content { get; set; } = content;
public GreyTipSegment() : this("", 3, 2, 4) { }

[JsonPropertyName("content")][CQProperty] public string Content { get; set; } = content;
[JsonPropertyName("object_type")][CQProperty] public uint ObjectType { get; set; } = objectType;
[JsonPropertyName("sub_type")][CQProperty] public uint SubType { get; set; } = subType;
[JsonPropertyName("type")][CQProperty] public uint Type { get; set; } = type;

}

[SegmentSubscriber(typeof(GreyTipEntity), "greytip")]
public partial class GreyTipSegment : SegmentBase
{
public override void Build(MessageBuilder builder, SegmentBase segment)
{
if (segment is GreyTipSegment greyTip) builder.GeryTip(greyTip.Content);
if (segment is GreyTipSegment greyTip) builder.greytip(greyTip.Content, greyTip.ObjectType, greyTip.SubType, greyTip.Type);
}

public override SegmentBase? FromEntity(MessageChain chain, IMessageEntity entity)
Expand Down

0 comments on commit b017d29

Please sign in to comment.