mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
Discord Bot Scaffolding
This commit is contained in:
parent
ceb3ab73c4
commit
c4bf4906ea
24 changed files with 1119 additions and 5 deletions
|
|
@ -804,6 +804,15 @@
|
|||
<setting name="MainWindow_Top" serializeAs="String">
|
||||
<value>50</value>
|
||||
</setting>
|
||||
<setting name="DiscordBotEnabled" serializeAs="String">
|
||||
<value>False</value>
|
||||
</setting>
|
||||
<setting name="DiscordBotPrefix" serializeAs="String">
|
||||
<value>asm</value>
|
||||
</setting>
|
||||
<setting name="DiscordBotToken" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
</ServerManagerTool.Config>
|
||||
</userSettings>
|
||||
</configuration>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
using ArkData;
|
||||
using Microsoft.WindowsAPICodePack.Dialogs;
|
||||
using ServerManagerTool.Discord.Interfaces;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.Targets;
|
||||
|
|
@ -23,6 +23,8 @@ using System.Threading.Tasks;
|
|||
using System.Windows;
|
||||
using System.Xml;
|
||||
using WPFSharp.Globalizer;
|
||||
using ServerManagerTool.Discord;
|
||||
using ServerManagerTool.Discord.Enums;
|
||||
|
||||
namespace ServerManagerTool
|
||||
{
|
||||
|
|
@ -39,6 +41,7 @@ namespace ServerManagerTool
|
|||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private CancellationTokenSource _tokenSource;
|
||||
private GlobalizedApplication _globalizer;
|
||||
private bool _applicationStarted;
|
||||
private string _args;
|
||||
|
|
@ -144,6 +147,12 @@ namespace ServerManagerTool
|
|||
}
|
||||
}
|
||||
|
||||
public IServerManagerBot ServerManagerBot
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public static void DiscoverMachinePublicIP(bool forceOverride)
|
||||
{
|
||||
if (forceOverride || string.IsNullOrWhiteSpace(Config.Default.MachinePublicIP))
|
||||
|
|
@ -179,7 +188,11 @@ 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();
|
||||
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));
|
||||
|
|
@ -218,6 +231,11 @@ namespace ServerManagerTool
|
|||
return LogManager.GetLogger(loggerName);
|
||||
}
|
||||
|
||||
private static IList<string> HandleDiscordCommand(CommandType commandType, string channelId, string profileId)
|
||||
{
|
||||
return new List<string>() { $"{commandType}; {channelId}; {profileId ?? "no profile"}" };
|
||||
}
|
||||
|
||||
private static void MigrateSettings()
|
||||
{
|
||||
var installFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
|
|
@ -412,6 +430,7 @@ namespace ServerManagerTool
|
|||
|
||||
ApplicationStarted = true;
|
||||
|
||||
var restartRequired = false;
|
||||
if (string.IsNullOrWhiteSpace(Config.Default.DataDir))
|
||||
{
|
||||
var dataDirectoryWindow = new DataDirectoryWindow();
|
||||
|
|
@ -422,6 +441,8 @@ namespace ServerManagerTool
|
|||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
restartRequired = true;
|
||||
}
|
||||
|
||||
Config.Default.ConfigDirectory = Path.Combine(Config.Default.DataDir, Config.Default.ProfilesDir);
|
||||
|
|
@ -429,6 +450,11 @@ namespace ServerManagerTool
|
|||
Config.Default.Save();
|
||||
CommonConfig.Default.Save();
|
||||
|
||||
if (restartRequired)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
DataFileDetails.PlayerFileExtension = Config.Default.PlayerFileExtension;
|
||||
DataFileDetails.TribeFileExtension = Config.Default.TribeFileExtension;
|
||||
|
||||
|
|
@ -446,6 +472,27 @@ namespace ServerManagerTool
|
|||
|
||||
StartupUri = new Uri("Windows/AutoUpdateWindow.xaml", UriKind.RelativeOrAbsolute);
|
||||
}
|
||||
|
||||
if (Config.Default.DiscordBotEnabled)
|
||||
{
|
||||
_tokenSource = new CancellationTokenSource();
|
||||
|
||||
ServerManagerBot = ServerManagerBotFactory.GetServerManagerBot();
|
||||
|
||||
Task discordTask = Task.Run(async () =>
|
||||
{
|
||||
await ServerManagerBot.StartAsync(Config.Default.DiscordBotPrefix, Config.Default.DiscordBotToken, Config.Default.DataDir, HandleDiscordCommand, _tokenSource.Token);
|
||||
}, _tokenSource.Token)
|
||||
.ContinueWith(t => {
|
||||
var message = t.Exception.InnerException is null ? t.Exception.Message : t.Exception.InnerException.Message;
|
||||
if (message.StartsWith("#"))
|
||||
{
|
||||
message = _globalizer.GetResourceString(message.Substring(1)) ?? message.Substring(1);
|
||||
}
|
||||
|
||||
MessageBox.Show(message, _globalizer.GetResourceString("DiscordBot_ErrorTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}, TaskContinuationOptions.OnlyOnFaulted);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnExit(ExitEventArgs e)
|
||||
|
|
@ -486,6 +533,12 @@ namespace ServerManagerTool
|
|||
|
||||
private void ShutDownApplication()
|
||||
{
|
||||
if (!(_tokenSource is null))
|
||||
{
|
||||
_tokenSource.Cancel();
|
||||
_tokenSource.Dispose();
|
||||
}
|
||||
|
||||
if (ApplicationStarted)
|
||||
{
|
||||
foreach (var server in ServerManager.Instance.Servers)
|
||||
|
|
|
|||
36
src/ARKServerManager/Config.Designer.cs
generated
36
src/ARKServerManager/Config.Designer.cs
generated
|
|
@ -2812,5 +2812,41 @@ namespace ServerManagerTool {
|
|||
return ((string)(this["DefaultDataDirectoryName"]));
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("False")]
|
||||
public bool DiscordBotEnabled {
|
||||
get {
|
||||
return ((bool)(this["DiscordBotEnabled"]));
|
||||
}
|
||||
set {
|
||||
this["DiscordBotEnabled"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("asm")]
|
||||
public string DiscordBotPrefix {
|
||||
get {
|
||||
return ((string)(this["DiscordBotPrefix"]));
|
||||
}
|
||||
set {
|
||||
this["DiscordBotPrefix"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("")]
|
||||
public string DiscordBotToken {
|
||||
get {
|
||||
return ((string)(this["DiscordBotToken"]));
|
||||
}
|
||||
set {
|
||||
this["DiscordBotToken"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -779,5 +779,14 @@
|
|||
<Setting Name="DefaultDataDirectoryName" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">asmdata</Value>
|
||||
</Setting>
|
||||
<Setting Name="DiscordBotEnabled" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">False</Value>
|
||||
</Setting>
|
||||
<Setting Name="DiscordBotPrefix" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)">asm</Value>
|
||||
</Setting>
|
||||
<Setting Name="DiscordBotToken" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
|
|
@ -5523,4 +5523,10 @@
|
|||
<sys:String x:Key="ServerUpdate_WarningLabel">There was a problem while performing the server update. This may leave your server in a incomplete state.\r\n\r\nDo you want to continue with the server start, this could cause problems?</sys:String>
|
||||
<!--#endregion-->
|
||||
|
||||
<!--#region Discord Bot -->
|
||||
<sys:String x:Key="DiscordBot_ErrorTitle">Discord Bot Error</sys:String>
|
||||
<sys:String x:Key="DiscordBot_MissingTokenError">The discord bot requires a valid token so it can log into the discord server\r\nThis can be set in the global settings.</sys:String>
|
||||
<sys:String x:Key="DiscordBot_InvalidPrefixError">The discord bot prefix contains invalid characters. Only letters and numbers are allowed.</sys:String>
|
||||
<!--#endregion-->
|
||||
|
||||
</Globalization:GlobalizationResourceDictionary>
|
||||
Loading…
Add table
Add a link
Reference in a new issue