Skip to content

Commit

Permalink
[OneBot] Fixed bug that ReplySegment.cs may not be received when targ…
Browse files Browse the repository at this point in the history
…et msg is not in Database
  • Loading branch information
Linwenxuan04 committed Feb 24, 2024
1 parent 0d423cf commit e2feeb5
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions Lagrange.OneBot/Message/Entity/ReplySegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public override void Build(MessageBuilder builder, SegmentBase segment)
public override SegmentBase FromEntity(MessageChain chain, IMessageEntity entity)
{
if (entity is not ForwardEntity forward || Database is null) throw new ArgumentException("The entity is not a forward entity.");


var collection = Database.GetCollection<MessageRecord>();

Expand All @@ -42,11 +41,10 @@ public override SegmentBase FromEntity(MessageChain chain, IMessageEntity entity
var query = chain.IsGroup
? collection.Query().Where(x => x.Sequence == forward.Sequence).Where(x => x.GroupUin == groupUin)
: collection.Query().Where(x => x.Sequence == forward.Sequence).Where(x => x.FriendUin == friendUin);
var target = query.First();
var target = query.FirstOrDefault();

return new ReplySegment
{
MessageId = target.MessageHash.ToString()
};
return target == null
? new ReplySegment { MessageId = 0.ToString() }
: new ReplySegment { MessageId = target.MessageHash.ToString() };
}
}

0 comments on commit e2feeb5

Please sign in to comment.