Skip to content

Commit 2a48ceb

Browse files
committed
清理代码
1 parent 54c456c commit 2a48ceb

File tree

67 files changed

+997
-981
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+997
-981
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,5 @@ Lib/
261261
Sora/Sora.xml
262262

263263
#vscode
264-
.vscode/
264+
.vscode/
265+
.claudiaideconfig

Sora/Command/CommandManager.cs

Lines changed: 137 additions & 128 deletions
Large diffs are not rendered by default.

Sora/Command/CommandUtils.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ internal static class CommandUtils
1818
[Reviewed("XiaoHe321", "2021-03-28 20:45")]
1919
internal static bool CheckMethodLegality(this MethodInfo method)
2020
{
21-
var isGroupCommandLegality = method.IsDefined(typeof(GroupCommand), false) &&
22-
method.GetParameters().Length == 1 &&
23-
method.GetParameters()
24-
.Any(para =>
25-
para.ParameterType == typeof(GroupMessageEventArgs) &&
26-
!para.IsOut);
21+
bool isGroupCommandLegality = method.IsDefined(typeof(GroupCommand), false) &&
22+
method.GetParameters().Length == 1 &&
23+
method.GetParameters()
24+
.Any(para =>
25+
para.ParameterType == typeof(GroupMessageEventArgs) &&
26+
!para.IsOut);
2727

28-
var isPrivateCommandLegality = method.IsDefined(typeof(PrivateCommand), false) &&
29-
method.GetParameters().Length == 1 &&
30-
method.GetParameters()
31-
.Any(para =>
32-
para.ParameterType == typeof(PrivateMessageEventArgs) &&
33-
!para.IsOut);
28+
bool isPrivateCommandLegality = method.IsDefined(typeof(PrivateCommand), false) &&
29+
method.GetParameters().Length == 1 &&
30+
method.GetParameters()
31+
.Any(para =>
32+
para.ParameterType == typeof(PrivateMessageEventArgs) &&
33+
!para.IsOut);
3434

3535
return isGroupCommandLegality || isPrivateCommandLegality;
3636
}

Sora/Converter/EnumDescriptionConverter.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.ComponentModel;
33
using System.Linq;
4+
using System.Reflection;
45
using Newtonsoft.Json;
56

67
namespace Sora.Converter;
@@ -28,15 +29,15 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
2829
return;
2930
}
3031

31-
var fieldInfo = value.GetType().GetField(value.ToString()!);
32+
FieldInfo fieldInfo = value.GetType().GetField(value.ToString()!);
3233
if (fieldInfo == null)
3334
{
3435
writer.WriteValue("");
3536
return;
3637
}
3738

3839
var attributes = (DescriptionAttribute[]) fieldInfo
39-
.GetCustomAttributes(typeof(DescriptionAttribute), false);
40+
.GetCustomAttributes(typeof(DescriptionAttribute), false);
4041
writer.WriteValue(attributes.Length > 0 ? attributes[0].Description : "");
4142
}
4243

