Skip to content

Commit

Permalink
add forward message
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkRRb committed Oct 1, 2024
1 parent b30bc3d commit 2444122
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 9 additions & 3 deletions Lagrange.Kritor/src/Converters/MessageConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Google.Protobuf.Collections;
using Kritor.Common;
using Lagrange.Core;
using Lagrange.Core.Common.Interface.Api;
using Lagrange.Core.Message;
using Lagrange.Core.Message.Entity;
using Lagrange.Kritor.Utilities;
Expand Down Expand Up @@ -260,9 +261,7 @@ public static async Task<MessageBuilder> AddElementAsync(this MessageBuilder bui
Element.Types.ElementType.MarketFace => throw new NotSupportedException(
$"Not supported Element.Types.ElementType({Element.Types.ElementType.MarketFace})"
), // Kritor miss arg
Element.Types.ElementType.Forward => throw new NotSupportedException(
$"Not supported Element.Types.ElementType({Element.Types.ElementType.Forward})"
), // TODO
Element.Types.ElementType.Forward => await builder.AddForwardElementAsync(bot, element.Forward),
Element.Types.ElementType.Contact => throw new NotSupportedException(
$"Not supported Element.Types.ElementType({Element.Types.ElementType.Contact})"
),
Expand Down Expand Up @@ -305,4 +304,11 @@ public static async Task<MessageBuilder> AddElementAsync(this MessageBuilder bui
_ => throw new NotSupportedException($"Not supported Element.Types.ElementType({element.Type})")
};
}

public static async Task<MessageBuilder> AddForwardElementAsync(this MessageBuilder builder, BotContext bot, ForwardElement element) {
(int code, List<MessageChain>? chains) = await bot.GetMessagesByResId(element.ResId);
if (code != 0) throw new Exception($"Get message by res id failed");

return builder.MultiMsg([.. chains]);
}
}
8 changes: 5 additions & 3 deletions Lagrange.Kritor/src/Converters/MessageEventConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static EventStructure ToMessageEvent(this EventBase @event) {
Time = (ulong)new DateTimeOffset(message.Chain.Time).ToUnixTimeSeconds(),
MessageId = MessageIdUtility.BuildPrivateMessageId(message.Chain.FriendUin, message.Chain.Sequence),
MessageSeq = message.Chain.Sequence,
Scene = Scene.Friend,
Private = new PrivateSender {
Uin = message.Chain.FriendUin,
Nick = message.Chain.FriendInfo?.Nickname
Expand All @@ -29,10 +30,11 @@ public static EventStructure ToMessageEvent(this EventBase @event) {
Message = new PushMessageBody {
Time = (ulong)new DateTimeOffset(message.EventTime).ToUnixTimeSeconds(),
MessageId = MessageIdUtility.BuildGroupMessageId(
message.Chain.GroupUin ?? throw new Exception("`GroupMessageEvent.Chain.GroupUin` is null"),
message.Chain.Sequence
),
message.Chain.GroupUin ?? throw new Exception("`GroupMessageEvent.Chain.GroupUin` is null"),
message.Chain.Sequence
),
MessageSeq = message.Chain.Sequence,
Scene = Scene.Friend,
Group = new GroupSender {
GroupId = message.Chain.GroupUin?.ToString()
?? throw new Exception("`GroupMessageEvent.Chain.GroupUin` is null"),
Expand Down

0 comments on commit 2444122

Please sign in to comment.