From b61530098589c6e89f1d3d3bc20c1b0924beefa5 Mon Sep 17 00:00:00 2001 From: Madpeter <57852827+Madpeterz@users.noreply.github.com> Date: Thu, 6 Feb 2025 21:20:38 +0000 Subject: [PATCH] adds support for WaitSecsToStart for on events --- Dockerfile | 1 + SecondBotEvents/Config/OnEventConfig.cs | 6 +++++ .../Services/TriggerOnEventService.cs | 27 ++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 17250f0..113d92d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -135,6 +135,7 @@ ENV basic_Username='' \ chatgpt_RedisCountIm='60' \ onevent_Enabled='false' \ onevent_Count=0 \ + onevent_WaitSecsToStart=10 \ onevent_HideStatusOutput='false' \ smtp_Enabled='false' \ smtp_AllowEmailAsReplyTarget='false' \ diff --git a/SecondBotEvents/Config/OnEventConfig.cs b/SecondBotEvents/Config/OnEventConfig.cs index 5102b2d..eab78a8 100644 --- a/SecondBotEvents/Config/OnEventConfig.cs +++ b/SecondBotEvents/Config/OnEventConfig.cs @@ -14,10 +14,16 @@ namespace SecondBotEvents.Config filename = "onevent"; settings.Add("Enabled"); settings.Add("Count"); + settings.Add("WaitSecsToStart"); settings.Add("HideStatusOutput"); settings.Add("DebugMe"); } + public int GetWaitSecsToStart() + { + return ReadSettingAsInt("WaitSecsToStart", 10); + } + public void unloadEvents() { int loop = 1; diff --git a/SecondBotEvents/Services/TriggerOnEventService.cs b/SecondBotEvents/Services/TriggerOnEventService.cs index 408eb27..f259f02 100644 --- a/SecondBotEvents/Services/TriggerOnEventService.cs +++ b/SecondBotEvents/Services/TriggerOnEventService.cs @@ -14,7 +14,7 @@ namespace SecondBotEvents.Services { public class TriggerOnEventService : BotServices { - protected OnEventConfig myConfig; + protected new OnEventConfig myConfig; protected bool botConnected = false; Dictionary> MyCustomEvents = new Dictionary>(); Dictionary lockouts = new Dictionary(); @@ -472,6 +472,10 @@ namespace SecondBotEvents.Services } protected void TriggerEvent(string eventName, Dictionary args) { + if (waitingForTimer == true) + { + return; + } if (myConfig.GetDebugMe() == true) { StringBuilder debugoutme = new StringBuilder(); @@ -809,6 +813,10 @@ namespace SecondBotEvents.Services long lastAvUpdate = 0; protected void TimedEvents() { + if(waitingForTimer == true) + { + return; + } TrackAvatarsOnParcel(); CleanLockouts(); ClockEvent(); @@ -837,14 +845,27 @@ namespace SecondBotEvents.Services { return "Waiting for bot"; } + else if(waitingForTimer == true) + { + if(SecondbotHelpers.UnixTimeNow() >= waitUntil) + { + waitingForTimer = false; + return "Ready for on events"; + } + return "Waiting for timer"; + } return "Active"; } + protected bool waitingForTimer = false; + protected long waitUntil = 0; protected void BotLoggedIn(object o, SimConnectedEventArgs e) { GetClient().Network.SimConnected -= BotLoggedIn; botConnected = true; LogFormater.Info("OnEvent Service [Active]"); + waitingForTimer = true; + waitUntil = SecondbotHelpers.UnixTimeNow() + myConfig.GetWaitSecsToStart(); AttachEvents(); } @@ -861,6 +882,8 @@ namespace SecondBotEvents.Services } Stop(); running = true; + waitingForTimer = true; + waitUntil = SecondbotHelpers.UnixTimeNow() + 9999; master.BotClientNoticeEvent += BotClientRestart; LogFormater.Info("OnEvent Service [Starting]"); } @@ -878,6 +901,8 @@ namespace SecondBotEvents.Services } master.BotClientNoticeEvent -= BotClientRestart; RemoveEvents(); + waitingForTimer = true; + waitUntil = SecondbotHelpers.UnixTimeNow() + 9999; } }