Skip to content

Commit 81a7e92

Browse files
authored
[NativeAPI] MessageBuilder 增加了一部分消息实体 (#53)
1 parent 8d8deb4 commit 81a7e92

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

Lagrange.Core.NativeAPI/SendMessageContext.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Text;
1+
using System.Text;
22
using Lagrange.Core.Message;
33

44
namespace Lagrange.Core.NativeAPI
@@ -87,6 +87,32 @@ public void AddLocalImage(int id, byte[] path, byte[]? summary = null,
8787
}
8888
}
8989

90+
public void AddMention(int id, long uin, byte[]? display = null)
91+
{
92+
if (MessageBuilders.TryGetValue(id, out var builder))
93+
{
94+
builder.Mention(uin, display is null ? null : Encoding.UTF8.GetString(display));
95+
}
96+
}
97+
98+
public void AddReply(int id /*, BotMessage messages */)
99+
{
100+
throw new NotImplementedException();
101+
}
102+
103+
public void AddMultiMsg(int id /*, List<BotMessage> messages */)
104+
{
105+
throw new NotImplementedException();
106+
}
107+
108+
public void AddMultiMsg(int id, byte[] resId)
109+
{
110+
if (MessageBuilders.TryGetValue(id, out var builder))
111+
{
112+
builder.MultiMsg(Encoding.UTF8.GetString(resId));
113+
}
114+
}
115+
90116
public void AddRecord(int id, byte[] record)
91117
{
92118
if (MessageBuilders.TryGetValue(id, out var builder))

Lagrange.Core.NativeAPI/SendMessageEntryPoint.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,46 @@ int subType
8383
);
8484
}
8585

86+
//display可选,可以传结构内Length为0或Data为Zero的ByteArrayNative
87+
[UnmanagedCallersOnly(EntryPoint = "AddMention")]
88+
public static void AddMention(
89+
int index,
90+
int id,
91+
long uin,
92+
ByteArrayNative display
93+
)
94+
{
95+
if (Program.Contexts.Count <= index)
96+
{
97+
return;
98+
}
99+
100+
byte[]? ds = display.IsEmpty() ? null : display.ToByteArrayWithoutFree();
101+
102+
var context = Program.Contexts[index];
103+
context.SendMessageContext.AddMention(
104+
id, uin, ds
105+
);
106+
}
107+
108+
[UnmanagedCallersOnly(EntryPoint = "AddMultiMsg")]
109+
public static void AddMultiMsg(
110+
int index,
111+
int id,
112+
ByteArrayNative resId
113+
)
114+
{
115+
if (Program.Contexts.Count <= index)
116+
{
117+
return;
118+
}
119+
120+
var context = Program.Contexts[index];
121+
context.SendMessageContext.AddMultiMsg(
122+
id, resId.ToByteArrayWithoutFree()
123+
);
124+
}
125+
86126
[UnmanagedCallersOnly(EntryPoint = "AddRecord")]
87127
public static void AddRecord(int index, int id, ByteArrayNative byteArrayNative)
88128
{

0 commit comments

Comments
 (0)