88using System . Threading . Tasks ;
99using Lagrange . Core ;
1010using Lagrange . Core . Events ;
11+ using Lagrange . Core . Events . EventArgs ;
1112using Lagrange . Milky . Configurations ;
1213using Lagrange . Milky . Events . Converters ;
1314using Lagrange . Milky . Events . Extensions ;
1415using Lagrange . Milky . Http ;
1516using Lagrange . Milky . Serialization ;
1617using Microsoft . Extensions . DependencyInjection ;
1718using Microsoft . Extensions . Logging ;
19+ using LogLevel = Microsoft . Extensions . Logging . LogLevel ;
1820
1921namespace Lagrange . Milky . Events ;
2022
@@ -33,6 +35,7 @@ public sealed class SSEEventHandler : IHttpHandler, IGenericEventHandler, IDispo
3335 private readonly string ? _token ;
3436 private readonly string ? _allowCorsOrigins ;
3537 private readonly ulong _heartbeatIntervalSeconds ;
38+ private readonly bool _suppressSelfMessageEvents ;
3639
3740 private readonly ConcurrentDictionary < Guid , ( HttpListenerResponse Response , SemaphoreSlim SendLock ) > _connections = new ( ) ;
3841 private readonly CancellationTokenSource _cts = new ( ) ;
@@ -49,6 +52,7 @@ public SSEEventHandler(IServiceScopeFactory scopeFactory, ILogger<SSEEventHandle
4952 _token = configuration . AccessToken ;
5053 _allowCorsOrigins = sseConfiguration . AllowCorsOrigins ;
5154 _heartbeatIntervalSeconds = sseConfiguration . HeartbeatIntervalSeconds ;
55+ _suppressSelfMessageEvents = configuration . Event . SuppressSelfMessageEvents ;
5256
5357 _lagrange . RegisterConvertibleEvents ( this ) ;
5458 }
@@ -179,6 +183,8 @@ private async Task SendAllAsync(byte[] payload, CancellationToken ct = default)
179183
180184 public async Task OnEvent < TEvent > ( BotContext lagrange , TEvent @event ) where TEvent : EventBase
181185 {
186+ if ( _suppressSelfMessageEvents && @event is BotMessageEvent message && message . Message . Contact . Uin == _lagrange . BotUin ) return ;
187+
182188 await using var scope = _scopeFactory . CreateAsyncScope ( ) ;
183189 var converter = scope . ServiceProvider . GetRequiredService < IEventConverter < TEvent > > ( ) ;
184190 byte [ ] bytes = Serializer . JsonSerializeToUtf8Bytes ( new MilkyEvent
0 commit comments