Skip to content

Commit

Permalink
Works with HES v2 now.
Browse files Browse the repository at this point in the history
  • Loading branch information
generalwrex committed Feb 3, 2020
1 parent 84fc8c5 commit 1d90954
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 36 deletions.
14 changes: 10 additions & 4 deletions HESDiscordChatBot/DiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
62 changes: 37 additions & 25 deletions HESDiscordChatBot/HESDiscordChatBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>..\..\HellionExtendedServer\HellionExtendedServer\bin\Debug\Hes\plugins\DiscordBot\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand Down Expand Up @@ -48,48 +48,56 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Discord.Net.Commands, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Discord.Net.Commands.1.0.2\lib\netstandard1.1\Discord.Net.Commands.dll</HintPath>
</Reference>
<Reference Include="Discord.Net.Core, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Discord.Net.Core.1.0.2\lib\net45\Discord.Net.Core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Discord.Net.Rest, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Discord.Net.Rest.1.0.2\lib\net45\Discord.Net.Rest.dll</HintPath>
</Reference>
<Reference Include="Discord.Net.Rpc, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Discord.Net.Rpc.1.0.2\lib\net45\Discord.Net.Rpc.dll</HintPath>
<Reference Include="Discord.Net.Rest">
<HintPath>..\..\HellionExtendedServer\HellionExtendedServer\bin\Debug\Hes\bin\Discord.Net.Rest.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Discord.Net.Webhook, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Discord.Net.Webhook.1.0.2\lib\netstandard1.1\Discord.Net.Webhook.dll</HintPath>
<Reference Include="Discord.Net.Webhook">
<HintPath>..\..\HellionExtendedServer\HellionExtendedServer\bin\Debug\Hes\bin\Discord.Net.Webhook.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Discord.Net.WebSocket, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Discord.Net.WebSocket.1.0.2\lib\net45\Discord.Net.WebSocket.dll</HintPath>
<Reference Include="Discord.Net.WebSocket">
<HintPath>..\..\HellionExtendedServer\HellionExtendedServer\bin\Debug\Hes\bin\Discord.Net.WebSocket.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="HellionExtendedServer">
<HintPath>..\..\..\HES\HellionExtendedServer\bin\Debug\HellionExtendedServer.exe</HintPath>
<HintPath>..\..\HellionExtendedServer\HellionExtendedServer\bin\Debug\HellionExtendedServer.exe</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="HELLION_Dedicated">
<HintPath>..\..\..\HES\HellionExtendedServer\bin\Debug\HELLION_Dedicated.exe</HintPath>
<HintPath>..\..\HellionExtendedServer\HellionExtendedServer\bin\Debug\HELLION_Dedicated.exe</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Libraries\Newtonsoft.Json.dll</HintPath>
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.1.1.1\lib\netstandard1.1\Microsoft.Extensions.DependencyInjection.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Libraries\NLog.dll</HintPath>
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.1.1.1\lib\netstandard1.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NLog">
<HintPath>..\..\HellionExtendedServer\HellionExtendedServer\bin\Debug\NLog.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable, Version=1.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Libraries\System.Collections.Immutable.dll</HintPath>
<HintPath>..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.Interactive.Async, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Libraries\System.Interactive.Async.dll</HintPath>
<HintPath>..\packages\System.Interactive.Async.3.1.1\lib\net45\System.Interactive.Async.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.IO.Compression" />
<Reference Include="System.Numerics" />
Expand All @@ -100,6 +108,10 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Serialization" />
<Reference Include="WebSocket4Net, Version=0.14.1.0, Culture=neutral, PublicKeyToken=eb4e154b696bf72a, processorArchitecture=MSIL">
<HintPath>..\packages\WebSocket4Net.0.14.1\lib\net45\WebSocket4Net.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="MyConfig.cs" />
Expand Down
22 changes: 17 additions & 5 deletions HESDiscordChatBot/PluginMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -16,7 +16,7 @@ public class PluginMain : PluginBase
private static ulong channelID;
private static DiscordClient discordClient;

public ThreadSafeDictionary<long, NetworkController.Client> Clients { get { return GetServer.NetworkController.clientList; } }
public Dictionary<long, NetworkController.Client> Clients { get { return GetServer.NetworkController.ClientList; } }

public PluginMain()
{
Expand All @@ -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");

Expand All @@ -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.");
}

Expand Down
2 changes: 1 addition & 1 deletion HESDiscordChatBot/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Interactive.Async" publicKeyToken="94bc3704cddfc263" culture="neutral" />
Expand Down
2 changes: 1 addition & 1 deletion HESDiscordChatBot/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Discord.Net" version="1.0.2" targetFramework="net452" />
<package id="Discord.Net" version="2.1.1" targetFramework="net452" />
<package id="Discord.Net.Commands" version="1.0.2" targetFramework="net452" />
<package id="Discord.Net.Core" version="1.0.2" targetFramework="net452" />
<package id="Discord.Net.Rest" version="1.0.2" targetFramework="net452" />
Expand Down

0 comments on commit 1d90954

Please sign in to comment.