Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自定义转发兼容字符串CQ码和自定义时间 #15

Merged
merged 2 commits into from
Mar 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 28 additions & 3 deletions Sora/Entities/CQCodes/CQCodeModel/CustomNode.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Sora.Server.ApiParams;

namespace Sora.Entities.CQCodes.CQCodeModel
{
Expand Down Expand Up @@ -33,7 +33,13 @@ public class CustomNode
/// 具体消息
/// </summary>
[JsonProperty(PropertyName = "content", NullValueHandling = NullValueHandling.Ignore)]
internal List<MessageElement> Messages { get; set; }
internal object Messages { get; set; }

/// <summary>
/// 转发时间
/// </summary>
[JsonProperty(PropertyName = "time", NullValueHandling = NullValueHandling.Ignore)]
internal string Time { get; set; }

/// <summary>
/// 消息段
Expand All @@ -51,6 +57,7 @@ public CustomNode(int messageId)
Name = null;
UserId = null;
Messages = null;
Time = null;
}

/// <summary>
Expand All @@ -59,12 +66,30 @@ public CustomNode(int messageId)
/// <param name="name">发送者名</param>
/// <param name="userId">发送者ID</param>
/// <param name="customMessage">消息段</param>
public CustomNode(string name, long userId, List<CQCode> customMessage)
/// <param name="time">消息段转发时间</param>
public CustomNode(string name, long userId, List<CQCode> customMessage, DateTimeOffset? time = null)
{
MessageId = null;
Name = name;
UserId = userId.ToString();
Messages = customMessage.Select(msg => msg.ToOnebotMessage()).ToList();
Time = $"{(time?.ToUnixTimeSeconds() ?? DateTimeOffset.Now.ToUnixTimeSeconds())}";
}

/// <summary>
/// 构造自定义节点
/// </summary>
/// <param name="name">发送者名</param>
/// <param name="userId">发送者ID</param>
/// <param name="cqString">CQ码字符串格式</param>
/// <param name="time">消息段转发时间</param>
public CustomNode(string name, long userId, string cqString, DateTimeOffset? time = null)
{
MessageId = null;
Name = name;
UserId = userId.ToString();
Messages = cqString;
Time = $"{(time?.ToUnixTimeSeconds() ?? DateTimeOffset.Now.ToUnixTimeSeconds())}";
}
}
}