From 1d90954cfc3a3d89a5901cae551a385fb7550a8c Mon Sep 17 00:00:00 2001 From: General Wrex Date: Mon, 3 Feb 2020 11:49:51 -0800 Subject: [PATCH] Works with HES v2 now. --- HESDiscordChatBot/DiscordClient.cs | 14 +++-- HESDiscordChatBot/HESDiscordChatBot.csproj | 62 +++++++++++++--------- HESDiscordChatBot/PluginMain.cs | 22 ++++++-- HESDiscordChatBot/app.config | 2 +- HESDiscordChatBot/packages.config | 2 +- 5 files changed, 66 insertions(+), 36 deletions(-) diff --git a/HESDiscordChatBot/DiscordClient.cs b/HESDiscordChatBot/DiscordClient.cs index bad7bd9..4e4452f 100644 --- a/HESDiscordChatBot/DiscordClient.cs +++ b/HESDiscordChatBot/DiscordClient.cs @@ -18,13 +18,19 @@ public class DiscordClient public static bool botStarted = false; - public DiscordClient() + public DiscordClient(MyConfig config) { - Instance = this; + try + { + Instance = this; - debugMode = MyConfig.Instance.Settings.DebugMode; + Console.WriteLine(!config.Settings.DebugMode ? String.Empty : "HESDiscordChatBot - Bot Client Constructed"); + } + catch (Exception ex) + { + Console.WriteLine("Error constructing DiscordPlugin:\n" + ex.ToString()); + } - Console.WriteLine(!debugMode ? String.Empty : "HESDiscordChatBot - Bot Client Constructed"); } public void Start() diff --git a/HESDiscordChatBot/HESDiscordChatBot.csproj b/HESDiscordChatBot/HESDiscordChatBot.csproj index 51e73fb..7e4f0c3 100644 --- a/HESDiscordChatBot/HESDiscordChatBot.csproj +++ b/HESDiscordChatBot/HESDiscordChatBot.csproj @@ -16,7 +16,7 @@ true full false - bin\Debug\ + ..\..\HellionExtendedServer\HellionExtendedServer\bin\Debug\Hes\plugins\DiscordBot\ DEBUG;TRACE prompt 4 @@ -48,48 +48,56 @@ MinimumRecommendedRules.ruleset - - ..\packages\Discord.Net.Commands.1.0.2\lib\netstandard1.1\Discord.Net.Commands.dll - ..\packages\Discord.Net.Core.1.0.2\lib\net45\Discord.Net.Core.dll + False - - ..\packages\Discord.Net.Rest.1.0.2\lib\net45\Discord.Net.Rest.dll - - - ..\packages\Discord.Net.Rpc.1.0.2\lib\net45\Discord.Net.Rpc.dll + + ..\..\HellionExtendedServer\HellionExtendedServer\bin\Debug\Hes\bin\Discord.Net.Rest.dll + False - - ..\packages\Discord.Net.Webhook.1.0.2\lib\netstandard1.1\Discord.Net.Webhook.dll + + ..\..\HellionExtendedServer\HellionExtendedServer\bin\Debug\Hes\bin\Discord.Net.Webhook.dll + False - - ..\packages\Discord.Net.WebSocket.1.0.2\lib\net45\Discord.Net.WebSocket.dll + + ..\..\HellionExtendedServer\HellionExtendedServer\bin\Debug\Hes\bin\Discord.Net.WebSocket.dll + False - ..\..\..\HES\HellionExtendedServer\bin\Debug\HellionExtendedServer.exe + ..\..\HellionExtendedServer\HellionExtendedServer\bin\Debug\HellionExtendedServer.exe + False - ..\..\..\HES\HellionExtendedServer\bin\Debug\HELLION_Dedicated.exe + ..\..\HellionExtendedServer\HellionExtendedServer\bin\Debug\HELLION_Dedicated.exe + False - - False - Libraries\Newtonsoft.Json.dll + + ..\packages\Microsoft.Extensions.DependencyInjection.1.1.1\lib\netstandard1.1\Microsoft.Extensions.DependencyInjection.dll + False - - False - Libraries\NLog.dll + + ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.1.1.1\lib\netstandard1.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll + False + + + ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll + False + + + ..\..\HellionExtendedServer\HellionExtendedServer\bin\Debug\NLog.dll + False - False - Libraries\System.Collections.Immutable.dll + ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + False - False - Libraries\System.Interactive.Async.dll + ..\packages\System.Interactive.Async.3.1.1\lib\net45\System.Interactive.Async.dll + False @@ -100,6 +108,10 @@ + + ..\packages\WebSocket4Net.0.14.1\lib\net45\WebSocket4Net.dll + False + diff --git a/HESDiscordChatBot/PluginMain.cs b/HESDiscordChatBot/PluginMain.cs index aef7bd2..281efe8 100644 --- a/HESDiscordChatBot/PluginMain.cs +++ b/HESDiscordChatBot/PluginMain.cs @@ -2,10 +2,10 @@ using HellionExtendedServer.Common.Plugins; using HellionExtendedServer.Managers.Plugins; using System; +using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using ZeroGravity.Network; -using ZeroGravity.Helpers; namespace HESDiscordChatBot { @@ -16,7 +16,7 @@ public class PluginMain : PluginBase private static ulong channelID; private static DiscordClient discordClient; - public ThreadSafeDictionary Clients { get { return GetServer.NetworkController.clientList; } } + public Dictionary Clients { get { return GetServer.NetworkController.ClientList; } } public PluginMain() { @@ -28,17 +28,26 @@ public override void Init(string modDirectory) { try { + MyConfig.FileName = Path.Combine(modDirectory, "Config.xml"); var config = new MyConfig(); debugMode = config.Settings.DebugMode; channelID = config.Settings.MainChannelID; - discordClient = new DiscordClient(); + try + { + discordClient = new DiscordClient(config); + + DiscordClient.SocketClient.MessageReceived += SocketClient_MessageReceived; - DiscordClient.SocketClient.MessageReceived += SocketClient_MessageReceived; + DiscordClient.Instance.Start(); + } + catch (Exception ex1) + { + GetLogger.Warn(ex1, "HESDiscordChatBot Discord Initialization failed."); + } - DiscordClient.Instance.Start(); Console.WriteLine("HESDiscordChatBot - Bot Started"); @@ -59,9 +68,12 @@ public override void Init(string modDirectory) Console.Write(" [LogOutRequest]"); Console.WriteLine("HESDiscordChatBot - Events Registered!"); + + } catch (Exception ex) { + Console.WriteLine(ex.ToString()); GetLogger.Warn(ex, "HESDiscordChatBot Initialization failed."); } diff --git a/HESDiscordChatBot/app.config b/HESDiscordChatBot/app.config index b5e8123..c2f9fa9 100644 --- a/HESDiscordChatBot/app.config +++ b/HESDiscordChatBot/app.config @@ -4,7 +4,7 @@ - + diff --git a/HESDiscordChatBot/packages.config b/HESDiscordChatBot/packages.config index f6b1d68..3a2696b 100644 --- a/HESDiscordChatBot/packages.config +++ b/HESDiscordChatBot/packages.config @@ -1,6 +1,6 @@  - +