File tree Expand file tree Collapse file tree 4 files changed +42
-5
lines changed Expand file tree Collapse file tree 4 files changed +42
-5
lines changed Original file line number Diff line number Diff line change 5
5
using Lagrange . Core . Message ;
6
6
using Lagrange . Core . Utility . Extension ;
7
7
using Lagrange . OneBot . Core . Entity . Message ;
8
- using Lagrange . OneBot . Core . Network . Service ;
8
+ using Lagrange . OneBot . Core . Network ;
9
9
using Lagrange . OneBot . Database ;
10
10
11
11
namespace Lagrange . OneBot . Core . Message ;
@@ -15,11 +15,11 @@ namespace Lagrange.OneBot.Core.Message;
15
15
/// </summary>
16
16
public sealed class MessageService
17
17
{
18
- private readonly ILagrangeWebService _service ;
18
+ private readonly LagrangeWebSvcCollection _service ;
19
19
private readonly ContextBase _context ;
20
20
private readonly Dictionary < Type , ( string , ISegment ) > _entityToSegment ;
21
21
22
- public MessageService ( BotContext bot , ILagrangeWebService service , ContextBase context )
22
+ public MessageService ( BotContext bot , LagrangeWebSvcCollection service , ContextBase context )
23
23
{
24
24
_service = service ;
25
25
_context = context ;
Original file line number Diff line number Diff line change
1
+ using Lagrange . OneBot . Core . Network . Service ;
2
+ using Microsoft . Extensions . Hosting ;
3
+
4
+ namespace Lagrange . OneBot . Core . Network ;
5
+
6
+ public class LagrangeWebSvcCollection : List < ILagrangeWebService > , IHostedService
7
+ {
8
+ public event EventHandler < MsgRecvEventArgs > OnMessageReceived = delegate { } ;
9
+
10
+ public LagrangeWebSvcCollection ( IEnumerable < ILagrangeWebService > services ) : base ( services )
11
+ {
12
+ foreach ( var service in this ) service . OnMessageReceived += OnMessageReceived . Invoke ;
13
+ }
14
+
15
+ public async Task StartAsync ( CancellationToken cancellationToken )
16
+ {
17
+ foreach ( var service in this ) await service . StartAsync ( cancellationToken ) ;
18
+ }
19
+
20
+ public async Task StopAsync ( CancellationToken cancellationToken )
21
+ {
22
+ foreach ( var service in this ) await service . StopAsync ( cancellationToken ) ;
23
+ }
24
+
25
+ public async Task SendJsonAsync < T > ( T json , CancellationToken cancellationToken = default )
26
+ {
27
+ foreach ( var service in this ) await service . SendJsonAsync ( json , cancellationToken ) ;
28
+ }
29
+ }
Original file line number Diff line number Diff line change 3
3
using Lagrange . Core ;
4
4
using Lagrange . Core . Utility . Extension ;
5
5
using Lagrange . OneBot . Core . Entity . Action ;
6
+ using Lagrange . OneBot . Core . Network ;
6
7
using Lagrange . OneBot . Core . Network . Service ;
7
8
8
9
namespace Lagrange . OneBot . Core . Operation ;
9
10
10
11
public sealed class OperationService
11
12
{
12
13
private readonly BotContext _bot ;
13
- private readonly ILagrangeWebService _service ;
14
+ private readonly LagrangeWebSvcCollection _service ;
14
15
private readonly Dictionary < string , IOperation > _operations ;
15
16
16
- public OperationService ( BotContext bot , ILagrangeWebService service )
17
+ public OperationService ( BotContext bot , LagrangeWebSvcCollection service )
17
18
{
18
19
_bot = bot ;
19
20
_service = service ;
@@ -55,5 +56,9 @@ private async Task HandleOperation(string data)
55
56
throw new Exception ( "action deserialized failed" ) ;
56
57
}
57
58
}
59
+ catch
60
+ {
61
+ await _service . SendJsonAsync ( new OneBotResult ( null , 200 , "failed" ) ) ;
62
+ }
58
63
}
59
64
}
Original file line number Diff line number Diff line change 3
3
using Lagrange . Core . Common . Interface ;
4
4
using Lagrange . Core . Utility . Sign ;
5
5
using Lagrange . OneBot . Core . Message ;
6
+ using Lagrange . OneBot . Core . Network ;
6
7
using Lagrange . OneBot . Core . Network . Service ;
7
8
using Lagrange . OneBot . Core . Operation ;
8
9
using Lagrange . OneBot . Database ;
@@ -85,6 +86,8 @@ public LagrangeAppBuilder ConfigureOneBot()
85
86
{
86
87
Services . AddSingleton < ILagrangeWebService , ForwardWSService > ( ) ;
87
88
}
89
+
90
+ Services . AddSingleton < LagrangeWebSvcCollection > ( ) ;
88
91
89
92
Services . AddSingleton < ContextBase , LiteDbContext > ( ) ;
90
93
Services . AddSingleton < SignProvider , OneBotSigner > ( ) ;
You can’t perform that action at this time.
0 commit comments