Skip to content

Commit

Permalink
[OneBot] Try to support node
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan authored and Linwenxuan committed Nov 9, 2023
1 parent 504758a commit c6eeaa5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
16 changes: 16 additions & 0 deletions Lagrange.Core/Message/MessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ public MessageBuilder Image(byte[] file)
return this;
}

public MessageBuilder File(byte[] file, string fileName)
{
var fileEntity = new FileEntity(file, fileName);
_chain.Add(fileEntity);

return this;
}

public MessageBuilder File(string filePath)
{
var fileEntity = new FileEntity(filePath);
_chain.Add(fileEntity);

return this;
}

public MessageBuilder Add(IMessageEntity entity)
{
_chain.Add(entity);
Expand Down
7 changes: 5 additions & 2 deletions Lagrange.OneBot/Core/Message/Entity/ForwardSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ public ForwardSegment() : this("") { }
[JsonPropertyName("id")] public string Name { get; set; } = name;
}

[SegmentSubscriber(typeof(MultiMsgEntity), "forward")]
[SegmentSubscriber(typeof(MultiMsgEntity), "forward", "node")]
public partial class ForwardSegment : ISegment
{
public IMessageEntity ToEntity() => throw new InvalidOperationException("Only Receive but not send");

public void Build(MessageBuilder builder, ISegment segment) => throw new InvalidOperationException();
public void Build(MessageBuilder builder, ISegment segment)
{
if (segment is ForwardSegment forward) builder.Add(new MultiMsgEntity(forward.Name));
}

public ISegment FromEntity(IMessageEntity entity)
{
Expand Down
4 changes: 3 additions & 1 deletion Lagrange.OneBot/Core/Message/SegmentSubscriberAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace Lagrange.OneBot.Core.Message;

[AttributeUsage(AttributeTargets.Class)]
public class SegmentSubscriberAttribute(Type entity, string type) : Attribute
public class SegmentSubscriberAttribute(Type entity, string type, string? sendType = null) : Attribute
{
public Type Entity { get; } = entity;

public string Type { get; } = type;

public string SendType { get; } = sendType ?? type;
}
2 changes: 1 addition & 1 deletion Lagrange.OneBot/Core/Operation/Message/MessageCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static MessageCommon()
foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
{
var attribute = type.GetCustomAttribute<SegmentSubscriberAttribute>();
if (attribute != null) TypeToSegment[attribute.Type] = (ISegment)type.CreateInstance(false);
if (attribute != null) TypeToSegment[attribute.SendType] = (ISegment)type.CreateInstance(false);
}
}

Expand Down

0 comments on commit c6eeaa5

Please sign in to comment.