Skip to content

Commit

Permalink
Merge branch 'LagrangeDev:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
sisi0318 authored Aug 20, 2024
2 parents 41d8c55 + 8b56d09 commit f03cae1
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 51 deletions.
9 changes: 6 additions & 3 deletions Lagrange.Core/Event/EventArg/FriendPokeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ public class FriendPokeEvent : EventBase
public string Action { get; }

public string Suffix { get; }

public string ActionImgUrl { get; }

public FriendPokeEvent(uint operatorUin, uint targetUin, string action, string suffix)
public FriendPokeEvent(uint operatorUin, uint targetUin, string action, string suffix, string actionImgUrl)
{
OperatorUin = operatorUin;
TargetUin = targetUin;
Action = action;
Suffix = suffix;
ActionImgUrl = actionImgUrl;

EventMessage = $"{nameof(FriendPokeEvent)}: OperatorUin: {OperatorUin} | TargetUin: {TargetUin} | Action: {Action} | Suffix: {Suffix}";
EventMessage = $"{nameof(FriendPokeEvent)}: OperatorUin: {OperatorUin} | TargetUin: {TargetUin} | Action: {Action} | Suffix: {Suffix} | ActionImgUrl: {ActionImgUrl}";
}
}
}
11 changes: 7 additions & 4 deletions Lagrange.Core/Event/EventArg/GroupPokeEvent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Lagrange.Core.Event.EventArg;
namespace Lagrange.Core.Event.EventArg;

public class GroupPokeEvent : EventBase
{
Expand All @@ -12,14 +12,17 @@ public class GroupPokeEvent : EventBase

public string Suffix { get; }

public GroupPokeEvent(uint groupUin, uint operatorUin, uint targetUin, string action, string suffix)
public string ActionImgUrl { get; }

public GroupPokeEvent(uint groupUin, uint operatorUin, uint targetUin, string action, string suffix, string actionImgUrl)
{
GroupUin = groupUin;
OperatorUin = operatorUin;
TargetUin = targetUin;
Action = action;
Suffix = suffix;
ActionImgUrl = actionImgUrl;

EventMessage = $"{nameof(GroupPokeEvent)}: GroupUin: {GroupUin} | OperatorUin: {OperatorUin} | TargetUin: {TargetUin} | Action: {Action} | Suffix: {Suffix}";
EventMessage = $"{nameof(GroupPokeEvent)}: GroupUin: {GroupUin} | OperatorUin: {OperatorUin} | TargetUin: {TargetUin} | Action: {Action} | Suffix: {Suffix} | ActionImgUrl: {ActionImgUrl}";
}
}
}
7 changes: 5 additions & 2 deletions Lagrange.Core/Event/EventArg/GroupReactionEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ public class GroupReactionEvent : EventBase

public string Code { get; }

public GroupReactionEvent(uint targetGroupUin, uint targetSequence, uint operatorUin, bool isAdd, string code)
public uint Count { get; }

