Skip to content

Commit 4fe2aee

Browse files
committed
fix: 支持rawtext为空的情况支持
1 parent ee57e22 commit 4fe2aee

File tree

8 files changed

+20
-32
lines changed

8 files changed

+20
-32
lines changed

Sora/Entities/MessageContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public sealed class MessageContext : BaseModel
2626
/// <para>Gocq提供的纯文本信息</para>
2727
/// <para>可能会缺失某些不重要且会在相同消息中不相等的字段</para>
2828
/// </summary>
29-
public string RawText { get; }
29+
public string RawText { get; internal set; }
3030

3131
/// <summary>
3232
/// 消息段列表
@@ -282,7 +282,7 @@ public override bool Equals(object obj)
282282
/// </summary>
283283
public override int GetHashCode()
284284
{
285-
return HashCode.Combine(MessageId, RawText, MessageBody, Time, Font, MessageSequence);
285+
return HashCode.Combine(MessageId, MessageBody, Time, Font, MessageSequence);
286286
}
287287

288288
#endregion

Sora/EventArgs/SoraEvent/BaseMessageEventArgs.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Sora.Enumeration.ApiType;
1010
using Sora.Net.Records;
1111
using Sora.OnebotModel.OnebotEvent.MessageEvent;
12+
using Sora.Serializer;
1213

1314
namespace Sora.EventArgs.SoraEvent;
1415

@@ -71,7 +72,13 @@ internal BaseMessageEventArgs(Guid serviceId,
7172
msg.Time,
7273
msg.Font,
7374
null);
74-
Sender = new User(serviceId, connectionId, msg.UserId);
75+
76+
//空raw信息兼容
77+
if (string.IsNullOrEmpty(msg.RawMessage))
78+
{
79+
Message.RawText = Message.MessageBody.SerializeToCq();
80+
}
81+
Sender = new User(serviceId, connectionId, msg.UserId);
7582
IsSelfMessage = msg.UserId == msg.SelfId;
7683
IsSuperUser = msg.UserId is not (0 or -1) && ServiceRecord.IsSuperUser(serviceId, msg.UserId);
7784
}

Sora/Net/SoraWebsocketClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public async ValueTask StartService()
144144
{
145145
if (_disposed)
146146
return;
147-
Event.Adapter(JObject.Parse(msg.Text), ServiceId);
147+
Event.Adapter(JObject.Parse(msg.Text ?? "{}"), ServiceId);
148148
}));
149149
//连接断开事件
150150
_subClientDisconnectionHappened = Client.DisconnectionHappened.Subscribe(info => Task.Run(() =>

Sora/Net/SoraWebsocketServer.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,6 @@ internal SoraWebsocketServer(ServerConfig config, Action<Exception> crashAction
8282
_isReady = false;
8383
Log.Info("Sora", $"Sora WebSocket服务器初始化... [{ServiceId}]");
8484
Config = config ?? throw new ArgumentNullException(nameof(config));
85-
//检查端口占用
86-
if (Helper.IsPortInUse(Config.Port))
87-
{
88-
InvalidOperationException e = new($"端口{Config.Port}已被占用,请更换其他端口");
89-
Log.Fatal(e, "Sora", $"端口{Config.Port}已被占用,请更换其他端口", Config);
90-
throw e;
91-
}
9285

9386
//写入初始化信息
9487
if (!ServiceRecord.AddOrUpdateRecord(ServiceId, new ServiceConfig(Config), this))

Sora/OnebotModel/OnebotEvent/MessageEvent/BaseObMessageEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ internal abstract class BaseObMessageEventArgs : BaseObApiEventArgs
4242
/// <summary>
4343
/// 原始消息内容
4444
/// </summary>
45-
[JsonProperty(PropertyName = "raw_message")]
45+
[JsonProperty(PropertyName = "raw_message", NullValueHandling = NullValueHandling.Ignore)]
4646
internal string RawMessage { get; set; }
4747

4848
/// <summary>

Sora/Properties/PublishProfiles/Package.pubxml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
99
<PublishDir>bin\Publish\</PublishDir>
1010
<PublishProtocol>FileSystem</PublishProtocol>
1111
<TargetFramework>net6.0</TargetFramework>
12-
<SelfContained>false</SelfContained>
12+
<SelfContained>true</SelfContained>
1313
<DocumentationFile>.\Sora.xml</DocumentationFile>
14+
<RuntimeIdentifier>linux-arm64</RuntimeIdentifier>
15+
<PublishSingleFile>false</PublishSingleFile>
16+
<PublishTrimmed>false</PublishTrimmed>
1417
</PropertyGroup>
1518
</Project>

Sora/Util/Helper.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.ComponentModel;
44
using System.Linq;
5-
using System.Net.NetworkInformation;
65
using System.Reflection;
76
using System.Runtime.Serialization;
87
using System.Text.RegularExpressions;
@@ -37,20 +36,6 @@ internal static void FriendlyException(UnhandledExceptionEventArgs args)
3736

3837
#endregion
3938

40-
#region 网络
41-
42-
/// <summary>
43-
/// 检查端口占用
44-
/// </summary>
45-
/// <param name="port">端口号</param>
46-
internal static bool IsPortInUse(uint port)
47-
{
48-
return IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners()
49-
.Any(ipEndPoint => ipEndPoint.Port == port);
50-
}
51-
52-
#endregion
53-
5439
#region 指令优先级转换
5540

5641
internal static List<(int p, List<T> cmds)> ToPriorityList<T>(this List<T> cmdList) where T : BaseCommandInfo

Sora_Test/Properties/PublishProfiles/FolderProfile.pubxml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
66
<PropertyGroup>
77
<Configuration>Release</Configuration>
88
<Platform>Any CPU</Platform>
9-
<PublishDir>bin\Release\net5.0\publish\</PublishDir>
9+
<PublishDir>bin\LinuxTest</PublishDir>
1010
<PublishProtocol>FileSystem</PublishProtocol>
1111
<TargetFramework>net6.0</TargetFramework>
12-
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
13-
<SelfContained>false</SelfContained>
12+
<RuntimeIdentifier>linux-arm64</RuntimeIdentifier>
13+
<SelfContained>true</SelfContained>
1414
<PublishSingleFile>true</PublishSingleFile>
15-
<PublishReadyToRun>false</PublishReadyToRun>
15+
<PublishTrimmed>false</PublishTrimmed>
1616
</PropertyGroup>
1717
</Project>

0 commit comments

Comments
 (0)