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);