-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented GroupRename and GroupRemark
- Loading branch information
Linwenxuan
authored and
Linwenxuan
committed
Oct 14, 2023
1 parent
4b3ca34
commit 3e1fefa
Showing
13 changed files
with
245 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Lagrange.Core/Internal/Event/Protocol/Action/GroupRemarkEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace Lagrange.Core.Internal.Event.Protocol.Action; | ||
|
||
internal class GroupRemarkEvent : ProtocolEvent | ||
{ | ||
public uint GroupUin { get; set; } | ||
|
||
public string TargetRemark { get; set; } = ""; | ||
|
||
private GroupRemarkEvent(uint groupUin, string targetRemark) : base(true) | ||
{ | ||
GroupUin = groupUin; | ||
TargetRemark = targetRemark; | ||
} | ||
|
||
private GroupRemarkEvent(int resultCode) : base(resultCode) { } | ||
|
||
public static GroupRemarkEvent Create(uint groupUin, string targetRemark) => new(groupUin, targetRemark); | ||
|
||
public static GroupRemarkEvent Result(int resultCode) => new(resultCode); | ||
} |
20 changes: 20 additions & 0 deletions
20
Lagrange.Core/Internal/Event/Protocol/Action/GroupRenameEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace Lagrange.Core.Internal.Event.Protocol.Action; | ||
|
||
internal class GroupRenameEvent : ProtocolEvent | ||
{ | ||
public uint GroupUin { get; set; } | ||
|
||
public string TargetName { get; set; } = ""; | ||
|
||
private GroupRenameEvent(uint groupUin, string targetName) : base(true) | ||
{ | ||
GroupUin = groupUin; | ||
TargetName = targetName; | ||
} | ||
|
||
private GroupRenameEvent(int resultCode) : base(resultCode) { } | ||
|
||
public static GroupRenameEvent Create(uint groupUin, string targetName) => new(groupUin, targetName); | ||
|
||
public static GroupRenameEvent Result(int resultCode) => new(resultCode); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0xF16_1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using ProtoBuf; | ||
|
||
namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request; | ||
|
||
#pragma warning disable CS8618 | ||
// ReSharper disable InconsistentNaming | ||
|
||
/// <summary> | ||
/// Group Remark | ||
/// </summary> | ||
[ProtoContract] | ||
[OidbSvcTrpcTcp(0xF16, 1)] | ||
internal class OidbSvcTrpcTcp0xF16_1 | ||
{ | ||
[ProtoMember(1)] public OidbSvcTrpcTcp0xF16_1Body Body { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class OidbSvcTrpcTcp0xF16_1Body | ||
{ | ||
[ProtoMember(1)] public uint GroupUin { get; set; } | ||
|
||
[ProtoMember(3)] public string TargetRemark { get; set; } | ||
} |
44 changes: 44 additions & 0 deletions
44
Lagrange.Core/Internal/Service/Action/GroupRemarkService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Lagrange.Core.Common; | ||
using Lagrange.Core.Internal.Event.Protocol; | ||
using Lagrange.Core.Internal.Event.Protocol.Action; | ||
using Lagrange.Core.Internal.Packets.Service.Oidb; | ||
using Lagrange.Core.Internal.Packets.Service.Oidb.Request; | ||
using Lagrange.Core.Utility.Binary; | ||
using ProtoBuf; | ||
|
||
namespace Lagrange.Core.Internal.Service.Action; | ||
|
||
[EventSubscribe(typeof(GroupRemarkEvent))] | ||
[Service("OidbSvcTrpcTcp.0xf16_1")] | ||
internal class GroupRemarkService : BaseService<GroupRemarkEvent> | ||
{ | ||
protected override bool Build(GroupRemarkEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, | ||
out BinaryPacket output, out List<BinaryPacket>? extraPackets) | ||
{ | ||
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0xF16_1>(new OidbSvcTrpcTcp0xF16_1 | ||
{ | ||
Body = new OidbSvcTrpcTcp0xF16_1Body | ||
{ | ||
GroupUin = input.GroupUin, | ||
TargetRemark = input.TargetRemark | ||
} | ||
}); | ||
|
||
var stream = new MemoryStream(); | ||
Serializer.Serialize(stream, packet); | ||
output = new BinaryPacket(stream); | ||
|
||
extraPackets = null; | ||
return true; | ||
} | ||
|
||
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, | ||
out GroupRemarkEvent output, out List<ProtocolEvent>? extraEvents) | ||
{ | ||
var payload = Serializer.Deserialize<OidbSvcTrpcTcpResponse<byte[]>>(input.AsSpan()); | ||
|
||
output = GroupRemarkEvent.Result((int)payload.ErrorCode); | ||
extraEvents = null; | ||
return true; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
Lagrange.Core/Internal/Service/Action/GroupRenameService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Lagrange.Core.Common; | ||
using Lagrange.Core.Internal.Event.Protocol; | ||
using Lagrange.Core.Internal.Event.Protocol.Action; | ||
using Lagrange.Core.Internal.Packets.Service.Oidb; | ||
using Lagrange.Core.Internal.Packets.Service.Oidb.Request; | ||
using Lagrange.Core.Utility.Binary; | ||
using ProtoBuf; | ||
|
||
namespace Lagrange.Core.Internal.Service.Action; | ||
|
||
[EventSubscribe(typeof(GroupRenameEvent))] | ||
[Service("OidbSvcTrpcTcp.0x89a_15")] | ||
internal class GroupRenameService : BaseService<GroupRenameEvent> | ||
{ | ||
protected override bool Build(GroupRenameEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, | ||
out BinaryPacket output, out List<BinaryPacket>? extraPackets) | ||
{ | ||
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x89A_15>(new OidbSvcTrpcTcp0x89A_15 | ||
{ | ||
GroupUin = input.GroupUin, | ||
Body = new OidbSvcTrpcTcp0x89A_15Body { TargetName = input.TargetName } | ||
}); | ||
|
||
var stream = new MemoryStream(); | ||
Serializer.Serialize(stream, packet); | ||
output = new BinaryPacket(stream); | ||
|
||
extraPackets = null; | ||
return true; | ||
} | ||
|
||
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, | ||
out GroupRenameEvent output, out List<ProtocolEvent>? extraEvents) | ||
{ | ||
var payload = Serializer.Deserialize<OidbSvcTrpcTcpResponse<byte[]>>(input.AsSpan()); | ||
|
||
output = GroupRenameEvent.Result((int)payload.ErrorCode); | ||
extraEvents = null; | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Lagrange.OneBot.Core.Entity.Action; | ||
|
||
[Serializable] | ||
public class OneBotSetGroupCard | ||
{ | ||
[JsonPropertyName("user_id")] public uint UserId { get; set; } | ||
|
||
[JsonPropertyName("group_id")] public uint GroupId { get; set; } | ||
|
||
[JsonPropertyName("card")] public string Card { get; set; } = ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Lagrange.OneBot.Core.Entity.Action; | ||
|
||
[Serializable] | ||
public class OneBotSetGroupName | ||
{ | ||
[JsonPropertyName("group_id")] public uint GroupId { get; set; } | ||
|
||
[JsonPropertyName("group_name")] public string GroupName { get; set; } = ""; | ||
} |
24 changes: 24 additions & 0 deletions
24
Lagrange.OneBot/Core/Operation/Group/SetGroupCardOperation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using Lagrange.Core; | ||
using Lagrange.Core.Common.Interface.Api; | ||
using Lagrange.OneBot.Core.Entity.Action; | ||
|
||
namespace Lagrange.OneBot.Core.Operation.Group; | ||
|
||
[Operation("set_group_card")] | ||
public class SetGroupCardOperation : IOperation | ||
{ | ||
public async Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload) | ||
{ | ||
var message = payload.Deserialize<OneBotSetGroupCard>(); | ||
|
||
if (message != null) | ||
{ | ||
bool _ = await context.RenameGroupMember(message.GroupId, message.UserId, message.Card); | ||
return new OneBotResult(null, 0, "ok", echo); | ||
} | ||
|
||
throw new Exception(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Lagrange.OneBot/Core/Operation/Group/SetGroupNameOperation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using Lagrange.Core; | ||
using Lagrange.Core.Common.Interface.Api; | ||
using Lagrange.OneBot.Core.Entity.Action; | ||
|
||
namespace Lagrange.OneBot.Core.Operation.Group; | ||
|
||
[Operation("set_group_name")] | ||
public class SetGroupNameOperation : IOperation | ||
{ | ||
public async Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload) | ||
{ | ||
var message = payload.Deserialize<OneBotSetGroupName>(); | ||
|
||
if (message != null) | ||
{ | ||
bool _ = await context.RenameGroup(message.GroupId, message.GroupName); | ||
return new OneBotResult(null, 0, "ok", echo); | ||
} | ||
|
||
throw new Exception(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters