From dff8897804ad7cc1bbe468571dfc99d299583f47 Mon Sep 17 00:00:00 2001 From: Madpeter <57852827+Madpeterz@users.noreply.github.com> Date: Wed, 2 Oct 2024 00:10:35 +0100 Subject: [PATCH] adds support to control ChatGptService via the commands service --- SecondBotEvents/Commands/Services.cs | 11 ++++++++--- SecondBotEvents/Services/ChatGptService.cs | 23 +++++++++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/SecondBotEvents/Commands/Services.cs b/SecondBotEvents/Commands/Services.cs index 7429e3c..884b3fe 100644 --- a/SecondBotEvents/Commands/Services.cs +++ b/SecondBotEvents/Commands/Services.cs @@ -17,14 +17,17 @@ namespace SecondBotEvents.Commands "EventsService
" + "DialogService
" + "TriggerOnEventService
" + - "RelayService")] + "RelayService
" + + "ChatGptService")] public class Services : CommandsAPI { public Services(EventsSecondBot setmaster) : base(setmaster) { } - protected List controlable = new List { "BotClientService","RLVService", + protected List controlable = new List { + "BotClientService", + "RLVService", "HttpService", "DiscordService", "InteractionService", @@ -32,7 +35,9 @@ namespace SecondBotEvents.Commands "EventsService", "DialogService", "TriggerOnEventService", - "RelayService"}; + "RelayService", + "ChatGptService" + }; [About("Marks a service as enabled and starts it")] [ReturnHints("ok")] diff --git a/SecondBotEvents/Services/ChatGptService.cs b/SecondBotEvents/Services/ChatGptService.cs index 1a25c07..36cd5c8 100644 --- a/SecondBotEvents/Services/ChatGptService.cs +++ b/SecondBotEvents/Services/ChatGptService.cs @@ -47,6 +47,7 @@ namespace SecondBotEvents.Services } if (myConfig.GetEnabled() == false) { + Stop(); return; } chatHistorySize = inrange(3,10,myConfig.GetChatHistoryMessages()); @@ -66,7 +67,27 @@ namespace SecondBotEvents.Services public override void Stop() { - running = false; + if (running == true) + { + running = false; + LogFormater.Info("ChatGpt [Stopping]"); + if (master != null) + { + master.BotClientNoticeEvent -= BotClientRestart; + } + if (GetClient() != null) + { + if (GetClient().Network != null) + { + GetClient().Network.SimConnected -= BotLoggedIn; + } + if (GetClient().Self != null) + { + GetClient().Self.IM -= BotImMessage; + GetClient().Self.ChatFromSimulator -= BotLocalchat; + } + } + } } public override string Status()