Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Lagrange.Core/Common/Entity/BotGroupInviteNotification.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Lagrange.Core.Common.Entity;

public class BotGroupInviteNotification(long group, ulong sequence, long targetUin, string targetUid, BotGroupNotificationState state, long? operatorUin, string? operatorUid, long inviterUin, string inviterUid) : BotGroupNotificationBase(group, sequence, BotGroupNotificationType.Invite, targetUin, targetUid)
public class BotGroupInviteNotification(long group, ulong sequence, long targetUin, string targetUid, BotGroupNotificationState state, long? operatorUin, string? operatorUid, long inviterUin, string inviterUid, bool isFiltered) : BotGroupNotificationBase(group, sequence, BotGroupNotificationType.Invite, targetUin, targetUid)
{
public BotGroupNotificationState State { get; } = state;

Expand All @@ -11,4 +11,6 @@ public class BotGroupInviteNotification(long group, ulong sequence, long targetU
public long InviterUin { get; } = inviterUin;

public string InviterUid { get; } = inviterUid;

public bool IsFiltered { get; } = isFiltered;
}
4 changes: 3 additions & 1 deletion Lagrange.Core/Common/Entity/BotGroupJoinNotification.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Lagrange.Core.Common.Entity;

public class BotGroupJoinNotification(long group, ulong sequence, long targetUin, string targetUid, BotGroupNotificationState state, long? operatorUin, string? operatorUid, string comment) : BotGroupNotificationBase(group, sequence, BotGroupNotificationType.Join, targetUin, targetUid)
public class BotGroupJoinNotification(long group, ulong sequence, long targetUin, string targetUid, BotGroupNotificationState state, long? operatorUin, string? operatorUid, string comment, bool isFiltered) : BotGroupNotificationBase(group, sequence, BotGroupNotificationType.Join, targetUin, targetUid)
{
public BotGroupNotificationState State { get; } = state;

Expand All @@ -9,4 +9,6 @@ public class BotGroupJoinNotification(long group, ulong sequence, long targetUin
public string? OperatorUid { get; } = operatorUid;

public string Comment { get; } = comment;

public bool IsFiltered { get; } = isFiltered;
}
11 changes: 7 additions & 4 deletions Lagrange.Core/Common/Interface/OperationExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ public static Task<List<BotGroup>> FetchGroups(this BotContext context, bool ref
public static Task<List<BotGroupMember>> FetchMembers(this BotContext context, long groupUin, bool refresh = false) =>
context.CacheContext.GetMemberList(groupUin, refresh);

public static Task<List<BotGroupNotificationBase>> FetchGroupNotifications(this BotContext context, ulong count) =>
context.EventContext.GetLogic<OperationLogic>().FetchGroupNotifications(count);
public static Task<List<BotGroupNotificationBase>> FetchGroupNotifications(this BotContext context, ulong count, ulong start = 0) =>
context.EventContext.GetLogic<OperationLogic>().FetchGroupNotifications(count, start);

public static Task<List<BotGroupNotificationBase>> FetchFilteredGroupNotifications(this BotContext context, ulong count, ulong start = 0) =>
context.EventContext.GetLogic<OperationLogic>().FetchFilteredGroupNotifications(count, start);

public static Task<BotStranger> FetchStranger(this BotContext context, long uin) =>
context.EventContext.GetLogic<OperationLogic>().FetchStranger(uin);

public static Task SetGroupNotification(this BotContext context, long groupUin, ulong sequence, BotGroupNotificationType type, GroupNotificationOperate operate, string message = "") =>
context.EventContext.GetLogic<OperationLogic>().SetGroupNotification(groupUin, sequence, type, operate, message);
public static Task SetGroupNotification(this BotContext context, long groupUin, ulong sequence, BotGroupNotificationType type, bool isFiltered, GroupNotificationOperate operate, string message = "") =>
context.EventContext.GetLogic<OperationLogic>().SetGroupNotification(groupUin, sequence, type, isFiltered, operate, message);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Diagnostics.CodeAnalysis;
using Lagrange.Core.Common.Entity;

namespace Lagrange.Core.Internal.Events.System;

internal class FetchFilteredGroupNotificationsEventReq(ulong count, ulong start = 0) : ProtocolEvent
{
public ulong Count { get; } = count;

public ulong Start { get; } = start;
}

internal class FetchFilteredGroupNotificationsEventResp(List<BotGroupNotificationBase> groupNotifications) : ProtocolEvent
{
public List<BotGroupNotificationBase> GroupNotifications { get; } = groupNotifications;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

namespace Lagrange.Core.Internal.Events.System;

internal class FetchGroupNotificationsEventReq(ulong count) : ProtocolEvent
internal class FetchGroupNotificationsEventReq(ulong count, ulong start = 0) : ProtocolEvent
{
public ulong Count { get; } = count;

public ulong Start { get; } = start;
}

internal class FetchGroupNotificationsEventResp(List<BotGroupNotificationBase> groupNotifications) : ProtocolEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Lagrange.Core.Common.Entity;

namespace Lagrange.Core.Internal.Events.System;

internal class SetFilteredGroupNotificationEventReq(long groupUin, ulong sequence, BotGroupNotificationType type, GroupNotificationOperate operate, string message) : ProtocolEvent
{
public long GroupUin { get; } = groupUin;

public ulong Sequence { get; } = sequence;

public BotGroupNotificationType Type { get; } = type;

public GroupNotificationOperate Operate { get; } = operate;

public string Message { get; } = message;
}

internal class SetFilteredGroupNotificationEventResp : ProtocolEvent
{
public static readonly SetFilteredGroupNotificationEventResp Default = new();
}
44 changes: 34 additions & 10 deletions Lagrange.Core/Internal/Logic/OperationLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,28 +226,52 @@ public async Task<string> SendGroupFile(long groupUin, Stream fileStream, string
return uploadResp.FileId;
}

public async Task<List<BotGroupNotificationBase>> FetchGroupNotifications(ulong count)
public async Task<List<BotGroupNotificationBase>> FetchGroupNotifications(ulong count, ulong start)
{
var req = new FetchGroupNotificationsEventReq(count);
var req = new FetchGroupNotificationsEventReq(count, start);
var resp = await context.EventContext.SendEvent<FetchGroupNotificationsEventResp>(req);
return resp.GroupNotifications;
}

public async Task<List<BotGroupNotificationBase>> FetchFilteredGroupNotifications(ulong count, ulong start)
{
var req = new FetchFilteredGroupNotificationsEventReq(count, start);
var resp = await context.EventContext.SendEvent<FetchFilteredGroupNotificationsEventResp>(req);
return resp.GroupNotifications;
}

public async Task<BotStranger> FetchStranger(long uid)
{
var req = new FetchStrangerByUinEventReq(uid);
var resp = await context.EventContext.SendEvent<FetchStrangerEventResp>(req);
return resp.Stranger;
}

public async Task SetGroupNotification(long groupUin, ulong sequence, BotGroupNotificationType type, GroupNotificationOperate operate, string message)
public async Task SetGroupNotification(long groupUin, ulong sequence, BotGroupNotificationType type, bool isFiltered, GroupNotificationOperate operate, string message)
{
await context.EventContext.SendEvent<SetGroupNotificationEventResp>(new SetGroupNotificationEventReq(
groupUin,
sequence,
type,
operate,
message
));
if (isFiltered)
{
await context.EventContext.SendEvent<SetFilteredGroupNotificationEventResp>(
new SetFilteredGroupNotificationEventReq(
groupUin,
sequence,
type,
operate,
message
)
);
}
else
{
await context.EventContext.SendEvent<SetGroupNotificationEventResp>(
new SetGroupNotificationEventReq(
groupUin,
sequence,
type,
operate,
message
)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ namespace Lagrange.Core.Internal.Packets.Service;
internal partial class FetchGroupNotificationsRequest
{
[ProtoMember(1)] public ulong Count { get; set; }

[ProtoMember(2)] public ulong StartSequence { get; set; }
}


[ProtoPackable]
internal partial class FetchGroupNotificationsResponse
{
[ProtoMember(1)] public List<FetchGroupNotificationsResponseNotification> GroupNotifications { get; set; }
// If empty, it is null
[ProtoMember(1)] public List<FetchGroupNotificationsResponseNotification>? GroupNotifications { get; set; }
}

[ProtoPackable]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using Lagrange.Core.Common;
using Lagrange.Core.Common.Entity;
using Lagrange.Core.Internal.Events;
using Lagrange.Core.Internal.Events.System;
using Lagrange.Core.Internal.Packets.Service;

namespace Lagrange.Core.Internal.Services.System;

[EventSubscribe<FetchFilteredGroupNotificationsEventReq>(Protocols.All)]
[Service("OidbSvcTrpcTcp.0x10c0_2")]
internal class FetchFilteredGroupNotificationsService : OidbService<FetchFilteredGroupNotificationsEventReq, FetchFilteredGroupNotificationsEventResp, FetchGroupNotificationsRequest, FetchGroupNotificationsResponse>
{
private protected override uint Command => 0x10c0;

private protected override uint Service => 2;

private protected override Task<FetchGroupNotificationsRequest> ProcessRequest(FetchFilteredGroupNotificationsEventReq request, BotContext context)
{
return Task.FromResult(new FetchGroupNotificationsRequest
{
Count = request.Count,
StartSequence = request.Start
});
}

private protected override Task<FetchFilteredGroupNotificationsEventResp> ProcessResponse(FetchGroupNotificationsResponse response, BotContext context)
{
if (response.GroupNotifications == null)
{
return Task.FromResult(new FetchFilteredGroupNotificationsEventResp([]));
}

List<BotGroupNotificationBase> notifications = [];
foreach (var request in response.GroupNotifications)
{
var targetUin = context.CacheContext.ResolveUin(request.Target.Uid);
long? operatorUin = request.Operator != null
? context.CacheContext.ResolveUin(request.Operator.Uid)
: null;
long? inviterUin = request.Inviter != null
? context.CacheContext.ResolveUin(request.Inviter.Uid)
: null;

var notification = request.Type switch
{
1 => new BotGroupJoinNotification(
request.Group.GroupUin,
request.Sequence,
targetUin,
request.Target.Uid,
(BotGroupNotificationState)request.State,
operatorUin,
request.Operator?.Uid,
request.Comment,
true
),
22 => new BotGroupInviteNotification(
request.Group.GroupUin,
request.Sequence,
targetUin,
request.Target.Uid,
(BotGroupNotificationState)request.State,
operatorUin,
request.Operator?.Uid,
inviterUin ?? 0,
request.Inviter?.Uid ?? string.Empty,
true
),
_ => LogUnknownNotificationType(context, request.Type),
};
if (notification != null) notifications.Add(notification);
}
return Task.FromResult(new FetchFilteredGroupNotificationsEventResp(notifications));
}

private BotGroupNotificationBase? LogUnknownNotificationType(BotContext context, ulong type)
{
context.LogWarning(nameof(FetchFilteredGroupNotificationsService), "Unknown filtered notification type: {0}", null, type);
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ private protected override Task<FetchGroupNotificationsRequest> ProcessRequest(F
{
return Task.FromResult(new FetchGroupNotificationsRequest
{
Count = request.Count
Count = request.Count,
StartSequence = request.Start
});
}

private protected override Task<FetchGroupNotificationsEventResp> ProcessResponse(FetchGroupNotificationsResponse response, BotContext context)
{
if (response.GroupNotifications == null)
{
return Task.FromResult(new FetchGroupNotificationsEventResp([]));
}

List<BotGroupNotificationBase> notifications = [];
foreach (var request in response.GroupNotifications)
{
Expand All @@ -45,7 +51,8 @@ private protected override Task<FetchGroupNotificationsEventResp> ProcessRespons
(BotGroupNotificationState)request.State,
operatorUin,
request.Operator?.Uid,
request.Comment
request.Comment,
false
),
3 => new BotGroupSetAdminNotification(
request.Group.GroupUin,
Expand Down Expand Up @@ -86,7 +93,8 @@ private protected override Task<FetchGroupNotificationsEventResp> ProcessRespons
operatorUin,
request.Operator?.Uid,
inviterUin ?? 0,
request.Inviter?.Uid ?? string.Empty
request.Inviter?.Uid ?? string.Empty,
false
),
_ => LogUnknownNotificationType(context, request.Type),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Events;
using Lagrange.Core.Internal.Events.System;
using Lagrange.Core.Internal.Packets.Service;

namespace Lagrange.Core.Internal.Services.System;

[EventSubscribe<SetFilteredGroupNotificationEventReq>(Protocols.All)]
[Service("OidbSvcTrpcTcp.0x10c8_2")]
internal class SetFilteredGroupNotificationService : OidbService<SetFilteredGroupNotificationEventReq, SetFilteredGroupNotificationEventResp, SetGroupNotificationRequest, SetGroupNotificationResponse>
{
private protected override uint Command => 0x10c8;

private protected override uint Service => 2;

private protected override Task<SetGroupNotificationRequest> ProcessRequest(SetFilteredGroupNotificationEventReq request, BotContext context)
{
return Task.FromResult(new SetGroupNotificationRequest
{
Operate = (ulong)request.Operate,
Body = new SetGroupNotificationRequestBody
{
Sequence = request.Sequence,
Type = (ulong)request.Type,
GroupUin = request.GroupUin,
Message = request.Message,
}
});
}

private protected override Task<SetFilteredGroupNotificationEventResp> ProcessResponse(SetGroupNotificationResponse response, BotContext context)
{
return Task.FromResult(SetFilteredGroupNotificationEventResp.Default);
}
}
Loading