public GroupReactionEvent(uint targetGroupUin, uint targetSequence, uint operatorUin, bool isAdd, string code, uint count)
{
TargetGroupUin = targetGroupUin;
TargetSequence = targetSequence;
OperatorUin = operatorUin;
IsAdd = isAdd;
Code = code;
Count = count;

EventMessage = $"{nameof(GroupReactionEvent)}: TargetGroupUin: {TargetGroupUin} | TargetSequence: {TargetSequence} | OperatorUin: {OperatorUin} | IsAdd: {IsAdd} | Code: {Code}";
EventMessage = $"{nameof(GroupReactionEvent)}: TargetGroupUin: {TargetGroupUin} | TargetSequence: {TargetSequence} | OperatorUin: {OperatorUin} | IsAdd: {IsAdd} | Code: {Code} | Count: {Count}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ public override async Task Incoming(ProtocolEvent e)
}
case GroupSysPokeEvent poke:
{
var pokeArgs = new GroupPokeEvent(poke.GroupUin, poke.OperatorUin, poke.TargetUin, poke.Action, poke.Suffix);
var pokeArgs = new GroupPokeEvent(poke.GroupUin, poke.OperatorUin, poke.TargetUin, poke.Action, poke.Suffix, poke.ActionImgUrl);
Collection.Invoker.PostEvent(pokeArgs);
break;
}
case GroupSysReactionEvent reaction:
{
uint operatorUin = await Collection.Business.CachingLogic.ResolveUin(reaction.TargetGroupUin, reaction.OperatorUid) ?? 0;
var pokeArgs = new GroupReactionEvent(reaction.TargetGroupUin, reaction.TargetSequence, operatorUin, reaction.IsAdd, reaction.Code);
var pokeArgs = new GroupReactionEvent(reaction.TargetGroupUin, reaction.TargetSequence, operatorUin, reaction.IsAdd, reaction.Code, reaction.Count);
Collection.Invoker.PostEvent(pokeArgs);
break;
}
Expand Down Expand Up @@ -200,7 +200,7 @@ public override async Task Incoming(ProtocolEvent e)
}
case FriendSysPokeEvent poke:
{
var pokeArgs = new FriendPokeEvent(poke.OperatorUin, poke.TargetUin, poke.Action, poke.Suffix);
var pokeArgs = new FriendPokeEvent(poke.OperatorUin, poke.TargetUin, poke.Action, poke.Suffix, poke.ActionImgUrl);
Collection.Invoker.PostEvent(pokeArgs);
break;
}
Expand Down Expand Up @@ -415,4 +415,4 @@ private async Task ResolveChainMetadata(MessageChain chain)
}
}
}
}
}
11 changes: 7 additions & 4 deletions Lagrange.Core/Internal/Event/Notify/FriendSysPokeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ internal class FriendSysPokeEvent : ProtocolEvent

public string Suffix { get; }

private FriendSysPokeEvent(uint operatorUin, uint targetUin, string action, string suffix) : base(0)
public string ActionImgUrl { get; }

private FriendSysPokeEvent(uint operatorUin, uint targetUin, string action, string suffix, string actionImgUrl) : base(0)
{
OperatorUin = operatorUin;
TargetUin = targetUin;
Action = action;
Suffix = suffix;
ActionImgUrl = actionImgUrl;
}

public static FriendSysPokeEvent Result(uint operatorUin, uint targetUin, string action, string suffix)
=> new(operatorUin, targetUin, action, suffix);
}
public static FriendSysPokeEvent Result(uint operatorUin, uint targetUin, string action, string suffix, string actionImgUrl)
=> new(operatorUin, targetUin, action, suffix, actionImgUrl);
}
11 changes: 7 additions & 4 deletions Lagrange.Core/Internal/Event/Notify/GroupSysPokeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ internal class GroupSysPokeEvent : ProtocolEvent

public string Suffix { get; }

private GroupSysPokeEvent(uint groupUin, uint operatorUin, uint targetUin, string action, string suffix) : base(0)
public string ActionImgUrl { get; }

private GroupSysPokeEvent(uint groupUin, uint operatorUin, uint targetUin, string action, string suffix, string actionImgUrl) : base(0)
{
GroupUin = groupUin;
OperatorUin = operatorUin;
TargetUin = targetUin;
Action = action;
Suffix = suffix;
ActionImgUrl = actionImgUrl;
}

public static GroupSysPokeEvent Result(uint groupUin, uint operatorUin, uint targetUin, string action, string suffix)
=> new(groupUin, operatorUin, targetUin, action, suffix);
}
public static GroupSysPokeEvent Result(uint groupUin, uint operatorUin, uint targetUin, string action, string suffix, string actionImgUrl)
=> new(groupUin, operatorUin, targetUin, action, suffix, actionImgUrl);
}
9 changes: 6 additions & 3 deletions Lagrange.Core/Internal/Event/Notify/GroupSysReaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ internal class GroupSysReactionEvent : ProtocolEvent

public string Code { get; }

private GroupSysReactionEvent(uint targetGroupUin, uint targetSequence, string operatorUid, bool isAdd, string code) : base(0)
public uint Count { get; }

private GroupSysReactionEvent(uint targetGroupUin, uint targetSequence, string operatorUid, bool isAdd, string code,uint count) : base(0)
{
TargetGroupUin = targetGroupUin;
TargetSequence = targetSequence;
OperatorUid = operatorUid;
IsAdd = isAdd;
Code = code;
Count = count;
}

