mirror of
https://github.com/tribufu/ServerManagers
synced 2026-06-01 09:42:39 +00:00
Created Helper classes for Discord Bot and Plugin
This commit is contained in:
parent
8d9d208a66
commit
d526a3f457
8 changed files with 74 additions and 35 deletions
|
|
@ -203,6 +203,8 @@
|
||||||
<Compile Include="Lib\ViewConverters\MapNameValueConverter.cs" />
|
<Compile Include="Lib\ViewConverters\MapNameValueConverter.cs" />
|
||||||
<Compile Include="Lib\ViewModel\Engram.cs" />
|
<Compile Include="Lib\ViewModel\Engram.cs" />
|
||||||
<Compile Include="Lib\ViewModel\EngramSettings.cs" />
|
<Compile Include="Lib\ViewModel\EngramSettings.cs" />
|
||||||
|
<Compile Include="Utils\DiscordBotHelper.cs" />
|
||||||
|
<Compile Include="Utils\DiscordPluginHelper.cs" />
|
||||||
<Compile Include="Utils\ModUtils.cs" />
|
<Compile Include="Utils\ModUtils.cs" />
|
||||||
<Compile Include="Windows\AddUserWindow.xaml.cs">
|
<Compile Include="Windows\AddUserWindow.xaml.cs">
|
||||||
<DependentUpon>AddUserWindow.xaml</DependentUpon>
|
<DependentUpon>AddUserWindow.xaml</DependentUpon>
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
using ArkData;
|
using ArkData;
|
||||||
using ServerManagerTool.Discord.Interfaces;
|
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Config;
|
using NLog.Config;
|
||||||
using NLog.Targets;
|
using NLog.Targets;
|
||||||
using ServerManagerTool.Common;
|
using ServerManagerTool.Common;
|
||||||
using ServerManagerTool.Common.Utils;
|
using ServerManagerTool.Common.Utils;
|
||||||
|
using ServerManagerTool.Discord;
|
||||||
using ServerManagerTool.Enums;
|
using ServerManagerTool.Enums;
|
||||||
using ServerManagerTool.Lib;
|
using ServerManagerTool.Lib;
|
||||||
using ServerManagerTool.Plugin.Common;
|
using ServerManagerTool.Plugin.Common;
|
||||||
|
using ServerManagerTool.Utils;
|
||||||
using ServerManagerTool.Windows;
|
using ServerManagerTool.Windows;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
@ -21,10 +21,7 @@ using System.Runtime.CompilerServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Xml;
|
|
||||||
using WPFSharp.Globalizer;
|
using WPFSharp.Globalizer;
|
||||||
using ServerManagerTool.Discord;
|
|
||||||
using ServerManagerTool.Discord.Enums;
|
|
||||||
|
|
||||||
namespace ServerManagerTool
|
namespace ServerManagerTool
|
||||||
{
|
{
|
||||||
|
|
@ -180,15 +177,6 @@ namespace ServerManagerTool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IList<Plugin.Common.Lib.Profile> FetchProfiles()
|
|
||||||
{
|
|
||||||
return ServerManager.Instance.Servers.Select(s => new ServerManagerTool.Plugin.Common.Lib.Profile()
|
|
||||||
{
|
|
||||||
ProfileName = s?.Profile?.ProfileName ?? string.Empty,
|
|
||||||
InstallationFolder = s?.Profile?.InstallDirectory ?? string.Empty
|
|
||||||
}).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetLogFolder() => IOUtils.NormalizePath(Path.Combine(Config.Default.DataDir, Config.Default.LogsDir));
|
public static string GetLogFolder() => IOUtils.NormalizePath(Path.Combine(Config.Default.DataDir, Config.Default.LogsDir));
|
||||||
|
|
||||||
public static string GetProfileLogFolder(string profileId) => IOUtils.NormalizePath(Path.Combine(Config.Default.DataDir, Config.Default.LogsDir, profileId.ToLower()));
|
public static string GetProfileLogFolder(string profileId) => IOUtils.NormalizePath(Path.Combine(Config.Default.DataDir, Config.Default.LogsDir, profileId.ToLower()));
|
||||||
|
|
@ -225,11 +213,6 @@ namespace ServerManagerTool
|
||||||
return LogManager.GetLogger(loggerName);
|
return LogManager.GetLogger(loggerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IList<string> HandleDiscordCommand(CommandType commandType, string serverId, string channelId, string profileId)
|
|
||||||
{
|
|
||||||
return new List<string>() { $"{commandType}; {serverId}; {channelId}; {profileId ?? "no profile"}" };
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void MigrateSettings()
|
private static void MigrateSettings()
|
||||||
{
|
{
|
||||||
var installFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
var installFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||||
|
|
@ -324,7 +307,7 @@ namespace ServerManagerTool
|
||||||
var installPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
var installPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||||
PluginHelper.Instance.BetaEnabled = this.BetaVersion;
|
PluginHelper.Instance.BetaEnabled = this.BetaVersion;
|
||||||
PluginHelper.Instance.LoadPlugins(installPath, true);
|
PluginHelper.Instance.LoadPlugins(installPath, true);
|
||||||
PluginHelper.Instance.SetFetchProfileCallback(FetchProfiles);
|
PluginHelper.Instance.SetFetchProfileCallback(DiscordPluginHelper.FetchProfiles);
|
||||||
OnResourceDictionaryChanged(Thread.CurrentThread.CurrentCulture.Name);
|
OnResourceDictionaryChanged(Thread.CurrentThread.CurrentCulture.Name);
|
||||||
|
|
||||||
// check if we are starting ASM for the old server restart - no longer supported
|
// check if we are starting ASM for the old server restart - no longer supported
|
||||||
|
|
@ -473,7 +456,7 @@ namespace ServerManagerTool
|
||||||
|
|
||||||
Task discordTask = Task.Run(async () =>
|
Task discordTask = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await ServerManagerBotFactory.GetServerManagerBot()?.StartAsync(Config.Default.DiscordBotToken, Config.Default.DiscordBotPrefix, Config.Default.DataDir, HandleDiscordCommand, _tokenSource.Token);
|
await ServerManagerBotFactory.GetServerManagerBot()?.StartAsync(Config.Default.DiscordBotToken, Config.Default.DiscordBotPrefix, Config.Default.DataDir, DiscordBotHelper.HandleDiscordCommand, _tokenSource.Token);
|
||||||
}, _tokenSource.Token)
|
}, _tokenSource.Token)
|
||||||
.ContinueWith(t => {
|
.ContinueWith(t => {
|
||||||
var message = t.Exception.InnerException is null ? t.Exception.Message : t.Exception.InnerException.Message;
|
var message = t.Exception.InnerException is null ? t.Exception.Message : t.Exception.InnerException.Message;
|
||||||
|
|
|
||||||
13
src/ARKServerManager/Utils/DiscordBotHelper.cs
Normal file
13
src/ARKServerManager/Utils/DiscordBotHelper.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
using ServerManagerTool.Discord.Enums;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace ServerManagerTool.Utils
|
||||||
|
{
|
||||||
|
internal static class DiscordBotHelper
|
||||||
|
{
|
||||||
|
public static IList<string> HandleDiscordCommand(CommandType commandType, string serverId, string channelId, string profileId)
|
||||||
|
{
|
||||||
|
return new List<string>() { $"{commandType}; {serverId}; {channelId}; {profileId ?? "no profile"}" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/ARKServerManager/Utils/DiscordPluginHelper.cs
Normal file
18
src/ARKServerManager/Utils/DiscordPluginHelper.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
using ServerManagerTool.Lib;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace ServerManagerTool.Utils
|
||||||
|
{
|
||||||
|
internal static class DiscordPluginHelper
|
||||||
|
{
|
||||||
|
public static IList<Plugin.Common.Lib.Profile> FetchProfiles()
|
||||||
|
{
|
||||||
|
return ServerManager.Instance.Servers.Select(s => new ServerManagerTool.Plugin.Common.Lib.Profile()
|
||||||
|
{
|
||||||
|
ProfileName = s?.Profile?.ProfileName ?? string.Empty,
|
||||||
|
InstallationFolder = s?.Profile?.InstallDirectory ?? string.Empty
|
||||||
|
}).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
using Microsoft.WindowsAPICodePack.Dialogs;
|
using NLog;
|
||||||
using NLog;
|
|
||||||
using NLog.Config;
|
using NLog.Config;
|
||||||
using NLog.Targets;
|
using NLog.Targets;
|
||||||
using ServerManagerTool.Common;
|
using ServerManagerTool.Common;
|
||||||
using ServerManagerTool.Common.Utils;
|
using ServerManagerTool.Common.Utils;
|
||||||
using ServerManagerTool.Discord;
|
using ServerManagerTool.Discord;
|
||||||
using ServerManagerTool.Discord.Enums;
|
using ServerManagerTool.Discord.Enums;
|
||||||
using ServerManagerTool.Discord.Interfaces;
|
|
||||||
using ServerManagerTool.Enums;
|
using ServerManagerTool.Enums;
|
||||||
using ServerManagerTool.Lib;
|
using ServerManagerTool.Lib;
|
||||||
using ServerManagerTool.Plugin.Common;
|
using ServerManagerTool.Plugin.Common;
|
||||||
|
using ServerManagerTool.Utils;
|
||||||
using ServerManagerTool.Windows;
|
using ServerManagerTool.Windows;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -179,15 +178,6 @@ namespace ServerManagerTool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IList<Plugin.Common.Lib.Profile> FetchProfiles()
|
|
||||||
{
|
|
||||||
return ServerManager.Instance.Servers.Select(s => new ServerManagerTool.Plugin.Common.Lib.Profile()
|
|
||||||
{
|
|
||||||
ProfileName = s?.Profile?.ProfileName ?? string.Empty,
|
|
||||||
InstallationFolder = s?.Profile?.InstallDirectory ?? string.Empty
|
|
||||||
}).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetLogFolder() => IOUtils.NormalizePath(Path.Combine(Config.Default.DataPath, Config.Default.LogsRelativePath));
|
public static string GetLogFolder() => IOUtils.NormalizePath(Path.Combine(Config.Default.DataPath, Config.Default.LogsRelativePath));
|
||||||
|
|
||||||
public static string GetProfileLogFolder(string profileId) => IOUtils.NormalizePath(Path.Combine(Config.Default.DataPath, Config.Default.LogsRelativePath, profileId.ToLower()));
|
public static string GetProfileLogFolder(string profileId) => IOUtils.NormalizePath(Path.Combine(Config.Default.DataPath, Config.Default.LogsRelativePath, profileId.ToLower()));
|
||||||
|
|
@ -317,7 +307,7 @@ namespace ServerManagerTool
|
||||||
var installPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
var installPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||||
PluginHelper.Instance.BetaEnabled = this.BetaVersion;
|
PluginHelper.Instance.BetaEnabled = this.BetaVersion;
|
||||||
PluginHelper.Instance.LoadPlugins(installPath, true);
|
PluginHelper.Instance.LoadPlugins(installPath, true);
|
||||||
PluginHelper.Instance.SetFetchProfileCallback(FetchProfiles);
|
PluginHelper.Instance.SetFetchProfileCallback(DiscordPluginHelper.FetchProfiles);
|
||||||
OnResourceDictionaryChanged(Thread.CurrentThread.CurrentCulture.Name);
|
OnResourceDictionaryChanged(Thread.CurrentThread.CurrentCulture.Name);
|
||||||
|
|
||||||
// check if we are starting server manager for server shutdown
|
// check if we are starting server manager for server shutdown
|
||||||
|
|
@ -454,7 +444,7 @@ namespace ServerManagerTool
|
||||||
|
|
||||||
Task discordTask = Task.Run(async () =>
|
Task discordTask = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await ServerManagerBotFactory.GetServerManagerBot()?.StartAsync(Config.Default.DiscordBotToken,Config.Default.DiscordBotPrefix, Config.Default.DataPath, HandleDiscordCommand, _tokenSource.Token);
|
await ServerManagerBotFactory.GetServerManagerBot()?.StartAsync(Config.Default.DiscordBotToken,Config.Default.DiscordBotPrefix, Config.Default.DataPath, DiscordBotHelper.HandleDiscordCommand, _tokenSource.Token);
|
||||||
}, _tokenSource.Token)
|
}, _tokenSource.Token)
|
||||||
.ContinueWith(t => {
|
.ContinueWith(t => {
|
||||||
var message = t.Exception.InnerException is null ? t.Exception.Message : t.Exception.InnerException.Message;
|
var message = t.Exception.InnerException is null ? t.Exception.Message : t.Exception.InnerException.Message;
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,8 @@
|
||||||
<Compile Include="Lib\ViewConverters\EnumDescriptionTypeConverter.cs" />
|
<Compile Include="Lib\ViewConverters\EnumDescriptionTypeConverter.cs" />
|
||||||
<Compile Include="Lib\ViewConverters\MapNameValueConverter.cs" />
|
<Compile Include="Lib\ViewConverters\MapNameValueConverter.cs" />
|
||||||
<Compile Include="Lib\ViewModel\PlayerInfo.cs" />
|
<Compile Include="Lib\ViewModel\PlayerInfo.cs" />
|
||||||
|
<Compile Include="Utils\DiscordBotHelper.cs" />
|
||||||
|
<Compile Include="Utils\DiscordPluginHelper.cs" />
|
||||||
<Compile Include="Windows\AddUserWindow.xaml.cs">
|
<Compile Include="Windows\AddUserWindow.xaml.cs">
|
||||||
<DependentUpon>AddUserWindow.xaml</DependentUpon>
|
<DependentUpon>AddUserWindow.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
|
||||||
13
src/ConanServerManager/Utils/DiscordBotHelper.cs
Normal file
13
src/ConanServerManager/Utils/DiscordBotHelper.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
using ServerManagerTool.Discord.Enums;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace ServerManagerTool.Utils
|
||||||
|
{
|
||||||
|
internal static class DiscordBotHelper
|
||||||
|
{
|
||||||
|
public static IList<string> HandleDiscordCommand(CommandType commandType, string serverId, string channelId, string profileId)
|
||||||
|
{
|
||||||
|
return new List<string>() { $"{commandType}; {serverId}; {channelId}; {profileId ?? "no profile"}" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/ConanServerManager/Utils/DiscordPluginHelper.cs
Normal file
18
src/ConanServerManager/Utils/DiscordPluginHelper.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
using ServerManagerTool.Lib;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace ServerManagerTool.Utils
|
||||||
|
{
|
||||||
|
internal static class DiscordPluginHelper
|
||||||
|
{
|
||||||
|
public static IList<Plugin.Common.Lib.Profile> FetchProfiles()
|
||||||
|
{
|
||||||
|
return ServerManager.Instance.Servers.Select(s => new ServerManagerTool.Plugin.Common.Lib.Profile()
|
||||||
|
{
|
||||||
|
ProfileName = s?.Profile?.ProfileName ?? string.Empty,
|
||||||
|
InstallationFolder = s?.Profile?.InstallDirectory ?? string.Empty
|
||||||
|
}).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue