-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OneBot] Implemented set_qq_avatar and set_group_portrait
- Loading branch information
1 parent
64796b5
commit 8c160e6
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
Lagrange.OneBot/Core/Entity/Action/OneBotSetGroupPortrait.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,11 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Lagrange.OneBot.Core.Entity.Action; | ||
|
||
[Serializable] | ||
public class OneBotSetGroupPortrait | ||
{ | ||
[JsonPropertyName("group_id")] public uint GroupId { get; set; } | ||
|
||
[JsonPropertyName("file")] public string File { get; set; } = string.Empty; | ||
} |
27 changes: 27 additions & 0 deletions
27
Lagrange.OneBot/Core/Operation/Generic/SetGroupPortraitOperation.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,27 @@ | ||
using System.Text.Json.Nodes; | ||
using Lagrange.Core; | ||
using Lagrange.Core.Common.Interface.Api; | ||
using Lagrange.Core.Message.Entity; | ||
using Lagrange.OneBot.Core.Entity.Action; | ||
using Lagrange.OneBot.Message.Entity; | ||
|
||
namespace Lagrange.OneBot.Core.Operation.Generic; | ||
|
||
[Operation("set_qq_avatar")] | ||
public class SetQQAvatar : IOperation | ||
{ | ||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload) | ||
{ | ||
if (payload?["file"]?.ToString() is { } portrait) | ||
{ | ||
var image = CommonResolver.ResolveStream(portrait); | ||
if (image == null) throw new Exception(); | ||
|
||
var imageEntity = new ImageEntity(image); | ||
bool result = await context.SetAvatar(imageEntity); | ||
return new OneBotResult(null, result ? 0 : 1, ""); | ||
} | ||
|
||
throw new Exception(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Lagrange.OneBot/Core/Operation/Group/SetGroupPortraitOperation.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,28 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using Lagrange.Core; | ||
using Lagrange.Core.Common.Interface.Api; | ||
using Lagrange.Core.Message.Entity; | ||
using Lagrange.OneBot.Core.Entity.Action; | ||
using Lagrange.OneBot.Message.Entity; | ||
|
||
namespace Lagrange.OneBot.Core.Operation.Group; | ||
|
||
[Operation("set_group_portrait")] | ||
public class SetGroupPortraitOperation : IOperation | ||
{ | ||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload) | ||
{ | ||
if (payload.Deserialize<OneBotSetGroupPortrait>() is { } portrait) | ||
{ | ||
var image = CommonResolver.ResolveStream(portrait.File); | ||
if (image == null) throw new Exception(); | ||
|
||
var imageEntity = new ImageEntity(image); | ||
bool result = await context.GroupSetAvatar(portrait.GroupId, imageEntity); | ||
return new OneBotResult(null, result ? 0 : 1, ""); | ||
} | ||
|
||
throw new Exception(); | ||
} | ||
} |