Skip to content

Commit a5a953b

Browse files
committed
fix: 根据程序集检查, 更正了一些问题
1 parent 37b66a0 commit a5a953b

21 files changed

+76
-33
lines changed

src/AssmeblyCheck/AssemblyCheckCore.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public static void Run()
3434

3535
foreach (var action in cqActionTypes)
3636
{
37+
if (!action.Name.EndsWith("Action"))
38+
throw new Exception($"{action.FullName} 名称不是 Action 结尾");
3739
if (!action.IsPublic)
3840
throw new Exception($"{action.FullName} 不是 public");
3941
foreach (var prop in action.GetProperties())
@@ -45,6 +47,8 @@ public static void Run()
4547

4648
foreach (var actionParamsModel in cqActionParamsModelTypes)
4749
{
50+
if (!actionParamsModel.Name.EndsWith("ActionParamsModel"))
51+
throw new Exception($"{actionParamsModel.FullName} 不是 ActionParamsModel 结尾");
4852
if (actionParamsModel.IsPublic)
4953
throw new Exception($"{actionParamsModel.FullName} 是 public");
5054
foreach (var prop in actionParamsModel.GetProperties())
@@ -56,6 +60,8 @@ public static void Run()
5660

5761
foreach (var actionResult in cqActionResultTypes)
5862
{
63+
if (!actionResult.Name.EndsWith("ActionResult"))
64+
throw new Exception($"{actionResult.FullName} 不是 ActionResult 结尾");
5965
if (!actionResult.IsPublic)
6066
throw new Exception($"{actionResult.FullName} 不是 public");
6167
if (actionResult.GetConstructors().Length > 0)
@@ -71,6 +77,8 @@ public static void Run()
7177

7278
foreach (var actionResultDataModel in cqActionResultDataModelTypes)
7379
{
80+
if (!actionResultDataModel.Name.EndsWith("ActionResultDataModel"))
81+
throw new Exception($"{actionResultDataModel.FullName} 不是 ActionResultDataModel 后缀");
7482
if (actionResultDataModel.IsPublic)
7583
throw new Exception($"{actionResultDataModel.FullName} 是 public");
7684
if (actionResultDataModel.Namespace?.StartsWith("EleCho.GoCqHttpSdk.Action.Result") ?? throw new Exception($"怪了, {actionResultDataModel} 没命名空间"))

src/EleCho.GoCqHttpSdk/Action/CqCreateGroupFolderAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public CqCreateGroupFolderAction(long groupId, string name)
4141

4242
internal override CqActionParamsModel GetParamsModel()
4343
{
44-
return new CqCreateGroupFolderParamsModel(GroupId, Name, Parent);
44+
return new CqCreateGroupFolderActionParamsModel(GroupId, Name, Parent);
4545
}
4646
}
4747
}

src/EleCho.GoCqHttpSdk/Action/Model/Params/CqCreateGroupFolderParamsModel.cs renamed to src/EleCho.GoCqHttpSdk/Action/Model/Params/CqCreateGroupFolderActionParamsModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44

55
namespace EleCho.GoCqHttpSdk.Action.Model.Params
66
{
7-
internal class CqCreateGroupFolderParamsModel : CqActionParamsModel
7+
internal class CqCreateGroupFolderActionParamsModel : CqActionParamsModel
88
{
99
[JsonConstructor]
10-
public CqCreateGroupFolderParamsModel(long group_id, string name, string parent_id)
10+
public CqCreateGroupFolderActionParamsModel(long group_id, string name, string parent_id)
1111
{
1212
this.group_id = group_id;
1313
this.name = name;
1414
this.parent_id = parent_id;
1515
}
1616

17-
public long group_id { get; set; }
18-
public string name { get; set; }
19-
public string parent_id { get; set; }
17+
public long group_id { get; }
18+
public string name { get; }
19+
public string parent_id { get; }
2020
}
2121
}

src/EleCho.GoCqHttpSdk/Action/Model/Params/CqDeleteGroupFileActionParamsModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public CqDeleteGroupFileActionParamsModel(long group_id, string file_id, int bus
1313
this.busid = busid;
1414
}
1515

16-
public long group_id { get; set; }
17-
public string file_id { get; set; }
16+
public long group_id { get; }
17+
public string file_id { get; }
1818

19-
public int busid { get; set; }
19+
public int busid { get; }
2020
}
2121
}

src/EleCho.GoCqHttpSdk/Action/Model/Params/CqDeleteGroupFolderActionParamsModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public CqDeleteGroupFolderActionParamsModel(long group_id, string folder_id)
1111
this.folder_id = folder_id;
1212
}
1313

14-
public long group_id { get; set; }
15-
public string folder_id { get; set; }
14+
public long group_id { get; }
15+
public string folder_id { get; }
1616
}
1717
}

src/EleCho.GoCqHttpSdk/Action/Model/Params/CqGetGroupFileSystemInformationActionParamsModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public CqGetGroupFileSystemInformationActionParamsModel(long group_id)
1010
this.group_id = group_id;
1111
}
1212

13-
public long group_id { get; set; }
13+
public long group_id { get; }
1414
}
1515
}

