Skip to content

Commit

Permalink
[Onebot] Fixed message time in get_xxx_msg_history.
Browse files Browse the repository at this point in the history
  • Loading branch information
XeronOwO committed Jan 10, 2025
1 parent 20c2b10 commit 61a1f00
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Lagrange.OneBot/Core/Entity/Message/OneBotGroupMsg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Lagrange.OneBot.Core.Entity.Message;

[Serializable]
public class OneBotGroupMsg(uint selfId, uint groupUin, List<OneBotSegment> message, string rawMessage, BotGroupMember member, int messageId) : OneBotEntityBase(selfId, "message")
public class OneBotGroupMsg(uint selfId, uint groupUin, List<OneBotSegment> message, string rawMessage, BotGroupMember member, int messageId, long time) : OneBotEntityBase(selfId, "message", time)
{
[JsonPropertyName("message_type")] public string MessageType { get; set; } = "group";

Expand All @@ -28,7 +28,7 @@ public class OneBotGroupMsg(uint selfId, uint groupUin, List<OneBotSegment> 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";

Expand Down
4 changes: 2 additions & 2 deletions Lagrange.OneBot/Core/Entity/Message/OneBotPrivateMsg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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";

Expand Down
9 changes: 7 additions & 2 deletions Lagrange.OneBot/Core/Entity/OneBotEntityBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions Lagrange.OneBot/Message/MessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

Expand All @@ -124,7 +124,7 @@ private void OnTempMessageReceived(BotContext bot, TempMessageEvent e)
_context.GetCollection<MessageRecord>().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,
Expand Down

0 comments on commit 61a1f00

Please sign in to comment.