From 225a64f9e0c40d3fe3ef1793396a847314030acd Mon Sep 17 00:00:00 2001 From: NostalgiaCyan Date: Thu, 30 Jun 2022 02:24:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=99onebot=E6=B2=A1=E5=86=99=E5=AF=B9?= =?UTF-8?q?=E5=90=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrichaltConnectors/OneBotConnector.cs | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/WFBot/Orichalt/OrichaltConnectors/OneBotConnector.cs b/WFBot/Orichalt/OrichaltConnectors/OneBotConnector.cs index afa38bc..21cd4fd 100644 --- a/WFBot/Orichalt/OrichaltConnectors/OneBotConnector.cs +++ b/WFBot/Orichalt/OrichaltConnectors/OneBotConnector.cs @@ -101,10 +101,18 @@ public async Task Init() await Task.Delay(1000); if (!wsevent.IsAvailable) { - Console.WriteLine("OneBot连接失败, 将在5秒后重试···"); - InitializationTimer = new Timer(TimeSpan.FromSeconds(5).TotalMilliseconds); - InitializationTimer.Elapsed += TryInitOneBot; - InitializationTimer.Start(); + while (true) + { + Console.WriteLine("OneBot连接失败, 将在5秒后重试···"); + await Task.Delay(5000); + wsevent.StartListen(); + if (!wsevent.IsAvailable) + { + continue; + } + Console.WriteLine("OneBot已连接."); + break; + } } else { @@ -126,19 +134,7 @@ public async Task Init() } Console.WriteLine("OneBot已连接.");*/ } - - private void TryInitOneBot(object sender, ElapsedEventArgs e) - { - wsevent.StartListen(); - if (!wsevent.IsAvailable) - { - Console.WriteLine("OneBot连接失败, 将在5秒后重试···"); - return; - } - Console.WriteLine("OneBot已连接."); - InitializationTimer.Stop(); - } - + protected virtual void OnOneBotMessage(OneBotContext e) { OneBotMessageReceived?.Invoke(this, e);