public static GroupSysReactionEvent Result(uint groupUin, uint targetSequence, string operatorUid, bool isAdd, string code)
=> new(groupUin, targetSequence, operatorUid, isAdd, code);
public static GroupSysReactionEvent Result(uint groupUin, uint targetSequence, string operatorUid, bool isAdd, string code, uint count)
=> new(groupUin, targetSequence, operatorUid, isAdd, code, count);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ internal class GroupReactionData3
{
[ProtoMember(1)] public string Code { get; set; }

[ProtoMember(3)] public uint Count { get; set; }

[ProtoMember(4)] public string OperatorUid { get; set; }

[ProtoMember(5)] public uint Type { get; set; } // 1 Add 2 Remove
Expand Down
25 changes: 21 additions & 4 deletions Lagrange.Core/Internal/Service/Message/PushMessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ private static void ProcessEvent0x2DC(Span<byte> payload, PushMsg msg, List<Prot
var type = reaction.Data.Data.Data.Data.Type;
var sequence = reaction.Data.Data.Data.Target.Sequence;
var code = reaction.Data.Data.Data.Data.Code;
var count = reaction.Data.Data.Data.Data.Count;

var groupRecallEvent = GroupSysReactionEvent.Result(group, sequence, uid, type == 1, code);
var groupRecallEvent = GroupSysReactionEvent.Result(group, sequence, uid, type == 1, code, count);
extraEvents.Add(groupRecallEvent);

break;
Expand Down Expand Up @@ -196,9 +197,17 @@ private static void ProcessEvent0x2DC(Span<byte> payload, PushMsg msg, List<Prot

var templates = greyTip.GeneralGrayTip.MsgTemplParam.ToDictionary(x => x.Name, x => x.Value);

if (!templates.TryGetValue("action_str", out var actionStr) || actionStr == null)
{
if (!templates.TryGetValue("alt_str1", out actionStr) || actionStr == null)
{
actionStr = string.Empty;
}
}

if (greyTip.GeneralGrayTip.BusiType == 12) // poke
{
var groupPokeEvent = GroupSysPokeEvent.Result(groupUin, uint.Parse(templates["uin_str1"]), uint.Parse(templates["uin_str2"]), templates["action_str"], templates["suffix_str"]);
var groupPokeEvent = GroupSysPokeEvent.Result(groupUin, uint.Parse(templates["uin_str1"]), uint.Parse(templates["uin_str2"]), actionStr, templates["suffix_str"], templates["action_img_url"]);
extraEvents.Add(groupPokeEvent);
}
break;
Expand Down Expand Up @@ -247,10 +256,18 @@ private static void ProcessEvent0x210(Span<byte> payload, PushMsg msg, List<Prot
var greyTip = Serializer.Deserialize<GeneralGrayTipInfo>(content.AsSpan());
var templates = greyTip.MsgTemplParam.ToDictionary(x => x.Name, x => x.Value);

if (!templates.TryGetValue("action_str", out var actionStr) || actionStr == null)
{
if (!templates.TryGetValue("alt_str1", out actionStr) || actionStr == null)
{
actionStr = string.Empty;
}
}

if (greyTip.BusiType == 12) // poke
{
var groupPokeEvent = FriendSysPokeEvent.Result(uint.Parse(templates["uin_str1"]), uint.Parse(templates["uin_str2"]), templates["action_str"], templates["suffix_str"]);
extraEvents.Add(groupPokeEvent);
var friendPokeEvent = FriendSysPokeEvent.Result(uint.Parse(templates["uin_str1"]), uint.Parse(templates["uin_str2"]), actionStr, templates["suffix_str"], templates["action_img_url"]);
extraEvents.Add(friendPokeEvent);
}
break;
}
Expand Down
6 changes: 4 additions & 2 deletions Lagrange.OneBot/Core/Entity/Notify/OneBotFriendPoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ public class OneBotFriendPoke(uint selfId) : OneBotNotify(selfId, "notify")

[JsonPropertyName("user_id")] public uint UserId { get; set; }

[JsonPropertyName("target_id")] public uint TargetId { get; set; } // self
[JsonPropertyName("target_id")] public uint TargetId { get; set; }

[JsonPropertyName("action")] public string Action { get; set; } = string.Empty;

[JsonPropertyName("suffix")] public string Suffix { get; set; } = string.Empty;
}

[JsonPropertyName("action_img_url")] public string ActionImgUrl { get; set; } = string.Empty;
}
6 changes: 4 additions & 2 deletions Lagrange.OneBot/Core/Entity/Notify/OneBotGroupPoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ public class OneBotGroupPoke(uint selfId) : OneBotNotify(selfId, "notify")

[JsonPropertyName("user_id")] public uint UserId { get; set; }

[JsonPropertyName("target_id")] public uint TargetId { get; set; } // self
[JsonPropertyName("target_id")] public uint TargetId { get; set; }

[JsonPropertyName("action")] public string Action { get; set; } = string.Empty;

[JsonPropertyName("suffix")] public string Suffix { get; set; } = string.Empty;
}

