-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 解决 MiraiHttpSession.GetUserProfileAsync 调用错误的问题 (#133) * 修正xml标注错误 修复转发消息无法正常发送的问题 (#132) 更改 ChangeTypeJsonConverter 定义, 并添加一个三泛型参数的 ChangeTypeJsonConverter 以便更好控制(反)序列化 * 添加转发消息构建器 (I)ForwardMessageBuilder
- Loading branch information
1 parent
00dd46e
commit 1c20ca3
Showing
28 changed files
with
438 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Mirai.CSharp.HttpApi.Models.ChatMessages; | ||
using ISharedChatMessage = Mirai.CSharp.Models.ChatMessages.IChatMessage; | ||
using ISharedForwardMessage = Mirai.CSharp.Models.ChatMessages.IForwardMessage; | ||
using ISharedForwardMessageBuilder = Mirai.CSharp.Builders.IForwardMessageBuilder; | ||
using ISharedForwardMessageNode = Mirai.CSharp.Models.ChatMessages.IForwardMessageNode; | ||
using ISharedMessageChainBuilder = Mirai.CSharp.Builders.IMessageChainBuilder; | ||
using SharedForwardMessageBuilder = Mirai.CSharp.Builders.ForwardMessageBuilder; | ||
|
||
namespace Mirai.CSharp.HttpApi.Builders | ||
{ | ||
public interface IForwardMessageBuilder : ISharedForwardMessageBuilder | ||
{ | ||
|
||
} | ||
|
||
public class ForwardMessageBuilder : SharedForwardMessageBuilder, IForwardMessageBuilder | ||
{ | ||
public override ISharedForwardMessage Build() | ||
{ | ||
IForwardMessageNode[] converted = new ForwardMessageNode[_nodes.Count]; | ||
int ix = 0; | ||
foreach (var node in _nodes) | ||
{ | ||
converted[ix++] = (IForwardMessageNode)node; | ||
} | ||
return new ForwardMessage(converted); | ||
} | ||
|
||
public override ISharedForwardMessageBuilder AddNode(ISharedForwardMessageNode node) | ||
{ | ||
if (node is not IForwardMessageNode) | ||
{ | ||
throw new InvalidOperationException($"添加的消息实例 {node.GetType().FullName} 不实现 {typeof(IForwardMessageNode).FullName}"); | ||
} | ||
return base.AddNode(node); | ||
} | ||
|
||
public override ISharedForwardMessageBuilder AddNodes(IEnumerable<ISharedForwardMessageNode> nodes) | ||
{ | ||
foreach (ISharedForwardMessageNode node in nodes) | ||
{ | ||
if (node is not IForwardMessageNode) | ||
{ | ||
throw new InvalidOperationException($"添加的消息实例 {node.GetType().FullName} 不实现 {typeof(IChatMessage).FullName}"); | ||
} | ||
} | ||
return base.AddNodes(nodes); | ||
} | ||
|
||
public override ISharedForwardMessageBuilder AddNode(int id) | ||
{ | ||
_nodes.Add(new ForwardMessageNode(id)); | ||
return this; | ||
} | ||
|
||
public override ISharedForwardMessageBuilder AddNode(string name, long qqNumber, DateTime time, ISharedMessageChainBuilder chainBuilder) | ||
{ | ||
return AddNode(name, qqNumber, time, chainBuilder.Build()); | ||
} | ||
|
||
public override ISharedForwardMessageBuilder AddNode(string name, long qqNumber, DateTime time, params ISharedChatMessage[] messages) | ||
{ | ||
if (messages is not IChatMessage[] converted) | ||
{ | ||
converted = new IChatMessage[messages.Length]; | ||
int ix = 0; | ||
foreach (var message in messages) | ||
{ | ||
if (message is not IChatMessage chatMessage) | ||
{ | ||
throw new InvalidOperationException($"添加的消息实例 {message.GetType().FullName} 不实现 {typeof(IChatMessage).FullName}"); | ||
} | ||
converted[ix++] = chatMessage; | ||
} | ||
} | ||
_nodes.Add(new ForwardMessageNode(name, qqNumber, time, converted)); | ||
return this; | ||
} | ||
} | ||
|
||
public class ImmutableForwardMessageBuilder : ForwardMessageBuilder | ||
{ | ||
protected ISharedForwardMessage? _builtMessage; | ||
|
||
public override ISharedForwardMessage Build() | ||
{ | ||
if (_builtMessage == null) | ||
{ | ||
_builtMessage = base.Build(); | ||
_nodes.Clear(); | ||
_nodes.Capacity = 0; | ||
} | ||
return _builtMessage; | ||
} | ||
|
||
public override ISharedForwardMessageBuilder AddNode(ISharedForwardMessageNode node) | ||
{ | ||
if (_builtMessage != null) | ||
{ | ||
throw new InvalidOperationException("由于之前进行过构建操作, 无法添加新的消息节点实例"); | ||
} | ||
return base.AddNode(node); | ||
} | ||
|
||
public override ISharedForwardMessageBuilder AddNodes(IEnumerable<ISharedForwardMessageNode> nodes) | ||
{ | ||
if (_builtMessage != null) | ||
{ | ||
throw new InvalidOperationException("由于之前进行过构建操作, 无法添加新的消息节点实例"); | ||
} | ||
return base.AddNodes(nodes); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.