Skip to content

Commit

Permalink
[All] Fix poke may not have action_str (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishkong authored Aug 20, 2024
1 parent 7c19535 commit 8f4c6e2
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 27 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}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ 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;
}
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);
}
22 changes: 19 additions & 3 deletions Lagrange.Core/Internal/Service/Message/PushMessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,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 @@ -248,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;
}
6 changes: 4 additions & 2 deletions Lagrange.OneBot/Core/Notify/NotifyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,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 +174,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 Down

0 comments on commit 8f4c6e2

Please sign in to comment.