Skip to content

Commit

Permalink
加一个api
Browse files Browse the repository at this point in the history
  • Loading branch information
sisi0318 committed Jul 23, 2024
1 parent e9c746d commit 82fdd36
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Lagrange.Core/Common/Interface/Api/GroupExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public static Task<bool> SetGroupAdmin(this BotContext bot, uint groupUin, uint

public static Task<bool> SetGroupBot(this BotContext bot, uint targetUin, uint On, uint groupUin)
=> bot.ContextCollection.Business.OperationLogic.SetGroupBot(targetUin, On, groupUin);

public static Task<bool> SetGroupBotHD(this BotContext bot, uint targetUin, uint groupUin)
=> bot.ContextCollection.Business.OperationLogic.SetGroupBotHD(targetUin, groupUin);

public static Task<bool> RenameGroupMember(this BotContext bot, uint groupUin, uint targetUin, string targetName)
=> bot.ContextCollection.Business.OperationLogic.RenameGroupMember(groupUin, targetUin, targetName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ public async Task<bool> SetGroupBot(uint BotId , uint On , uint groupUin)
return events.Count != 0 && ((GroupSetBotEvent)events[0]).ResultCode == 0;
}

public async Task<bool> SetGroupBotHD(uint BotId , uint groupUin)
{
var muteBotEvent = GroupSetBothdEvent.Create(BotId, groupUin);
var events = await Collection.Business.SendEvent(muteBotEvent);
return events.Count != 0 && ((GroupSetBothdEvent)events[0]).ResultCode == 0;
}

public async Task<bool> RenameGroupMember(uint groupUin, uint targetUin, string targetName)
{
string? uid = await Collection.Business.CachingLogic.ResolveUid(groupUin, targetUin);
Expand Down
20 changes: 20 additions & 0 deletions Lagrange.Core/Internal/Event/Action/GroupSetBothdEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Lagrange.Core.Internal.Event.Action;

internal class GroupSetBothdEvent : ProtocolEvent
{
public uint BotId { get; set; }

public uint GroupUin { get; set; }

private GroupSetBothdEvent(uint botId, uint groupuin) : base(0)
{
BotId = botId;
GroupUin = groupuin;
}

private GroupSetBothdEvent(int resultCode) : base(resultCode) { }

public static GroupSetBothdEvent Create(uint botId, uint groupuin) => new(botId, groupuin);

public static GroupSetBothdEvent Result(int resultCode) => new(resultCode);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using ProtoBuf;

namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request;

// ReSharper disable InconsistentNaming
#pragma warning disable CS8618

[ProtoContract]
[OidbSvcTrpcTcp(0x112E, 1)]
internal class OidbSvcTrpcTcp0x112E_1
{
[ProtoMember(3)] public uint BotId { get; set; }

[ProtoMember(4)] public uint Seq { get; set; } = 111111;

[ProtoMember(5)] public string B_id { get; set; } = "";

[ProtoMember(6)] public string B_data { get; set; } = "";

[ProtoMember(7)] public uint IDD { get; set; } = 0;

[ProtoMember(8)] public uint GroupUin { get; set; }

[ProtoMember(9)] public uint GroupType { get; set; } = 1;
}
35 changes: 35 additions & 0 deletions Lagrange.Core/Internal/Service/Action/GroupSetBothdService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Event;
using Lagrange.Core.Internal.Event.Action;
using Lagrange.Core.Internal.Packets.Service.Oidb;
using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
using Lagrange.Core.Internal.Packets.Service.Oidb.Response;
using Lagrange.Core.Utility.Binary;
using Lagrange.Core.Utility.Extension;
using ProtoBuf;

namespace Lagrange.Core.Internal.Service.Action;

[EventSubscribe(typeof(GroupSetBothdEvent))]
[Service("OidbSvcTrpcTcp.0x112e_1")]
internal class GroupSetBothdService : BaseService<GroupSetBothdEvent>
{
protected override bool Build(GroupSetBothdEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out BinaryPacket output, out List<BinaryPacket>? extraPackets)
{
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x112E_1>(new OidbSvcTrpcTcp0x112E_1
{
BotId = input.BotId,
Seq = 11111,
B_id = "",
B_data = "",
IDD = 0,
GroupUin = input.GroupUin,
GroupType = 1
});
output = packet.Serialize();
extraPackets = null;
return true;
}

}
12 changes: 12 additions & 0 deletions Lagrange.OneBot/Core/Entity/Action/OneBotSetGroupBothd.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;

namespace Lagrange.OneBot.Core.Entity.Action;

[Serializable]
public class OneBotSetGroupBothd
{
[JsonPropertyName("group_id")] public uint GroupId { get; set; }

[JsonPropertyName("bot_id")] public uint BotId { get; set; }

}
26 changes: 26 additions & 0 deletions Lagrange.OneBot/Core/Operation/Group/SetGroupBothdOperation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Text.Json;
using System.Text.Json.Nodes;
using Lagrange.Core;
using Lagrange.Core.Common.Interface.Api;
using Lagrange.OneBot.Core.Entity.Action;
using Lagrange.OneBot.Core.Operation.Converters;

namespace Lagrange.OneBot.Core.Operation.Group;

[Operation("set_group_bot_hd")]
public class SetGroupBothdOperation : IOperation
{
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
{
var message = payload.Deserialize<OneBotSetGroupBothd>(SerializerOptions.DefaultOptions);

if (message != null)
{
bool _ = await context.SetGroupBotHD(message.BotId, message.GroupId);

return new OneBotResult(message.BotId, 0, "ok");
}

throw new Exception();
}
}

0 comments on commit 82fdd36

Please sign in to comment.