-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKookCommandReader.cs
More file actions
72 lines (61 loc) · 2.73 KB
/
KookCommandReader.cs
File metadata and controls
72 lines (61 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using HuaJiBot.NET.Bot;
using HuaJiBot.NET.Commands;
using Kook;
using static HuaJiBot.NET.Commands.CommonCommandReader;
namespace HuaJiBot.NET.Adapter.Kook;
/// <summary>
/// Kook 指令读取器
/// </summary>
internal class KookCommandReader(BotService service, IMessage message) : CommonCommandReader
{
public override IEnumerable<ReaderEntity> Msg
{
get
{
return Parse();
IEnumerable<ReaderEntity> Parse()
{
// Parse the message content - Kook uses KMarkdown format
var content = message.Content;
if (string.IsNullOrEmpty(content))
yield break;
// Parse mentions in the format (met)userId(met)
var mentionPattern = @"\(met\)(\d+)\(met\)";
var matches = System.Text.RegularExpressions.Regex.Matches(content, mentionPattern);
var processedContent = content;
foreach (System.Text.RegularExpressions.Match match in matches)
{
var userId = match.Groups[1].Value;
processedContent = processedContent.Replace(match.Value, "");
// Get the username if possible
var username = "";
if (message is IUserMessage userMessage && userMessage.MentionedUsers.Any())
{
var mentionedUser = userMessage.MentionedUsers.FirstOrDefault(u => u.Id.ToString() == userId);
username = mentionedUser?.Username ?? "";
}
yield return new ReaderAt(userId, username);
}
// Return the text content without mentions
var trimmedContent = processedContent.Trim();
if (!string.IsNullOrEmpty(trimmedContent))
{
yield return trimmedContent;
}
// Handle quote/reply if reference exists
if (message.Reference.HasValue && message.Reference.Value.MessageId.HasValue)
{
var refMessageId = message.Reference.Value.MessageId.Value.ToString();
yield return new ReaderReply(new CommandReader.ReplyInfo(
messageId: refMessageId,
seqId: null,
senderId: null,
content: null
));
}
// TODO: Handle other Kook-specific message types like cards, embeds, attachments, etc.
// Kook supports rich KMarkdown content that could be parsed here
}
}
}
}