Skip to content

Commit 64ca36a

Browse files
committed
fix: 修复 at 全体成员的崩溃 bug
1 parent 2ba513c commit 64ca36a

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/EleCho.GoCqHttpSdk/Message/CqAtMsg.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,27 @@ namespace EleCho.GoCqHttpSdk.Message
99
/// </summary>
1010
public record class CqAtMsg : CqMsg
1111
{
12+
/// <summary>
13+
/// 消息类型: @
14+
/// </summary>
1215
public override string MsgType => Consts.MsgType.At;
1316

1417
/// <summary>
1518
/// 说明: @的 QQ 号, all 表示全体成员
1619
/// 可能的值: QQ 号, all
1720
/// </summary>
18-
public long QQ { get; set; }
21+
public long QQ { get; set; } = -1;
1922

23+
/// <summary>
24+
/// 名称
25+
/// </summary>
2026
public string? Name { get; set; }
2127

28+
/// <summary>
29+
/// 是 AT 全体成员
30+
/// </summary>
31+
public bool IsAtAll { get; set; }
32+
2233
internal CqAtMsg()
2334
{ }
2435

@@ -27,19 +38,28 @@ public CqAtMsg(long qq)
2738
QQ = qq;
2839
}
2940

41+
/// <summary>
42+
/// 获取 AT 所有人的消息段
43+
/// </summary>
44+
public static CqAtMsg AtAll => new CqAtMsg() { IsAtAll = true };
45+
3046
internal override void ReadDataModel(CqMsgDataModel? model)
3147
{
3248
CqAtMsgDataModel? m = model as CqAtMsgDataModel;
3349
if (m == null)
3450
throw new ArgumentException();
3551

36-
QQ = long.Parse(m.qq);
52+
if (long.TryParse(m.qq, out long _qq))
53+
QQ = _qq;
54+
else if (m.qq.Equals("all", StringComparison.OrdinalIgnoreCase))
55+
IsAtAll = true;
56+
3757
Name = m.name;
3858
}
3959

4060
internal override CqMsgDataModel? GetDataModel()
4161
{
42-
return new CqAtMsgDataModel(QQ.ToString(), Name);
62+
return new CqAtMsgDataModel(IsAtAll ? "all" : QQ.ToString(), Name);
4363
}
4464
}
4565
}

0 commit comments

Comments
 (0)