Skip to content

Commit

Permalink
feat: 添加了 GetGroupMemberList 操作
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimeNull committed Mar 23, 2023
1 parent 626d934 commit 452cabb
Show file tree
Hide file tree
Showing 31 changed files with 519 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class CqCommandExecutePostPlugin : CommandLineApp
public bool IgnoreCases { get; set; } = true;
public bool AllowGroupMessage { get; set; } = true;
public bool AllowPrivateMessage { get; set; } = true;
public bool ExecuteNextWhenExecuted { get; set; } = false;
public bool ExecuteNextWhenExecuted { get; set; } = true;

private StringComparison GetStringComparison()
{
Expand All @@ -30,7 +30,7 @@ public async Task Execute(CqPostContext context, Func<Task> next)
{
if (context is CqMessagePostContext msgContext && msgContext.Message.Text.StartsWith(Prefix))
{
string commandLine =
string commandLine =
msgContext.Message.Text.Substring(Prefix.Length);

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

if (ReplyInvoker)
response.WithHead(new CqReplyMsg(msgContext.MessageId));
if (AtInvoker)
response.WithHead(new CqAtMsg(groupContext.UserId));
{
if (AtInvoker)
{
response.WithHead(new CqAtMsg(groupContext.UserId));
response.WithHead(new CqTextMsg(" "));
response.WithHead(new CqReplyMsg(msgContext.MessageId));
}
else
{
response.WithHead(new CqReplyMsg(msgContext.MessageId));
}
}
else
{
if (AtInvoker)
{
response.WithHead(new CqAtMsg(groupContext.UserId));
}
}

await actionSession.SendGroupMessageAsync(groupContext.GroupId, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net6.0;net7.0;netcoreapp3.1;netstandard2.0;net462</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<Version>1.0.2</Version>
<Version>1.0.4</Version>
<Description>EleCho.GoCqHttpSdk 的指令执行拓展</Description>
<Copyright>Copyright (c) EleCho 2023</Copyright>
<RepositoryUrl>https://github.com/OrgEleCho/EleCho.GoCqHttpSdk</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net6.0;net7.0;netcoreapp3.1;netstandard2.0;net462</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
<Description>EleCho.GoCqHttpSdk 的消息匹配拓展</Description>
<Copyright>Copyright (c) EleCho 2023</Copyright>
<RepositoryUrl>https://github.com/OrgEleCho/EleCho.GoCqHttpSdk</RepositoryUrl>
Expand Down
9 changes: 3 additions & 6 deletions src/EleCho.GoCqHttpSdk/Action/CqGetGroupInformationAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ namespace EleCho.GoCqHttpSdk.Action
public class CqGetGroupInformationAction : CqAction
{
/// <summary>
/// 实例化对象
/// 实例化对象 (使用缓存)
/// </summary>
/// <param name="groupId">群号</param>
public CqGetGroupInformationAction(long groupId)
{
GroupId = groupId;
NoCache = false;
}
public CqGetGroupInformationAction(long groupId) : this(groupId, false)
{ }

/// <summary>
/// 实例化对象
Expand Down
22 changes: 21 additions & 1 deletion src/EleCho.GoCqHttpSdk/Action/CqGetGroupListAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,29 @@ public class CqGetGroupListAction : CqAction
/// </summary>
public override CqActionType ActionType => CqActionType.GetGroupList;

/// <summary>
/// 是否不使用缓存
/// </summary>
public bool NoCache { get; set; }

/// <summary>
/// 创建实例 (NoCache = false)
/// </summary>
public CqGetGroupListAction() : this(false)
{ }

/// <summary>
/// 创建实例
/// </summary>
/// <param name="noCache">是否不使用缓存</param>
public CqGetGroupListAction(bool noCache)
{
NoCache = noCache;
}

internal override CqActionParamsModel GetParamsModel()
{
return new CqGetGroupListActionParamsModel();
return new CqGetGroupListActionParamsModel(NoCache);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ namespace EleCho.GoCqHttpSdk.Action
public class CqGetGroupMemberInformationAction : CqAction
{
/// <summary>
/// 实例化对象
/// 实例化对象 (NoCache = false)
/// </summary>
/// <param name="groupId">群号</param>
/// <param name="userId">用户 QQ</param>
public CqGetGroupMemberInformationAction(long groupId, long userId)
{
GroupId = groupId;
UserId = userId;
NoCache = false;
}
public CqGetGroupMemberInformationAction(long groupId, long userId) : this(groupId, userId, false)
{ }

/// <summary>
/// 实例化对象
Expand Down
48 changes: 48 additions & 0 deletions src/EleCho.GoCqHttpSdk/Action/CqGetGroupMemberListAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using EleCho.GoCqHttpSdk.Action.Model.Params;

namespace EleCho.GoCqHttpSdk.Action
{
/// <summary>
/// 获取群成员列表操作
/// </summary>
public class CqGetGroupMemberListAction : CqAction
{
/// <summary>
/// 操作类型: 获取群成员列表
/// </summary>
public override CqActionType ActionType => CqActionType.GetGroupMemberList;

/// <summary>
/// 群号
/// </summary>
public long GroupId { get; }

/// <summary>
/// 不使用缓存
/// </summary>
public bool NoCache { get; }

/// <summary>
/// 实例化对象 (NoCache = false)
/// </summary>
/// <param name="groupId">群号</param>
public CqGetGroupMemberListAction(long groupId) : this(groupId, false)
{ }

/// <summary>
/// 实例化对象
/// </summary>
/// <param name="groupId">群号</param>
/// <param name="noCache">不使用缓存</param>
public CqGetGroupMemberListAction(long groupId, bool noCache)
{
GroupId = groupId;
NoCache = noCache;
}

internal override CqActionParamsModel GetParamsModel()
{
return new CqGetGroupMemberListActionParamsModel(GroupId, NoCache);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,11 @@ public CqGetStrangerInformationAction(long userId, bool noCache)
}

/// <summary>
/// 实例化对象
/// 实例化对象 (NoCache = false)
/// </summary>
/// <param name="userId">用户 QQ</param>
public CqGetStrangerInformationAction(long userId)
{
UserId = userId;
NoCache = false;
}
public CqGetStrangerInformationAction(long userId) : this(userId, false)
{ }

internal override CqActionParamsModel GetParamsModel()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
{
internal class CqGetGroupListActionParamsModel : CqActionParamsModel
{
// no param
public CqGetGroupListActionParamsModel(bool no_cache)
{
this.no_cache = no_cache;
}

public bool no_cache { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace EleCho.GoCqHttpSdk.Action.Model.Params
{
internal class CqGetGroupMemberListActionParamsModel : CqActionParamsModel
{
public CqGetGroupMemberListActionParamsModel(long group_id, bool no_cache)
{
this.group_id = group_id;
this.no_cache = no_cache;
}

public long group_id { get; }
public bool no_cache { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ internal class CqActionResultDataModel

GetFriendList => dataValue.Deserialize<CqGetFriendListActionResultDataModel>(JsonHelper.Options),
GetGroupList => dataValue.Deserialize<CqGetGroupListActionResultDataModel>(JsonHelper.Options),
GetGroupMemberList => dataValue.Deserialize<CqGetGroupMemberListActionResultDataModel>(JsonHelper.Options),


GetLoginInfo => dataValue.Deserialize<CqGetLoginInformationActionResultDataModel>(JsonHelper.Options),
GetStrangerInfo => dataValue.Deserialize<CqGetStrangerInformationActionResultDataModel>(JsonHelper.Options),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using EleCho.GoCqHttpSdk.DataStructure.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -7,6 +8,9 @@

namespace EleCho.GoCqHttpSdk.Action.Model.ResultData
{
/// <summary>
/// The same as <seealso cref="CqGroupModel"/>
/// </summary>
internal class CqGetGroupInformationActionResultDataModel : CqActionResultDataModel
{
[JsonConstructor]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using EleCho.GoCqHttpSdk.DataStructure.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -7,6 +8,9 @@

namespace EleCho.GoCqHttpSdk.Action.Model.ResultData
{
/// <summary>
/// The same as <seealso cref="CqGroupMemberModel"/>
/// </summary>
internal class CqGetGroupMemberInformationActionResultDataModel : CqActionResultDataModel
{
[JsonConstructor]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using EleCho.GoCqHttpSdk.DataStructure.Model;

namespace EleCho.GoCqHttpSdk.Action.Model.ResultData
{
internal class CqGetGroupMemberListActionResultDataModel : CqActionResultDataModel, IList<CqGroupMemberModel>
{
readonly List<CqGroupMemberModel> list = new List<CqGroupMemberModel>();

public CqGroupMemberModel this[int index] { get => list[index]; set => list[index] = value; }

public int Count => list.Count;

public bool IsReadOnly => false;

public void Add(CqGroupMemberModel item) => list.Add(item);
public void Clear() => list.Clear();
public bool Contains(CqGroupMemberModel item) => list.Contains(item);
public void CopyTo(CqGroupMemberModel[] array, int arrayIndex) => list.CopyTo(array, arrayIndex);
public IEnumerator<CqGroupMemberModel> GetEnumerator() => list.GetEnumerator();
public int IndexOf(CqGroupMemberModel item) => list.IndexOf(item);
public void Insert(int index, CqGroupMemberModel item) => list.Insert(index, item);
public bool Remove(CqGroupMemberModel item) => list.Remove(item);
public void RemoveAt(int index) => list.RemoveAt(index);
IEnumerator IEnumerable.GetEnumerator() => list.GetEnumerator();
}
}
1 change: 1 addition & 0 deletions src/EleCho.GoCqHttpSdk/Action/Result/CqActionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ internal static CqActionResult CreateActionResultFromActionType(string actionTyp

GetFriendList => new CqGetFriendListActionResult(),
GetGroupList => new CqGetGroupListActionResult(),
GetGroupMemberList => new CqGetGroupMemberListActionResult(),

GetLoginInfo => new CqGetLoginInformationActionResult(),
GetStrangerInfo => new CqGetStrangerInformationActionResult(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace EleCho.GoCqHttpSdk.Action
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using EleCho.GoCqHttpSdk.Action.Model.ResultData;
using System;
using System.Collections.Generic;
using System.Linq;

namespace EleCho.GoCqHttpSdk.Action
{
/// <summary>
/// 获取群成员列表操作结果
/// </summary>
public record class CqGetGroupMemberListActionResult : CqActionResult
{
internal CqGetGroupMemberListActionResult() { }

/// <summary>
/// 成员
/// </summary>
public IReadOnlyList<CqGroupMember> Members { get; private set; } = new List<CqGroupMember>(0).AsReadOnly();

internal override void ReadDataModel(CqActionResultDataModel? model)
{
if (model is not CqGetGroupMemberListActionResultDataModel m)
throw new ArgumentException();

Members = m.Select(fm => new CqGroupMember(fm)).ToList().AsReadOnly();
}
}
}
Loading

0 comments on commit 452cabb

Please sign in to comment.