diff --git a/Lagrange.OneBot/Core/Entity/Message/OneBotGroupMsg.cs b/Lagrange.OneBot/Core/Entity/Message/OneBotGroupMsg.cs index e23694bcb..44a1a3cb9 100644 --- a/Lagrange.OneBot/Core/Entity/Message/OneBotGroupMsg.cs +++ b/Lagrange.OneBot/Core/Entity/Message/OneBotGroupMsg.cs @@ -4,7 +4,7 @@ namespace Lagrange.OneBot.Core.Entity.Message; [Serializable] -public class OneBotGroupMsg(uint selfId, uint groupUin, List message, string rawMessage, BotGroupMember member, int messageId) : OneBotEntityBase(selfId, "message") +public class OneBotGroupMsg(uint selfId, uint groupUin, List message, string rawMessage, BotGroupMember member, int messageId, long time) : OneBotEntityBase(selfId, "message", time) { [JsonPropertyName("message_type")] public string MessageType { get; set; } = "group"; @@ -28,7 +28,7 @@ public class OneBotGroupMsg(uint selfId, uint groupUin, List mess } [Serializable] -public class OneBotGroupStringMsg(uint selfId, uint groupUin, string message, BotGroupMember member, int messageId) : OneBotEntityBase(selfId, "message") +public class OneBotGroupStringMsg(uint selfId, uint groupUin, string message, BotGroupMember member, int messageId, long time) : OneBotEntityBase(selfId, "message", time) { [JsonPropertyName("message_type")] public string MessageType { get; set; } = "group"; diff --git a/Lagrange.OneBot/Core/Entity/Message/OneBotPrivateMsg.cs b/Lagrange.OneBot/Core/Entity/Message/OneBotPrivateMsg.cs index 6506ccc51..69d43ade8 100644 --- a/Lagrange.OneBot/Core/Entity/Message/OneBotPrivateMsg.cs +++ b/Lagrange.OneBot/Core/Entity/Message/OneBotPrivateMsg.cs @@ -3,7 +3,7 @@ namespace Lagrange.OneBot.Core.Entity.Message; [Serializable] -public class OneBotPrivateMsg(uint selfId, OneBotSender groupSender, string subType) : OneBotEntityBase(selfId, "message") +public class OneBotPrivateMsg(uint selfId, OneBotSender groupSender, string subType, long time) : OneBotEntityBase(selfId, "message", time) { [JsonPropertyName("message_type")] public string MessageType { get; set; } = "private"; @@ -25,7 +25,7 @@ public class OneBotPrivateMsg(uint selfId, OneBotSender groupSender, string subT } [Serializable] -public class OneBotPrivateStringMsg(uint selfId, OneBotSender groupSender, string subType) : OneBotEntityBase(selfId, "message") +public class OneBotPrivateStringMsg(uint selfId, OneBotSender groupSender, string subType, long time) : OneBotEntityBase(selfId, "message", time) { [JsonPropertyName("message_type")] public string MessageType { get; set; } = "private"; diff --git a/Lagrange.OneBot/Core/Entity/OneBotEntityBase.cs b/Lagrange.OneBot/Core/Entity/OneBotEntityBase.cs index 7f559b882..b48886081 100644 --- a/Lagrange.OneBot/Core/Entity/OneBotEntityBase.cs +++ b/Lagrange.OneBot/Core/Entity/OneBotEntityBase.cs @@ -3,9 +3,14 @@ namespace Lagrange.OneBot.Core.Entity; [Serializable] -public abstract class OneBotEntityBase(uint selfId, string postType) +public abstract class OneBotEntityBase(uint selfId, string postType, long time) { - [JsonPropertyName("time")] public long Time { get; set; } = DateTimeOffset.Now.ToUnixTimeSeconds(); + public OneBotEntityBase(uint selfId, string postType) + : this(selfId, postType, DateTimeOffset.Now.ToUnixTimeSeconds()) + { + } + + [JsonPropertyName("time")] public long Time { get; set; } = time; [JsonPropertyName("self_id")] public uint SelfId { get; set; } = selfId; diff --git a/Lagrange.OneBot/Message/MessageService.cs b/Lagrange.OneBot/Message/MessageService.cs index fe3ed4dc5..c59a853b0 100644 --- a/Lagrange.OneBot/Message/MessageService.cs +++ b/Lagrange.OneBot/Message/MessageService.cs @@ -79,14 +79,14 @@ public object ConvertToPrivateMsg(uint uin, MessageChain chain) var segments = Convert(chain); int hash = MessageRecord.CalcMessageHash(chain.MessageId, chain.Sequence); string raw = ToRawMessage(segments); - object request = _stringPost ? new OneBotPrivateStringMsg(uin, new OneBotSender(chain.FriendUin, chain.FriendInfo?.Nickname ?? string.Empty), "friend") + object request = _stringPost ? new OneBotPrivateStringMsg(uin, new OneBotSender(chain.FriendUin, chain.FriendInfo?.Nickname ?? string.Empty), "friend", ((DateTimeOffset)chain.Time).ToUnixTimeSeconds()) { MessageId = hash, UserId = chain.FriendUin, Message = raw, RawMessage = raw, TargetId = chain.TargetUin, - } : new OneBotPrivateMsg(uin, new OneBotSender(chain.FriendUin, chain.FriendInfo?.Nickname ?? string.Empty), "friend") + } : new OneBotPrivateMsg(uin, new OneBotSender(chain.FriendUin, chain.FriendInfo?.Nickname ?? string.Empty), "friend", ((DateTimeOffset)chain.Time).ToUnixTimeSeconds()) { MessageId = hash, UserId = chain.FriendUin, @@ -113,8 +113,8 @@ public object ConvertToGroupMsg(uint uin, MessageChain chain) var segments = Convert(chain); int hash = MessageRecord.CalcMessageHash(chain.MessageId, chain.Sequence); object request = _stringPost - ? new OneBotGroupStringMsg(uin, chain.GroupUin ?? 0, ToRawMessage(segments), chain.GroupMemberInfo ?? throw new Exception("Group member not found"), hash) - : new OneBotGroupMsg(uin, chain.GroupUin ?? 0, segments, ToRawMessage(segments), chain.GroupMemberInfo ?? throw new Exception("Group member not found"), hash); + ? new OneBotGroupStringMsg(uin, chain.GroupUin ?? 0, ToRawMessage(segments), chain.GroupMemberInfo ?? throw new Exception("Group member not found"), hash, ((DateTimeOffset)chain.Time).ToUnixTimeSeconds()) + : new OneBotGroupMsg(uin, chain.GroupUin ?? 0, segments, ToRawMessage(segments), chain.GroupMemberInfo ?? throw new Exception("Group member not found"), hash, ((DateTimeOffset)chain.Time).ToUnixTimeSeconds()); return request; } @@ -124,7 +124,7 @@ private void OnTempMessageReceived(BotContext bot, TempMessageEvent e) _context.GetCollection().Insert(new BsonValue(record.MessageHash), record); var segments = Convert(e.Chain); - var request = new OneBotPrivateMsg(bot.BotUin, new OneBotSender(e.Chain.FriendUin, e.Chain.FriendInfo?.Nickname ?? string.Empty), "group") + var request = new OneBotPrivateMsg(bot.BotUin, new OneBotSender(e.Chain.FriendUin, e.Chain.FriendInfo?.Nickname ?? string.Empty), "group", ((DateTimeOffset)e.Chain.Time).ToUnixTimeSeconds()) { MessageId = record.MessageHash, UserId = e.Chain.FriendUin,