[JsonPropertyName("action_img_url")] public string ActionImgUrl { get; set; } = string.Empty;
}
5 changes: 4 additions & 1 deletion Lagrange.OneBot/Core/Entity/Notify/OneBotGroupReaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Lagrange.OneBot.Core.Entity.Notify;

[Serializable]
public class OneBotGroupReaction(uint selfId, uint groupId, int messageId, uint operatorId, string subType, string code)
public class OneBotGroupReaction(uint selfId, uint groupId, int messageId, uint operatorId, string subType, string code, uint count)
: OneBotNotify(selfId, "reaction")
{
[JsonPropertyName("group_id")] public uint GroupId { get; } = groupId;
Expand All @@ -15,4 +15,7 @@ public class OneBotGroupReaction(uint selfId, uint groupId, int messageId, uint
[JsonPropertyName("sub_type")] public string SubType { get; } = subType;

[JsonPropertyName("code")] public string Code { get; } = code;


[JsonPropertyName("count")] public uint Count { get; } = count;
}
26 changes: 8 additions & 18 deletions Lagrange.OneBot/Core/Notify/NotifyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
using Lagrange.OneBot.Core.Entity.Notify;
using Lagrange.OneBot.Core.Network;
using Lagrange.OneBot.Database;
using LiteDB;
using Microsoft.Extensions.Logging;

namespace Lagrange.OneBot.Core.Notify;

public sealed class NotifyService(BotContext bot, ILogger<NotifyService> logger, LiteDatabase database, LagrangeWebSvcCollection service)
public sealed class NotifyService(BotContext bot, ILogger<NotifyService> logger, LagrangeWebSvcCollection service)
{
public void RegisterEvents()
{
Expand Down Expand Up @@ -160,7 +159,8 @@ await service.SendJsonAsync(new OneBotFriendPoke(bot.BotUin)
UserId = @event.OperatorUin,
TargetId = @event.TargetUin,
Action = @event.Action,
Suffix = @event.Suffix
Suffix = @event.Suffix,
ActionImgUrl = @event.ActionImgUrl
});
};

Expand All @@ -173,7 +173,8 @@ await service.SendJsonAsync(new OneBotGroupPoke(bot.BotUin)
UserId = @event.OperatorUin,
TargetId = @event.TargetUin,
Action = @event.Action,
Suffix = @event.Suffix
Suffix = @event.Suffix,
ActionImgUrl = @event.ActionImgUrl
});
};

Expand All @@ -194,25 +195,14 @@ await service.SendJsonAsync(new OneBotGroupEssence(bot.BotUin)
{
logger.LogInformation(@event.ToString());
var record = database
.GetCollection<MessageRecord>()
.FindOne(Query.And(
Query.EQ("GroupUin", new BsonValue(@event.TargetGroupUin)),
Query.EQ("Sequence", new BsonValue(@event.TargetSequence))
));
if (record == null)
{
logger.LogWarning("No message record found for GroupUin: {GroupUin}, Sequence: {Sequence}", @event.TargetGroupUin, @event.TargetSequence);
}
await service.SendJsonAsync(new OneBotGroupReaction(
bot.BotUin,
@event.TargetGroupUin,
record?.MessageHash ?? 0,
0,
@event.OperatorUin,
@event.IsAdd ? "add" : "remove",
@event.Code
@event.Code,
@event.Count
));
};
}
Expand Down

0 comments on commit f03cae1

Please sign in to comment.