Created Helper classes for Discord Bot and Plugin

This commit is contained in:
Brett Hewitson 2021-12-04 15:01:47 +10:00
parent 8d9d208a66
commit d526a3f457
8 changed files with 74 additions and 35 deletions

View file

@ -1,15 +1,14 @@
using Microsoft.WindowsAPICodePack.Dialogs;
using NLog;
using NLog;
using NLog.Config;
using NLog.Targets;
using ServerManagerTool.Common;
using ServerManagerTool.Common.Utils;
using ServerManagerTool.Discord;
using ServerManagerTool.Discord.Enums;
using ServerManagerTool.Discord.Interfaces;
using ServerManagerTool.Enums;
using ServerManagerTool.Lib;
using ServerManagerTool.Plugin.Common;
using ServerManagerTool.Utils;
using ServerManagerTool.Windows;
using System;
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 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);
PluginHelper.Instance.BetaEnabled = this.BetaVersion;
PluginHelper.Instance.LoadPlugins(installPath, true);
PluginHelper.Instance.SetFetchProfileCallback(FetchProfiles);
PluginHelper.Instance.SetFetchProfileCallback(DiscordPluginHelper.FetchProfiles);
OnResourceDictionaryChanged(Thread.CurrentThread.CurrentCulture.Name);
// check if we are starting server manager for server shutdown
@ -454,7 +444,7 @@ namespace ServerManagerTool
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)
.ContinueWith(t => {
var message = t.Exception.InnerException is null ? t.Exception.Message : t.Exception.InnerException.Message;

View file

@ -171,6 +171,8 @@
<Compile Include="Lib\ViewConverters\EnumDescriptionTypeConverter.cs" />
<Compile Include="Lib\ViewConverters\MapNameValueConverter.cs" />
<Compile Include="Lib\ViewModel\PlayerInfo.cs" />
<Compile Include="Utils\DiscordBotHelper.cs" />
<Compile Include="Utils\DiscordPluginHelper.cs" />
<Compile Include="Windows\AddUserWindow.xaml.cs">
<DependentUpon>AddUserWindow.xaml</DependentUpon>
</Compile>

View 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"}" };
}
}
}

View 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();
}
}
}