diff --git a/src/ZeroBot.Abstraction/Bot/IBotContext.cs b/src/ZeroBot.Abstraction/Bot/IBotContext.cs index 31ac989..ee2cedd 100644 --- a/src/ZeroBot.Abstraction/Bot/IBotContext.cs +++ b/src/ZeroBot.Abstraction/Bot/IBotContext.cs @@ -38,4 +38,7 @@ ValueTask UpdateGroupReactionAsync(long accountId, long groupId, long messageId, void SetEventRepository(IBotEventRepository repository); ValueTask GetTempResourceUrlAsync(long accountId, string id, CancellationToken cancellationToken = default); + + ValueTask UploadFileToGroupAsync(long accountId, long groupId, string fileName, MilkyUri fileUri, + CancellationToken cancellationToken = default); } diff --git a/src/ZeroBot.Abstraction/Bot/IBotService.cs b/src/ZeroBot.Abstraction/Bot/IBotService.cs index 045d059..e0bc241 100644 --- a/src/ZeroBot.Abstraction/Bot/IBotService.cs +++ b/src/ZeroBot.Abstraction/Bot/IBotService.cs @@ -31,4 +31,7 @@ ValueTask GetGroupInformationAsync(long groupId, ValueTask GetTempResourceUrlAsync(string id, CancellationToken cancellationToken = default); ValueTask AcceptFriendRequestAsync(string uid, CancellationToken cancellationToken = default); + + ValueTask UploadFileToGroupAsync(long accountId, long groupId, string fileName, MilkyUri fileUri, + CancellationToken cancellationToken = default); } diff --git a/src/ZeroBot.Core/Services/BotContext.cs b/src/ZeroBot.Core/Services/BotContext.cs index 1cdd7b6..fb29da2 100644 --- a/src/ZeroBot.Core/Services/BotContext.cs +++ b/src/ZeroBot.Core/Services/BotContext.cs @@ -153,6 +153,14 @@ public ValueTask GetTempResourceUrlAsync(long accountId, string id, : botService.GetTempResourceUrlAsync(id, cancellationToken); } + public ValueTask UploadFileToGroupAsync(long accountId, long groupId, string fileName, MilkyUri fileUri, + CancellationToken cancellationToken = default) + { + return !_services.TryGetValue(accountId, out var botService) + ? default + : botService.UploadFileToGroupAsync(accountId, groupId, fileName, fileUri, cancellationToken); + } + public async ValueTask UpdateGroupReactionAsync(long accountId, long groupId, long messageId, string reactionId, bool add, CancellationToken cancellationToken = default) { diff --git a/src/plugins/ZeroBot.Milky/Bot/MilkyBot.cs b/src/plugins/ZeroBot.Milky/Bot/MilkyBot.cs index 832df43..284fb2e 100644 --- a/src/plugins/ZeroBot.Milky/Bot/MilkyBot.cs +++ b/src/plugins/ZeroBot.Milky/Bot/MilkyBot.cs @@ -49,6 +49,12 @@ public async ValueTask AcceptFriendRequestAsync(string uid, CancellationToken ca await milky.Friend.AcceptFriendRequestAsync(param, cancellationToken); } + public async ValueTask UploadFileToGroupAsync(long accountId, long groupId, string fileName, MilkyUri fileUri, + CancellationToken cancellationToken = default) + { + await milky.File.UploadGroupFileAsync(new UploadGroupFileInput(groupId, "/", fileUri, fileName), cancellationToken); + } + public async ValueTask GetCurrentAccountAsync(CancellationToken cancellationToken = default) { return await botInfos.GetAccountInfoAsync(cancellationToken); diff --git a/src/plugins/ZeroBot.Painter/PaintCommandHandler.cs b/src/plugins/ZeroBot.Painter/PaintCommandHandler.cs index 812229a..e0ad5c4 100644 --- a/src/plugins/ZeroBot.Painter/PaintCommandHandler.cs +++ b/src/plugins/ZeroBot.Painter/PaintCommandHandler.cs @@ -212,7 +212,7 @@ private async ValueTask TryConsumeQuotaAsync(long peerId, long senderId, i value.DailyQuotas[key] = quota = new DailyQuota(today, 0); } - if (quota.Count >= limit) return false; + if (limit > -1 && quota.Count >= limit) return false; value.DailyQuotas[key] = quota with { Count = quota.Count + 1 }; await config.SaveAsync(value, token); diff --git a/src/plugins/ZeroBot.Painter/PainterManageCommandHandler.cs b/src/plugins/ZeroBot.Painter/PainterManageCommandHandler.cs index 235db44..aeb81c7 100644 --- a/src/plugins/ZeroBot.Painter/PainterManageCommandHandler.cs +++ b/src/plugins/ZeroBot.Painter/PainterManageCommandHandler.cs @@ -40,7 +40,7 @@ protected override async ValueTask PredicateAsync(Event m protected override async ValueTask HandleAsync(Event message, CancellationToken cancellationToken = default) { - var command = message.ToTextCommands().FirstOrDefault(); + var command = message.ToTextCommands(argumentSplitters: "::").FirstOrDefault(); var arguments = command?.Arguments ?? []; var peerId = message.Data.PeerId; diff --git a/src/plugins/ZeroBot.Painter/PainterQuota.cs b/src/plugins/ZeroBot.Painter/PainterQuota.cs index 74c75c2..3bae91b 100644 --- a/src/plugins/ZeroBot.Painter/PainterQuota.cs +++ b/src/plugins/ZeroBot.Painter/PainterQuota.cs @@ -24,5 +24,5 @@ public static DateOnly Today(DateTimeOffset now) => /// /// 启用指令 number 合法性:1 <= number <= max。 /// - public static bool IsValidDailyLimit(int number, int max) => number >= 1 && number <= max; + public static bool IsValidDailyLimit(int number, int max) => number == -1 || (number >= 1 && number <= max); } diff --git a/src/plugins/ZeroBot.Workflow/WorkflowCommandHandler.cs b/src/plugins/ZeroBot.Workflow/WorkflowCommandHandler.cs index 1139a8f..4841c97 100644 --- a/src/plugins/ZeroBot.Workflow/WorkflowCommandHandler.cs +++ b/src/plugins/ZeroBot.Workflow/WorkflowCommandHandler.cs @@ -1,6 +1,5 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Milky.Net.Client; using Milky.Net.Model; using ZeroBot.Abstraction.Bot; using ZeroBot.Abstraction.Service; @@ -20,7 +19,6 @@ public class WorkflowCommandHandler( IPermission permission, IOptions options, WorkflowApi api, - MilkyClient milky, ILogger logger) : CommandQueuedHandler(dispatcher) { private const string CommandPrefix = "/workflow"; @@ -146,8 +144,11 @@ private async ValueTask SendResultAsync(Event @event, string si } var fileName = GuessFileName(data); - await milky.File.UploadGroupFileAsync( - new UploadGroupFileInput(@event.Data.PeerId, "/", new MilkyUri($"base64://{base64}"), fileName), + await bot.UploadFileToGroupAsync( + @event.SelfId, + @event.Data.PeerId, + fileName, + new MilkyUri($"base64://{base64}"), cancellationToken); } diff --git a/src/plugins/ZeroBot.Workflow/ZeroBot.Workflow.csproj b/src/plugins/ZeroBot.Workflow/ZeroBot.Workflow.csproj index f513da8..12b1a57 100644 --- a/src/plugins/ZeroBot.Workflow/ZeroBot.Workflow.csproj +++ b/src/plugins/ZeroBot.Workflow/ZeroBot.Workflow.csproj @@ -10,7 +10,6 @@ - diff --git a/test/ZeroBot.Core.Test/PainterQuotaTest.cs b/test/ZeroBot.Core.Test/PainterQuotaTest.cs index 1d4c3d2..d3f1ffc 100644 --- a/test/ZeroBot.Core.Test/PainterQuotaTest.cs +++ b/test/ZeroBot.Core.Test/PainterQuotaTest.cs @@ -29,7 +29,7 @@ public void Key_ShouldCombinePeerAndSender() [InlineData(1, true)] [InlineData(5, true)] [InlineData(6, false)] - [InlineData(-1, false)] + [InlineData(-1, true)] public void IsValidDailyLimit_ShouldRespectBoundaries(int number, bool expected) { Assert.Equal(expected, PainterQuota.IsValidDailyLimit(number, 5)); diff --git a/test/ZeroBot.Core.Test/TestBotService.cs b/test/ZeroBot.Core.Test/TestBotService.cs index 5782d94..10b14cd 100644 --- a/test/ZeroBot.Core.Test/TestBotService.cs +++ b/test/ZeroBot.Core.Test/TestBotService.cs @@ -70,4 +70,10 @@ public ValueTask AcceptFriendRequestAsync(string uid, CancellationToken cancella { throw new NotImplementedException(); } + + public ValueTask UploadFileToGroupAsync(long accountId, long groupId, string fileName, MilkyUri fileUri, + CancellationToken cancellationToken = default) + { + throw new NotImplementedException(); + } } \ No newline at end of file