src/EleCho.GoCqHttpSdk/Action/Model/Params/CqGetGroupFileUrlActionParamsModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public CqGetGroupFileUrlActionParamsModel(long group_id, string file_id, int bus
1212
this.busid = busid;
1313
}
1414

15-
public long group_id { get; set; }
16-
public string file_id { get; set; }
17-
public int busid { get; set; }
15+
public long group_id { get; }
16+
public string file_id { get; }
17+
public int busid { get; }
1818
}
1919
}

src/EleCho.GoCqHttpSdk/Action/Model/Params/CqGetGroupFilesByFolderActionParamsModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public CqGetGroupFilesByFolderActionParamsModel(long group_id, string folder_id)
1111
this.folder_id = folder_id;
1212
}
1313

14-
public long group_id { get; set; }
15-
public string folder_id { get; set; }
14+
public long group_id { get; }
15+
public string folder_id { get; }
1616
}
1717
}

src/EleCho.GoCqHttpSdk/Action/Model/Params/CqGetGroupRootFilesActionParamsModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public CqGetGroupRootFilesActionParamsModel(long group_id)
1010
this.group_id = group_id;
1111
}
1212

13-
public long group_id { get; set; }
13+
public long group_id { get; }
1414
}
1515
}

src/EleCho.GoCqHttpSdk/Action/Model/Params/CqOcrImageActionParamsModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace EleCho.GoCqHttpSdk.Action.Model.Params
44
{
55
internal class CqOcrImageActionParamsModel : CqActionParamsModel
66
{
7-
public string image { get; set; }
7+
public string image { get; }
88

99
public CqOcrImageActionParamsModel(string image)
1010
{

src/EleCho.GoCqHttpSdk/Action/Model/Params/CqReloadEventFilterActionParamsModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ public CqReloadEventFilterActionParamsModel(string file)
77
this.file = file;
88
}
99

10-
public string file { get; set; }
10+
public string file { get; }
1111
}
1212
}

src/EleCho.GoCqHttpSdk/Action/Model/Params/CqUploadGroupFileActionParamsModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public CqUploadGroupFileActionParamsModel(long group_id, string file, string nam
1414
this.folder = folder;
1515
}
1616

17-
public long group_id { get; set; }
18-
public string file { get; set; } = string.Empty;
19-
public string name { get; set; } = string.Empty;
20-
public string? folder { get; set; } = string.Empty;
17+
public long group_id { get; }
18+
public string file { get; } = string.Empty;
19+
public string name { get; } = string.Empty;
20+
public string? folder { get; } = string.Empty;
2121
}
2222
}

src/EleCho.GoCqHttpSdk/Action/Model/Params/CqUploadPrivateFileActionParamsModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public CqUploadPrivateFileActionParamsModel(long user_id, string file, string na
1212
this.name = name;
1313
}
1414

15-
public long user_id { get; set; }
16-
public string file { get; set; }
17-
public string name { get; set; }
15+
public long user_id { get; }
16+
public string file { get; }
17+
public string name { get; }
1818
}
1919
}

src/EleCho.GoCqHttpSdk/Action/Model/ResultData/CqActionResultDataModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ internal class CqActionResultDataModel
4545
SetFriendAddRequest => dataValue.Deserialize<CqHandleFriendRequestActionResultDataModel>(JsonHelper.Options),
4646
SetGroupAddRequest => dataValue.Deserialize<CqHandleGroupRequestActionResultDataModel>(JsonHelper.Options),
4747

48-
MarkMsgAsRead => dataValue.Deserialize<CqMarkMessageAsReadResultDataModel>(JsonHelper.Options),
48+
MarkMsgAsRead => dataValue.Deserialize<CqMarkMessageAsReadActionResultDataModel>(JsonHelper.Options),
4949
SetGroupAdmin => dataValue.Deserialize<CqSetGroupAdministratorActionResultDataModel>(JsonHelper.Options),
5050
SetGroupAnonymous => dataValue.Deserialize<CqSetGroupAnonymousActionResultDataModel>(JsonHelper.Options),
5151
SetGroupCard => dataValue.Deserialize<CqSetGroupNicknameActionResultDataModel>(JsonHelper.Options),
@@ -91,6 +91,7 @@ internal class CqActionResultDataModel
9191
GetGroupFileSystemInfo => dataValue.Deserialize<CqGetGroupFileSystemInformationActionResultDataModel>(JsonHelper.Options),
9292
GetGroupRootFiles => dataValue.Deserialize<CqGetGroupRootFilesActionResultDataModel>(JsonHelper.Options),
9393
GetGroupFilesByFolder => dataValue.Deserialize<CqGetGroupFilesByFolderActionResultDataModel>(JsonHelper.Options),
94+
GetGroupFileUrl => dataValue.Deserialize<CqGetGroupFileUrlActionResultDataModel>(JsonHelper.Options),
9495

9596
_ => throw new NotImplementedException()
9697
};

