Skip to content

Commit 452cabb

Browse files
committed
feat: 添加了 GetGroupMemberList 操作
1 parent 626d934 commit 452cabb

31 files changed

+519
-41
lines changed

src/EleCho.GoCqHttpSdk.CommandExecuting/CqCommandExecutePostPlugin.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public abstract class CqCommandExecutePostPlugin : CommandLineApp
1919
public bool IgnoreCases { get; set; } = true;
2020
public bool AllowGroupMessage { get; set; } = true;
2121
public bool AllowPrivateMessage { get; set; } = true;
22-
public bool ExecuteNextWhenExecuted { get; set; } = false;
22+
public bool ExecuteNextWhenExecuted { get; set; } = true;
2323

2424
private StringComparison GetStringComparison()
2525
{
@@ -30,7 +30,7 @@ public async Task Execute(CqPostContext context, Func<Task> next)
3030
{
3131
if (context is CqMessagePostContext msgContext && msgContext.Message.Text.StartsWith(Prefix))
3232
{
33-
string commandLine =
33+
string commandLine =
3434
msgContext.Message.Text.Substring(Prefix.Length);
3535

3636
if (AllowGroupMessage && context is CqGroupMessagePostContext groupContext)
@@ -45,9 +45,25 @@ public async Task Execute(CqPostContext context, Func<Task> next)
4545
CqMessage response = new CqMessage($"{rst}");
4646

4747
if (ReplyInvoker)
48-
response.WithHead(new CqReplyMsg(msgContext.MessageId));
49-
if (AtInvoker)
50-
response.WithHead(new CqAtMsg(groupContext.UserId));
48+
{
49+
if (AtInvoker)
50+
{
51+
response.WithHead(new CqAtMsg(groupContext.UserId));
52+
response.WithHead(new CqTextMsg(" "));
53+
response.WithHead(new CqReplyMsg(msgContext.MessageId));
54+
}
55+
else
56+
{
57+
response.WithHead(new CqReplyMsg(msgContext.MessageId));
58+
}
59+
}
60+
else
61+
{
62+
if (AtInvoker)
63+
{
64+
response.WithHead(new CqAtMsg(groupContext.UserId));
65+
}
66+
}
5167

5268
await actionSession.SendGroupMessageAsync(groupContext.GroupId, response);
5369
}

src/EleCho.GoCqHttpSdk.CommandExecuting/EleCho.GoCqHttpSdk.CommandExecuting.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFrameworks>net6.0;net7.0;netcoreapp3.1;netstandard2.0;net462</TargetFrameworks>
55
<Nullable>enable</Nullable>
66
<LangVersion>latest</LangVersion>
7-
<Version>1.0.2</Version>
7+
<Version>1.0.4</Version>
88
<Description>EleCho.GoCqHttpSdk 的指令执行拓展</Description>
99
<Copyright>Copyright (c) EleCho 2023</Copyright>
1010
<RepositoryUrl>https://github.com/OrgEleCho/EleCho.GoCqHttpSdk</RepositoryUrl>

src/EleCho.GoCqHttpSdk.MessageMatching/EleCho.GoCqHttpSdk.MessageMatching.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFrameworks>net6.0;net7.0;netcoreapp3.1;netstandard2.0;net462</TargetFrameworks>
55
<Nullable>enable</Nullable>
66
<LangVersion>latest</LangVersion>
7-
<Version>1.0.2</Version>
7+
<Version>1.0.3</Version>
88
<Description>EleCho.GoCqHttpSdk 的消息匹配拓展</Description>
99
<Copyright>Copyright (c) EleCho 2023</Copyright>
1010
<RepositoryUrl>https://github.com/OrgEleCho/EleCho.GoCqHttpSdk</RepositoryUrl>

src/EleCho.GoCqHttpSdk/Action/CqGetGroupInformationAction.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ namespace EleCho.GoCqHttpSdk.Action
1313
public class CqGetGroupInformationAction : CqAction
1414
{
1515
/// <summary>
16-
/// 实例化对象
16+
/// 实例化对象 (使用缓存)
1717
/// </summary>
1818
/// <param name="groupId">群号</param>
19-
public CqGetGroupInformationAction(long groupId)
20-
{
21-
GroupId = groupId;
22-
NoCache = false;
23-
}
19+
public CqGetGroupInformationAction(long groupId) : this(groupId, false)
20+
{ }
2421

2522
/// <summary>
2623
/// 实例化对象

src/EleCho.GoCqHttpSdk/Action/CqGetGroupListAction.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,29 @@ public class CqGetGroupListAction : CqAction
1212
/// </summary>
1313
public override CqActionType ActionType => CqActionType.GetGroupList;
1414

15+
/// <summary>
16+
/// 是否不使用缓存
17+
/// </summary>
18+
public bool NoCache { get; set; }
19+
20+
/// <summary>
21+
/// 创建实例 (NoCache = false)
22+
/// </summary>
23+
public CqGetGroupListAction() : this(false)
24+
{ }
25+
26+
/// <summary>
27+
/// 创建实例
28+
/// </summary>
29+
/// <param name="noCache">是否不使用缓存</param>
30+
public CqGetGroupListAction(bool noCache)
31+
{
32+
NoCache = noCache;
33+
}
34+
1535
internal override CqActionParamsModel GetParamsModel()
1636
{
17-
return new CqGetGroupListActionParamsModel();
37+
return new CqGetGroupListActionParamsModel(NoCache);
1838
}
1939
}
2040
}

src/EleCho.GoCqHttpSdk/Action/CqGetGroupMemberInformationAction.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,12 @@ namespace EleCho.GoCqHttpSdk.Action
1313
public class CqGetGroupMemberInformationAction : CqAction
1414
{
1515
/// <summary>
16-
/// 实例化对象
16+
/// 实例化对象 (NoCache = false)
1717
/// </summary>
1818
/// <param name="groupId">群号</param>
1919
/// <param name="userId">用户 QQ</param>
20-
public CqGetGroupMemberInformationAction(long groupId, long userId)
21-
{
22-
GroupId = groupId;
23-
UserId = userId;
24-
NoCache = false;
25-
}
20+
public CqGetGroupMemberInformationAction(long groupId, long userId) : this(groupId, userId, false)
21+
{ }
2622

2723
/// <summary>
2824
/// 实例化对象
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using EleCho.GoCqHttpSdk.Action.Model.Params;
2+
3+
namespace EleCho.GoCqHttpSdk.Action
4+
{
5+
/// <summary>
6+
/// 获取群成员列表操作
7+
/// </summary>
8+
public class CqGetGroupMemberListAction : CqAction
9+
{
10+
/// <summary>
11+
/// 操作类型: 获取群成员列表
12+
/// </summary>
13+
public override CqActionType ActionType => CqActionType.GetGroupMemberList;
14+
15+
/// <summary>
16+
/// 群号
17+
/// </summary>
18+
public long GroupId { get; }
19+
20+
/// <summary>
21+
/// 不使用缓存
22+
/// </summary>
23+
public bool NoCache { get; }
24+
25+
/// <summary>
26+
/// 实例化对象 (NoCache = false)
27+
/// </summary>
28+
/// <param name="groupId">群号</param>
29+
public CqGetGroupMemberListAction(long groupId) : this(groupId, false)
30+
{ }
31+
32+
/// <summary>
33+
/// 实例化对象
34+
/// </summary>
35+
/// <param name="groupId">群号</param>
36+
/// <param name="noCache">不使用缓存</param>
37+
public CqGetGroupMemberListAction(long groupId, bool noCache)
38+
{
39+
GroupId = groupId;
40+
NoCache = noCache;
41+
}
42+
43+
internal override CqActionParamsModel GetParamsModel()
44+
{
45+
return new CqGetGroupMemberListActionParamsModel(GroupId, NoCache);
46+
}
47+
}
48+
}

src/EleCho.GoCqHttpSdk/Action/CqGetStrangerInformationAction.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,11 @@ public CqGetStrangerInformationAction(long userId, bool noCache)
3535
}
3636

3737
/// <summary>
38-
/// 实例化对象
38+
/// 实例化对象 (NoCache = false)
3939
/// </summary>
4040
/// <param name="userId">用户 QQ</param>
41-
public CqGetStrangerInformationAction(long userId)
42-
{
43-
UserId = userId;
44-
NoCache = false;
45-
}
41+
public CqGetStrangerInformationAction(long userId) : this(userId, false)
42+
{ }
4643

4744
internal override CqActionParamsModel GetParamsModel()
4845
{

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
{
33
internal class CqGetGroupListActionParamsModel : CqActionParamsModel
44
{
5-
// no param
5+
public CqGetGroupListActionParamsModel(bool no_cache)
6+
{
7+
this.no_cache = no_cache;
8+
}
9+
10+
public bool no_cache { get; set; }
611
}
712
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace EleCho.GoCqHttpSdk.Action.Model.Params
2+
{
3+
internal class CqGetGroupMemberListActionParamsModel : CqActionParamsModel
4+
{
5+
public CqGetGroupMemberListActionParamsModel(long group_id, bool no_cache)
6+
{
7+
this.group_id = group_id;
8+
this.no_cache = no_cache;
9+
}
10+
11+
public long group_id { get; }
12+
public bool no_cache { get; }
13+
}
14+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ internal class CqActionResultDataModel
3131

3232
GetFriendList => dataValue.Deserialize<CqGetFriendListActionResultDataModel>(JsonHelper.Options),
3333
GetGroupList => dataValue.Deserialize<CqGetGroupListActionResultDataModel>(JsonHelper.Options),
34+
GetGroupMemberList => dataValue.Deserialize<CqGetGroupMemberListActionResultDataModel>(JsonHelper.Options),
35+
3436

3537
GetLoginInfo => dataValue.Deserialize<CqGetLoginInformationActionResultDataModel>(JsonHelper.Options),
3638
GetStrangerInfo => dataValue.Deserialize<CqGetStrangerInformationActionResultDataModel>(JsonHelper.Options),

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using EleCho.GoCqHttpSdk.DataStructure.Model;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -7,6 +8,9 @@
78

89
namespace EleCho.GoCqHttpSdk.Action.Model.ResultData
910
{
11+
/// <summary>
12+
/// The same as <seealso cref="CqGroupModel"/>
13+
/// </summary>
1014
internal class CqGetGroupInformationActionResultDataModel : CqActionResultDataModel
1115
{
1216
[JsonConstructor]

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using EleCho.GoCqHttpSdk.DataStructure.Model;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -7,6 +8,9 @@
78

89
namespace EleCho.GoCqHttpSdk.Action.Model.ResultData
910
{
11+
/// <summary>
12+
/// The same as <seealso cref="CqGroupMemberModel"/>
13+
/// </summary>
1014
internal class CqGetGroupMemberInformationActionResultDataModel : CqActionResultDataModel
1115
{
1216
[JsonConstructor]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using EleCho.GoCqHttpSdk.DataStructure.Model;
4+
5+
namespace EleCho.GoCqHttpSdk.Action.Model.ResultData
6+
{
7+
internal class CqGetGroupMemberListActionResultDataModel : CqActionResultDataModel, IList<CqGroupMemberModel>
8+
{
9+
readonly List<CqGroupMemberModel> list = new List<CqGroupMemberModel>();
10+
11+
public CqGroupMemberModel this[int index] { get => list[index]; set => list[index] = value; }
12+
13+
public int Count => list.Count;
14+
15+
public bool IsReadOnly => false;
16+
17+
public void Add(CqGroupMemberModel item) => list.Add(item);
18+
public void Clear() => list.Clear();
19+
public bool Contains(CqGroupMemberModel item) => list.Contains(item);
20+
public void CopyTo(CqGroupMemberModel[] array, int arrayIndex) => list.CopyTo(array, arrayIndex);
21+
public IEnumerator<CqGroupMemberModel> GetEnumerator() => list.GetEnumerator();
22+
public int IndexOf(CqGroupMemberModel item) => list.IndexOf(item);
23+
public void Insert(int index, CqGroupMemberModel item) => list.Insert(index, item);
24+
public bool Remove(CqGroupMemberModel item) => list.Remove(item);
25+
public void RemoveAt(int index) => list.RemoveAt(index);
26+
IEnumerator IEnumerable.GetEnumerator() => list.GetEnumerator();
27+
}
28+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ internal static CqActionResult CreateActionResultFromActionType(string actionTyp
5858

5959
GetFriendList => new CqGetFriendListActionResult(),
6060
GetGroupList => new CqGetGroupListActionResult(),
61+
GetGroupMemberList => new CqGetGroupMemberListActionResult(),
6162

6263
GetLoginInfo => new CqGetLoginInformationActionResult(),
6364
GetStrangerInfo => new CqGetStrangerInformationActionResult(),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Linq;
5+
using System.Text.RegularExpressions;
56

67
namespace EleCho.GoCqHttpSdk.Action
78
{
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using EleCho.GoCqHttpSdk.Action.Model.ResultData;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
namespace EleCho.GoCqHttpSdk.Action
7+
{
8+
/// <summary>
9+
/// 获取群成员列表操作结果
10+
/// </summary>
11+
public record class CqGetGroupMemberListActionResult : CqActionResult
12+
{
13+
internal CqGetGroupMemberListActionResult() { }
14+
15+
/// <summary>
16+
/// 成员
17+
/// </summary>
18+
public IReadOnlyList<CqGroupMember> Members { get; private set; } = new List<CqGroupMember>(0).AsReadOnly();
19+
20+
internal override void ReadDataModel(CqActionResultDataModel? model)
21+
{
22+
if (model is not CqGetGroupMemberListActionResultDataModel m)
23+
throw new ArgumentException();
24+
25+
Members = m.Select(fm => new CqGroupMember(fm)).ToList().AsReadOnly();
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)