@@ -45,11 +46,11 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
4546
/// 通过Description获取枚举值
4647
/// </summary>
4748
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
48-
JsonSerializer serializer)
49+
JsonSerializer serializer)
4950
{
50-
var fields = objectType.GetFields();
51-
var readValue = reader.Value?.ToString() ?? string.Empty;
52-
foreach (var field in fields)
51+
FieldInfo[] fields = objectType.GetFields();
52+
string readValue = reader.Value?.ToString() ?? string.Empty;
53+
foreach (FieldInfo field in fields)
5354
{
5455
object[] objects = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
5556
if (objects.Any(item => (item as DescriptionAttribute)?.Description == readValue))

Sora/Converter/MessageConverter.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ private static SoraSegment ParseMessageElement(OnebotSegment onebotSegment)
2929
if (onebotSegment.RawData == null) return new SoraSegment(SegmentType.Unknown, null);
3030
try
3131
{
32-
var jsonObj = JObject.FromObject(onebotSegment.RawData);
32+
JObject jsonObj = JObject.FromObject(onebotSegment.RawData);
3333
if (jsonObj.Count == 0) return new SoraSegment(SegmentType.Unknown, null);
3434
return onebotSegment.MsgType switch
3535
{
36-
SegmentType.Text => new SoraSegment(SegmentType.Text, jsonObj.ToObject<TextSegment>()),
37-
SegmentType.Face => new SoraSegment(SegmentType.Face, jsonObj.ToObject<FaceSegment>()),
38-
SegmentType.Image => new SoraSegment(SegmentType.Image, jsonObj.ToObject<ImageSegment>()),
39-
SegmentType.Record => new SoraSegment(SegmentType.Record, jsonObj.ToObject<RecordSegment>()),
40-
SegmentType.At => new SoraSegment(SegmentType.At, jsonObj.ToObject<AtSegment>()),
41-
SegmentType.Share => new SoraSegment(SegmentType.Share, jsonObj.ToObject<ShareSegment>()),
42-
SegmentType.Reply => new SoraSegment(SegmentType.Reply, jsonObj.ToObject<ReplySegment>()),
36+
SegmentType.Text => new SoraSegment(SegmentType.Text, jsonObj.ToObject<TextSegment>()),
37+
SegmentType.Face => new SoraSegment(SegmentType.Face, jsonObj.ToObject<FaceSegment>()),
38+
SegmentType.Image => new SoraSegment(SegmentType.Image, jsonObj.ToObject<ImageSegment>()),
39+
SegmentType.Record => new SoraSegment(SegmentType.Record, jsonObj.ToObject<RecordSegment>()),
40+
SegmentType.At => new SoraSegment(SegmentType.At, jsonObj.ToObject<AtSegment>()),
41+
SegmentType.Share => new SoraSegment(SegmentType.Share, jsonObj.ToObject<ShareSegment>()),
42+
SegmentType.Reply => new SoraSegment(SegmentType.Reply, jsonObj.ToObject<ReplySegment>()),
4343
SegmentType.Forward => new SoraSegment(SegmentType.Forward, jsonObj.ToObject<ForwardSegment>()),
44-
SegmentType.Xml => new SoraSegment(SegmentType.Xml, jsonObj.ToObject<CodeSegment>()),
45-
SegmentType.Json => new SoraSegment(SegmentType.Json, jsonObj.ToObject<CodeSegment>()),
46-
_ => new SoraSegment(SegmentType.Unknown, new UnknownSegment {Content = jsonObj})
44+
SegmentType.Xml => new SoraSegment(SegmentType.Xml, jsonObj.ToObject<CodeSegment>()),
45+
SegmentType.Json => new SoraSegment(SegmentType.Json, jsonObj.ToObject<CodeSegment>()),
46+
_ => new SoraSegment(SegmentType.Unknown, new UnknownSegment {Content = jsonObj})
4747
};
4848
}
4949
catch (Exception e)
@@ -63,7 +63,7 @@ internal static MessageBody ToMessageBody(this List<OnebotSegment> messages)
6363
{
6464
Log.Debug("Sora", "Parsing msg list");
6565
if (messages == null || messages.Count == 0) return new MessageBody();
66-
var retMsg = messages.Select(ParseMessageElement).ToList();
66+
List<SoraSegment> retMsg = messages.Select(ParseMessageElement).ToList();
6767

6868
Log.Debug("Sora", $"Get msg len={retMsg.Count}");
6969
return new MessageBody(retMsg);

Sora/Converter/StringConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
2020
}
2121

2222
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
23-
JsonSerializer serializer)
23+
JsonSerializer serializer)
2424
{
2525
//此方法不可能调用,不做实现
2626
return null;

Sora/Entities/Base/SoraApi.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public async ValueTask<ApiStatus> RecallMessage(int messageId)
139139
public async ValueTask<(ApiStatus apiStatus, List<Node> nodeArray)> GetForwardMessage(string forwardId)
140140
{
141141
if (string.IsNullOrEmpty(forwardId)) throw new NullReferenceException(nameof(forwardId));
142-
var (apiStatus, nodeArray) = await ApiInterface.GetForwardMessage(ConnectionId, forwardId);
142+
(ApiStatus apiStatus, List<Node> nodeArray) = await ApiInterface.GetForwardMessage(ConnectionId, forwardId);
143143
return (apiStatus, nodeArray);
144144
}
145145

@@ -344,7 +344,7 @@ public async ValueTask<ApiStatus> EnableGroupAnonymousMute(long groupId, Anonymo
344344
/// <param name="anonymousFlag">匿名用户Flag</param>
345345
/// <param name="duration">禁言时长, 单位秒</param>
346346
public async ValueTask<ApiStatus> EnableGroupAnonymousMute(long groupId, string anonymousFlag,
347-
long duration)
347+
long duration)
348348
{
349349
if (groupId < MinGroupId)
350350
throw new ArgumentOutOfRangeException(nameof(groupId), $"out of range [{groupId}]");
@@ -449,7 +449,7 @@ public async ValueTask<ApiStatus> SetGroupPortrait(long groupId, string imageFil
449449
{
450450
if (groupId < MinGroupId) throw new ArgumentOutOfRangeException(nameof(groupId));
451451
if (string.IsNullOrEmpty(imageFile)) throw new NullReferenceException(nameof(imageFile));
452-
var (retFileStr, isMatch) = SegmentHelper.ParseDataStr(imageFile);
452+
(string retFileStr, bool isMatch) = SegmentHelper.ParseDataStr(imageFile);
453453
if (!isMatch) throw new NotSupportedException($"not supported file type({imageFile})");
454454
return await ApiInterface.SetGroupPortrait(ConnectionId, groupId, retFileStr, useCache);
455455
}
@@ -559,11 +559,11 @@ public async
559559
/// <param name="folderId">父目录ID</param>
560560
/// <returns>API状态</returns>
561561
public async ValueTask<ApiStatus> UploadGroupFile(long groupId, string localFilePath, string fileName,
562-
string folderId = null)
562+
string folderId = null)
563563
{
564564
if (groupId < MinGroupId) throw new ArgumentOutOfRangeException(nameof(groupId));
565565
return await ApiInterface.UploadGroupFile(ConnectionId, groupId, localFilePath,
566-
fileName, folderId);
566+
fileName, folderId);
567567
}
568568

569569
/// <summary>
@@ -915,7 +915,7 @@ public async ValueTask<ApiStatus> ReloadEventFilter()
915915
/// <param name="approve">是否同意</param>
916916
/// <param name="remark">好友备注</param>
917917
public async ValueTask<ApiStatus> SetFriendAddRequest(string flag, bool approve,
918-
string remark = null)
918+
string remark = null)
919919
{
920920
if (string.IsNullOrEmpty(flag)) throw new NullReferenceException(nameof(flag));
921921
return await ApiInterface.SetFriendAddRequest(ConnectionId, flag, approve, remark);
@@ -929,9 +929,9 @@ public async ValueTask<ApiStatus> SetFriendAddRequest(string flag, bool approve,
929929
/// <param name="approve">是否同意</param>
930930
/// <param name="reason">拒绝理由</param>
931931
public async ValueTask<ApiStatus> SetGroupAddRequest(string flag,
932-
GroupRequestType requestType,
933-
bool approve,
934-
string reason = null)
932+
GroupRequestType requestType,
933+
bool approve,
934+
string reason = null)
935935
{
936936
if (string.IsNullOrEmpty(flag)) throw new NullReferenceException(nameof(flag));
937937
return await ApiInterface.SetGroupAddRequest(ConnectionId, flag, requestType, approve, reason);
@@ -968,7 +968,7 @@ public async ValueTask<ApiStatus> SetGroupAddRequest(string flag,
968968
/// <returns>文件绝对路径</returns>
969969
public async ValueTask<(ApiStatus apiStatus, string filePath)> DownloadFile(
970970
string url, int threadCount, Dictionary<string, string> customHeader = null,
971-
int timeout = 10000)
971+
int timeout = 10000)
972972
{
973973
if (string.IsNullOrEmpty(url)) throw new NullReferenceException(nameof(url));
974974
if (threadCount < 1)
@@ -1026,7 +1026,7 @@ public Group GetGroup(long groupId)
10261026
/// </summary>
10271027
public long GetLoginUserId()
10281028
{
1029-
if (ConnectionManager.GetLoginUid(ConnectionId, out var uid)) return uid;
1029+
if (ConnectionManager.GetLoginUid(ConnectionId, out long uid)) return uid;
10301030
return -1;
10311031
}
10321032

@@ -1037,7 +1037,7 @@ public long GetLoginUserId()
10371037
/// <param name="userId">用户ID</param>
10381038
public bool BlockUser(long userId)
10391039
{
1040-
return StaticVariable.ServiceInfos[ServiceId].BlockUsers.Add(userId);
1040+
return StaticVariable.ServiceConfigs[ServiceId].BlockUsers.Add(userId);
10411041
}
10421042

10431043
/// <summary>
@@ -1046,7 +1046,7 @@ public bool BlockUser(long userId)
10461046
/// <param name="userId">用户ID</param>
10471047
public bool RemoveBlock(long userId)
10481048
{
1049-
return StaticVariable.ServiceInfos[ServiceId].BlockUsers.Remove(userId);
1049+
return StaticVariable.ServiceConfigs[ServiceId].BlockUsers.Remove(userId);
10501050
}
10511051

10521052
/// <summary>
@@ -1055,7 +1055,7 @@ public bool RemoveBlock(long userId)
10551055
/// <param name="userId">用户ID</param>
10561056
public bool AddSuperUser(long userId)
10571057
{
1058-
return StaticVariable.ServiceInfos[ServiceId].SuperUsers.Add(userId);
1058+
return StaticVariable.ServiceConfigs[ServiceId].SuperUsers.Add(userId);
10591059
}
10601060

10611061
/// <summary>
@@ -1064,7 +1064,7 @@ public bool AddSuperUser(long userId)
10641064
/// <param name="userId">用户ID</param>
10651065
public bool RemoveSuperUser(long userId)
10661066
{
1067-
return StaticVariable.ServiceInfos[ServiceId].SuperUsers.Remove(userId);
1067+
return StaticVariable.ServiceConfigs[ServiceId].SuperUsers.Remove(userId);
10681068
}
10691069

10701070
#endregion

Sora/Entities/Group.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ internal Group(Guid serviceId, Guid connectionId, long gid) : base(serviceId, co
5050
/// <para><see langword="messageId"/> 消息ID</para>
5151
/// </returns>
5252
public async ValueTask<(ApiStatus apiStatus, int messageId)> SendGroupMessage(MessageBody message,
53-
TimeSpan? timeout = null)
53+
TimeSpan? timeout = null)
5454
{
5555
return await SoraApi.SendGroupMessage(Id, message, timeout);
5656
}
@@ -211,10 +211,10 @@ public async ValueTask<ApiStatus> SendGroupNotice(string content, string image =
211211
/// <param name="folderId">父目录ID</param>
212212
/// <returns>API状态</returns>
213213
public async ValueTask<ApiStatus> UploadGroupFile(string localFilePath, string fileName,
214-
string folderId = null)
214+
string folderId = null)
215215
{
216216
return await SoraApi.UploadGroupFile(Id, localFilePath,
217-
fileName, folderId);
217+
fileName, folderId);
218218
}
219219

220220
#endregion

Sora/Entities/Info/GroupInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public readonly struct GroupInfo
5252
/// 群创建时间
5353
/// </summary>
5454
[JsonProperty(PropertyName = "group_create_time", NullValueHandling = NullValueHandling.Ignore,
55-
DefaultValueHandling = DefaultValueHandling.Ignore)]
55+
DefaultValueHandling = DefaultValueHandling.Ignore)]
5656
private long? GroupCreateTimeStamp
5757
{
5858
get => (GroupCreateTime ?? DateTime.MinValue).ToTimeStamp();

Sora/Entities/Info/GroupMemberInfo.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public Sex Sex
5252
{
5353
return SexStr switch
5454
{
55-
"male" => Sex.Male,
55+
"male" => Sex.Male,
5656
"female" => Sex.Female,
57-
_ => Sex.Unknown
57+
_ => Sex.Unknown
5858
};
5959
}
6060
}
@@ -128,7 +128,7 @@ private long LastSentTimeStamp
128128
public DateTime? TitleExpireTime { get; internal init; }
129129

130130
[JsonProperty(PropertyName = "title_expire_time", NullValueHandling = NullValueHandling.Ignore,
131-
DefaultValueHandling = DefaultValueHandling.Ignore)]
131+
DefaultValueHandling = DefaultValueHandling.Ignore)]
132132
private long? TitleExpireTimeStamp
133133
{
134134
init => TitleExpireTime = value == 0 ? null : value?.ToDateTime() ?? null;
@@ -147,7 +147,7 @@ private long? TitleExpireTimeStamp
147147
public DateTime? ShutUpTime { get; internal init; }
148148

149149
[JsonProperty(PropertyName = "shut_up_timestamp", NullValueHandling = NullValueHandling.Ignore,
150-
DefaultValueHandling = DefaultValueHandling.Ignore)]
150+
DefaultValueHandling = DefaultValueHandling.Ignore)]
151151
private long? ShutUpTimestamp
152152
{
153153
init => ShutUpTime = value == 0 ? null : value?.ToDateTime() ?? null;

0 commit comments

Comments
 (0)