src/EleCho.GoCqHttpSdk/Action/Model/ResultData/CqMarkMessageAsReadResultDataModel.cs renamed to src/EleCho.GoCqHttpSdk/Action/Model/ResultData/CqMarkMessageAsReadActionResultDataModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace EleCho.GoCqHttpSdk.Action.Model.ResultData
88
{
9-
internal class CqMarkMessageAsReadResultDataModel : CqActionResultDataModel
9+
internal class CqMarkMessageAsReadActionResultDataModel : CqActionResultDataModel
1010
{
1111
}
1212
}

src/EleCho.GoCqHttpSdk/Action/Result/CqActionResult.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ internal static CqActionResult CreateActionResultFromActionType(string actionTyp
117117
GetGroupRootFiles => new CqGetGroupRootFilesActionResult(),
118118
GetGroupFilesByFolder => new CqGetGroupFilesByFolderActionResult(),
119119
UploadPrivateFile => new CqUploadPrivateFileActionResult(),
120+
GetGroupFileUrl => new CqGetGroupFileUrlActionResult(),
120121

121122

122123
_ => throw new NotImplementedException()

src/EleCho.GoCqHttpSdk/Action/Result/CqGetGroupFileSystemInformationActionResult.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ internal CqGetGroupFileSystemInformationActionResult()
1414
/// <summary>
1515
/// 文件总数
1616
/// </summary>
17-
public int FileCount { get; set; }
17+
public int FileCount { get; private set; }
1818

1919
/// <summary>
2020
/// 文件上限
2121
/// </summary>
22-
public int LimitCount { get; set; }
22+
public int LimitCount { get; private set; }
2323

2424
/// <summary>
2525
/// 已使用空间
2626
/// </summary>
27-
public long UsedSpace { get; set; }
27+
public long UsedSpace { get; private set; }
2828

2929
/// <summary>
3030
/// 空间总量
3131
/// </summary>
32-
public long TotalSpace { get; set; }
32+
public long TotalSpace { get; private set; }
3333

3434
internal override void ReadDataModel(CqActionResultDataModel? model)
3535
{

src/EleCho.GoCqHttpSdk/Enumeration/CqEnum.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ internal static class CqEnum
189189
CqActionType.GetGroupRootFiles => GetGroupRootFiles,
190190
CqActionType.GetGroupFilesByFolder => GetGroupFilesByFolder,
191191
CqActionType.UploadPrivateFile => UploadPrivateFile,
192+
CqActionType.GetGroupFileUrl => GetGroupFileUrl,
192193

193194
_ => throw new ArgumentException($"Unknown Action type: {type}")
194195
};

src/EleCho.GoCqHttpSdk/Extension/CqActionSessionExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ public static CqCanSendRecordActionResult CandSendRecord(this ICqActionSession s
355355
=> GetGroupRootFilesAsync(session, groupId).Result;
356356
public static CqGetGroupFilesByFolderActionResult? GetGroupFilesByFolder(this ICqActionSession session, long groupId, string folderId)
357357
=> GetGroupFilesByFolderAsync(session, groupId, folderId).Result;
358+
public static CqUploadPrivateFileActionResult? UploadPrivateFile(this ICqActionSession session, long userId, string file, string name)
359+
=> UploadPrivateFileAsync(session, userId, file, name).Result;
358360

359361
#endregion
360362
}

src/EleCho.GoCqHttpSdk/Utils/Consts.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public static class ActionType
142142
public const string GetGroupRootFiles = "get_group_root_files";
143143
public const string GetGroupFilesByFolder = "get_group_files_by_folder";
144144
public const string UploadPrivateFile = "upload_private_file";
145+
public const string GetGroupFileUrl = "get_group_file_url";
145146

146147
}
147148

src/TestConsole/Program.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Linq;
34
using System.Net.Http;
45
using System.Net.Http.Json;
@@ -110,6 +111,34 @@ public async Task Slide(CqGroupMessagePostContext context, string content)
110111

111112
await ActionSession.SendGroupMessageAsync(context.GroupId, new CqMessage(string.Join(", ", slices.Slices)));
112113
}
114+
115+
[CqMessageMatch("^testFile (?<name>.*)")]
116+
public async Task TestFile(CqMessagePostContext context, string name)
117+
{
118+
var testContent =
119+
$"""
120+
现在时间: {DateTime.Now};
121+
随机 GUID: {Guid.NewGuid()}
122+
""";
123+
124+
FileInfo fileInfo = new FileInfo(name);
125+
126+
using (var file = fileInfo.OpenWrite())
127+
{
128+
using var writer = new StreamWriter(file);
129+
130+
await writer.WriteAsync(testContent);
131+
}
132+
133+
if (context is CqGroupMessagePostContext groupContext)
134+
{
135+
await ActionSession.UploadGroupFileAsync(groupContext.GroupId, fileInfo.FullName, name);
136+
}
137+
else if (context is CqPrivateMessagePostContext privateContext)
138+
{
139+
await ActionSession.UploadPrivateFileAsync(privateContext.UserId, fileInfo.FullName, name);
140+
}
141+
}
113142
}
114143

115144
class OpenAiMatchPlugin : CqMessageMatchPostPlugin

0 commit comments

Comments
 (0)