diff --git a/src/ARKServerManager/App.config b/src/ARKServerManager/App.config
index 10b747b7..a136ee00 100644
--- a/src/ARKServerManager/App.config
+++ b/src/ARKServerManager/App.config
@@ -353,6 +353,9 @@
https://arkservermanager.freeforums.net/thread/8764/get-own-discord-bot
+
+ 10
+
diff --git a/src/ARKServerManager/Config.Designer.cs b/src/ARKServerManager/Config.Designer.cs
index 39bbded1..60833055 100644
--- a/src/ARKServerManager/Config.Designer.cs
+++ b/src/ARKServerManager/Config.Designer.cs
@@ -3023,5 +3023,14 @@ namespace ServerManagerTool {
this["DiscordBotLogLevel"] = value;
}
}
+
+ [global::System.Configuration.ApplicationScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("10")]
+ public int DiscordBotStatusCheckTime {
+ get {
+ return ((int)(this["DiscordBotStatusCheckTime"]));
+ }
+ }
}
}
diff --git a/src/ARKServerManager/Config.settings b/src/ARKServerManager/Config.settings
index 00b1e243..19c0a3ec 100644
--- a/src/ARKServerManager/Config.settings
+++ b/src/ARKServerManager/Config.settings
@@ -834,5 +834,8 @@
Info
+
+ 10
+
\ No newline at end of file
diff --git a/src/ARKServerManager/Globalization/en-US/en-US.xaml b/src/ARKServerManager/Globalization/en-US/en-US.xaml
index e8073fed..5d540166 100644
--- a/src/ARKServerManager/Globalization/en-US/en-US.xaml
+++ b/src/ARKServerManager/Globalization/en-US/en-US.xaml
@@ -790,12 +790,18 @@
Enable
Enable the auto-update scheduled task
Next Run Time:
+ Discord Bot:
+ Start
+ Start the discord bot
+ Stop
+ Stop the discord bot
Unknown
Disabled
Queued
Ready
Running
+ Stopped
Profile failed to load
The profile at {0} failed to load. The error was: {1}\r\n{2}
diff --git a/src/ARKServerManager/VersionFeed.xml b/src/ARKServerManager/VersionFeed.xml
index b9ab2012..d2349003 100644
--- a/src/ARKServerManager/VersionFeed.xml
+++ b/src/ARKServerManager/VersionFeed.xml
@@ -9,8 +9,8 @@
urn:uuid:3E33DCB2-ECFE-4489-B1A4-56F5D386F9DC
- 1.1.413 (1.1.413.6)
- 1.1.413.6
+ 1.1.413 (1.1.413.7)
+ 1.1.413.7
2021-12-17T00:00:00Z
@@ -22,6 +22,7 @@
Global Settings - Discord Bot section - Added a log level droplist.
Global Settings - Discord Bot section - Added a whitelist to allow bots to send commands to the server manager.
Server Settings - Discord Bot section - Added an alias that can be used with the discord command instead of the profile id.
+ Main Window - Added Discord Bot Status and a button to Stop/Start the discord bot.
CHANGE
diff --git a/src/ARKServerManager/VersionFeedBeta.xml b/src/ARKServerManager/VersionFeedBeta.xml
index 922adc92..ae26ac53 100644
--- a/src/ARKServerManager/VersionFeedBeta.xml
+++ b/src/ARKServerManager/VersionFeedBeta.xml
@@ -7,6 +7,29 @@
2021-12-16T00:00:00Z
+
+ urn:uuid:8EE5659C-18E6-47D3-941D-C32B129D2E06
+ 1.1.413 (1.1.413.7)
+ 1.1.413.7
+
+ 2021-12-17T00:00:00Z
+
+
+
+ NEW
+
+
+ - Main Window - Added Discord Bot Status and a button to Stop/Start the discord bot.
+
+
+
+
+
+ bletch
+ bletch1971@hotmail.com
+
+
+
urn:uuid:65A7E6B1-98D1-422D-B42F-B0EBB1D20E41
1.1.413 (1.1.413.6)
diff --git a/src/ARKServerManager/Windows/MainWindow.xaml b/src/ARKServerManager/Windows/MainWindow.xaml
index 5eeba4bc..cbaf9329 100644
--- a/src/ARKServerManager/Windows/MainWindow.xaml
+++ b/src/ARKServerManager/Windows/MainWindow.xaml
@@ -9,6 +9,7 @@
xmlns:cvr="clr-namespace:ServerManagerTool.Common.ValidationRules;assembly=ServerManager.Common"
xmlns:com="clr-namespace:ServerManagerTool.Common;assembly=ServerManager.Common"
xmlns:enum="clr-namespace:ServerManagerTool.Enums"
+ xmlns:bot="clr-namespace:ServerManagerTool.DiscordBot;assembly=ServerManager.Discord"
MinWidth="900" MinHeight="600" Width="1100" Height="900" Left="50" Top="50" WindowState="Normal"
Loaded="MainWindow_Loaded" SizeChanged="MainWindow_SizeChanged" StateChanged="MainWindow_StateChanged" LocationChanged="MainWindow_LocationChanged"
Name="Main" Icon="../Art/favicon.ico" Title="{DynamicResource MainWindow_Title}">
@@ -132,6 +133,7 @@
+
@@ -257,6 +259,61 @@
+
+
+
+
+
+
diff --git a/src/ARKServerManager/Windows/MainWindow.xaml.cs b/src/ARKServerManager/Windows/MainWindow.xaml.cs
index d5456da1..ad172d40 100644
--- a/src/ARKServerManager/Windows/MainWindow.xaml.cs
+++ b/src/ARKServerManager/Windows/MainWindow.xaml.cs
@@ -30,6 +30,9 @@ namespace ServerManagerTool
private readonly GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
private readonly ActionQueue versionChecker;
private readonly ActionQueue scheduledTaskChecker;
+ private readonly ActionQueue discordBotChecker;
+
+ private bool discordBotStateClicked = false;
public static readonly DependencyProperty AppInstanceProperty = DependencyProperty.Register(nameof(AppInstance), typeof(App), typeof(MainWindow), new PropertyMetadata(null));
public static readonly DependencyProperty ConfigProperty = DependencyProperty.Register(nameof(Config), typeof(Config), typeof(MainWindow), new PropertyMetadata(null));
@@ -40,6 +43,8 @@ namespace ServerManagerTool
public static readonly DependencyProperty AutoUpdateStateProperty = DependencyProperty.Register(nameof(AutoUpdateState), typeof(Microsoft.Win32.TaskScheduler.TaskState), typeof(MainWindow), new PropertyMetadata(Microsoft.Win32.TaskScheduler.TaskState.Unknown));
public static readonly DependencyProperty AutoUpdateStateStringProperty = DependencyProperty.Register(nameof(AutoUpdateStateString), typeof(string), typeof(MainWindow), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty AutoUpdateNextRunTimeProperty = DependencyProperty.Register(nameof(AutoUpdateNextRunTime), typeof(string), typeof(MainWindow), new PropertyMetadata(string.Empty));
+ public static readonly DependencyProperty DiscordBotStateProperty = DependencyProperty.Register(nameof(DiscordBotState), typeof(DiscordBot.Enums.BotState), typeof(MainWindow), new PropertyMetadata(DiscordBot.Enums.BotState.Unknown));
+ public static readonly DependencyProperty DiscordBotStateStringProperty = DependencyProperty.Register(nameof(DiscordBotStateString), typeof(string), typeof(MainWindow), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty IsIpValidProperty = DependencyProperty.Register(nameof(IsIpValid), typeof(bool), typeof(MainWindow), new PropertyMetadata(false));
public static readonly DependencyProperty LatestServerManagerVersionProperty = DependencyProperty.Register(nameof(LatestServerManagerVersion), typeof(Version), typeof(MainWindow), new PropertyMetadata(new Version()));
public static readonly DependencyProperty NewServerManagerAvailableProperty = DependencyProperty.Register(nameof(NewServerManagerAvailable), typeof(bool), typeof(MainWindow), new PropertyMetadata(false));
@@ -57,6 +62,7 @@ namespace ServerManagerTool
this.DataContext = this;
this.versionChecker = new ActionQueue();
this.scheduledTaskChecker = new ActionQueue();
+ this.discordBotChecker = new ActionQueue();
IsAdministrator = SecurityUtils.IsAdministrator();
if (!string.IsNullOrWhiteSpace(App.Instance.Title))
@@ -139,6 +145,18 @@ namespace ServerManagerTool
set { SetValue(AutoUpdateNextRunTimeProperty, value); }
}
+ public DiscordBot.Enums.BotState DiscordBotState
+ {
+ get { return (DiscordBot.Enums.BotState)GetValue(DiscordBotStateProperty); }
+ set { SetValue(DiscordBotStateProperty, value); }
+ }
+
+ public string DiscordBotStateString
+ {
+ get { return (string)GetValue(DiscordBotStateStringProperty); }
+ set { SetValue(DiscordBotStateStringProperty, value); }
+ }
+
public bool IsAdministrator
{
get;
@@ -191,6 +209,7 @@ namespace ServerManagerTool
this.versionChecker.PostAction(CheckForUpdates).DoNotWait();
this.scheduledTaskChecker.PostAction(CheckForScheduledTasks).DoNotWait();
+ this.discordBotChecker.PostAction(CheckForDiscordBot).DoNotWait();
}
private void MainWindow_LocationChanged(object sender, EventArgs e)
@@ -254,6 +273,7 @@ namespace ServerManagerTool
this.Title = _globalizer.GetResourceString("MainWindow_Title");
this.scheduledTaskChecker.PostAction(CheckForScheduledTasks).DoNotWait();
+ this.discordBotChecker.PostAction(CheckForDiscordBot).DoNotWait();
}
private void PatchNotes_Click(object sender, RoutedEventArgs e)
@@ -571,6 +591,36 @@ namespace ServerManagerTool
}
}
+ private async void DiscordBotTaskState_Click(object sender, RoutedEventArgs e)
+ {
+ if (discordBotStateClicked)
+ return;
+ discordBotStateClicked = true;
+
+ try
+ {
+ switch (DiscordBotState)
+ {
+ case DiscordBot.Enums.BotState.Stopped:
+ AppInstance.StartDiscordBot();
+ break;
+ case DiscordBot.Enums.BotState.Running:
+ AppInstance.StopDiscordBot();
+ break;
+ }
+
+ await Task.Delay(5000);
+ }
+ catch (Exception)
+ {
+ // Ignore.
+ }
+ finally
+ {
+ discordBotStateClicked = false;
+ }
+ }
+
public ICommand ShowWindowCommand
{
get
@@ -662,8 +712,8 @@ namespace ServerManagerTool
this.AutoBackupState = backupState;
this.AutoUpdateState = updateState;
- this.AutoBackupStateString = GetTaskStateString(AutoBackupState);
- this.AutoUpdateStateString = GetTaskStateString(AutoUpdateState);
+ this.AutoBackupStateString = GetTaskSchedulerStateString(AutoBackupState);
+ this.AutoUpdateStateString = GetTaskSchedulerStateString(AutoUpdateState);
this.AutoBackupNextRunTime = backupnextRunTime == DateTime.MinValue ? string.Empty : $"{_globalizer.GetResourceString("MainWindow_TaskRunTimeLabel")} {backupnextRunTime:G}";
this.AutoUpdateNextRunTime = updatenextRunTime == DateTime.MinValue ? string.Empty : $"{_globalizer.GetResourceString("MainWindow_TaskRunTimeLabel")} {updatenextRunTime:G}";
@@ -680,7 +730,46 @@ namespace ServerManagerTool
this.scheduledTaskChecker.PostAction(CheckForScheduledTasks).DoNotWait();
}
- private string GetTaskStateString(Microsoft.Win32.TaskScheduler.TaskState taskState)
+ private async Task CheckForDiscordBot()
+ {
+ TaskUtils.RunOnUIThreadAsync(() =>
+ {
+ try
+ {
+ var botState = DiscordBot.Enums.BotState.Unknown;
+ if (AppInstance.DiscordBotStarted)
+ {
+ botState = DiscordBot.Enums.BotState.Running;
+ }
+ else
+ {
+ if (Config.DiscordBotEnabled)
+ {
+ botState = DiscordBot.Enums.BotState.Stopped;
+ }
+ else
+ {
+ botState = DiscordBot.Enums.BotState.Disabled;
+ }
+ }
+
+ this.DiscordBotState = botState;
+
+ this.DiscordBotStateString = GetDiscordBotStateString(botState);
+
+ Logger.Info($"{nameof(CheckForDiscordBot)} performed");
+ }
+ catch (Exception)
+ {
+ // Ignore.
+ }
+ }).DoNotWait();
+
+ await Task.Delay(Config.Default.DiscordBotStatusCheckTime * 1 * 1000);
+ this.discordBotChecker.PostAction(CheckForDiscordBot).DoNotWait();
+ }
+
+ private string GetTaskSchedulerStateString(Microsoft.Win32.TaskScheduler.TaskState taskState)
{
switch (taskState)
{
@@ -699,6 +788,21 @@ namespace ServerManagerTool
}
}
+ private string GetDiscordBotStateString(DiscordBot.Enums.BotState botState)
+ {
+ switch (botState)
+ {
+ case DiscordBot.Enums.BotState.Disabled:
+ return _globalizer.GetResourceString("MainWindow_TaskStateDisabledLabel");
+ case DiscordBot.Enums.BotState.Running:
+ return _globalizer.GetResourceString("MainWindow_TaskStateRunningLabel");
+ case DiscordBot.Enums.BotState.Stopped:
+ return _globalizer.GetResourceString("MainWindow_TaskStateStoppedLabel");
+ default:
+ return _globalizer.GetResourceString("MainWindow_TaskStateUnknownLabel");
+ }
+ }
+
private async Task StartServerAsync(Server server)
{
if (server == null || server.Profile == null || server.Runtime == null || server.Runtime.Status != ServerStatus.Stopped)
diff --git a/src/ConanServerManager/App.config b/src/ConanServerManager/App.config
index e5424f03..61f2b35c 100644
--- a/src/ConanServerManager/App.config
+++ b/src/ConanServerManager/App.config
@@ -263,6 +263,9 @@
https://servermanagers.freeforums.net/thread/99/get-own-discord-bot
+
+ 10
+
diff --git a/src/ConanServerManager/Config.Designer.cs b/src/ConanServerManager/Config.Designer.cs
index e40502ea..9a861e60 100644
--- a/src/ConanServerManager/Config.Designer.cs
+++ b/src/ConanServerManager/Config.Designer.cs
@@ -2176,5 +2176,14 @@ namespace ServerManagerTool {
this["DiscordBotLogLevel"] = value;
}
}
+
+ [global::System.Configuration.ApplicationScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("10")]
+ public int DiscordBotStatusCheckTime {
+ get {
+ return ((int)(this["DiscordBotStatusCheckTime"]));
+ }
+ }
}
}
diff --git a/src/ConanServerManager/Config.settings b/src/ConanServerManager/Config.settings
index bc3afb46..3d319f4d 100644
--- a/src/ConanServerManager/Config.settings
+++ b/src/ConanServerManager/Config.settings
@@ -600,5 +600,8 @@
Info
+
+ 10
+
\ No newline at end of file
diff --git a/src/ConanServerManager/Globalization/en-US/en-US.xaml b/src/ConanServerManager/Globalization/en-US/en-US.xaml
index a293c4b8..392e8d78 100644
--- a/src/ConanServerManager/Globalization/en-US/en-US.xaml
+++ b/src/ConanServerManager/Globalization/en-US/en-US.xaml
@@ -615,12 +615,18 @@
Enable
Enable the auto-update scheduled task
Next Run Time:
+ Discord Bot:
+ Start
+ Start the discord bot
+ Stop
+ Stop the discord bot
Unknown
Disabled
Queued
Ready
Running
+ Stopped
Profile failed to load
The profile at {0} failed to load. The error was: {1}\r\n{2}
diff --git a/src/ConanServerManager/VersionFeed.xml b/src/ConanServerManager/VersionFeed.xml
index 5da92cb6..d810c45a 100644
--- a/src/ConanServerManager/VersionFeed.xml
+++ b/src/ConanServerManager/VersionFeed.xml
@@ -9,8 +9,8 @@
urn:uuid:19B09A66-43F2-4D5F-AF33-5C77D7EA9A6B
- 1.1.58 (1.1.58.5)
- 1.1.58.5
+ 1.1.58 (1.1.58.7)
+ 1.1.58.7
2021-12-16T00:00:00Z
@@ -22,6 +22,7 @@
Global Settings - Discord Bot section - Added a log level droplist.
Global Settings - Discord Bot section - Added a whitelist to allow bots to send commands to the server manager.
Server Settings - Discord Bot section - Added an alias that can be used with the discord command instead of the profile id.
+ Main Window - Added Discord Bot Status and a button to Stop/Start the discord bot.
CHANGE
diff --git a/src/ConanServerManager/VersionFeedBeta.xml b/src/ConanServerManager/VersionFeedBeta.xml
index ab7aed42..2079fb5d 100644
--- a/src/ConanServerManager/VersionFeedBeta.xml
+++ b/src/ConanServerManager/VersionFeedBeta.xml
@@ -7,6 +7,29 @@
2021-12-17T00:00:00Z
+
+ urn:uuid:9A427D82-9904-44F5-8C1E-7C943049869A
+ 1.1.58 (1.1.58.7)
+ 1.1.58.7
+
+ 2021-12-17T00:00:00Z
+
+
+
+ NEW
+
+
+ - Main Window - Added Discord Bot Status and a button to Stop/Start the discord bot.
+
+
+
+
+
+ bletch
+ bletch1971@hotmail.com
+
+
+
urn:uuid:A189668E-DA03-471A-9C5A-7FF2A7264F9C
1.1.58 (1.1.58.6)
diff --git a/src/ConanServerManager/Windows/MainWindow.xaml b/src/ConanServerManager/Windows/MainWindow.xaml
index 8a4cd1d7..c80333e3 100644
--- a/src/ConanServerManager/Windows/MainWindow.xaml
+++ b/src/ConanServerManager/Windows/MainWindow.xaml
@@ -9,6 +9,7 @@
xmlns:cvr="clr-namespace:ServerManagerTool.Common.ValidationRules;assembly=ServerManager.Common"
xmlns:com="clr-namespace:ServerManagerTool.Common;assembly=ServerManager.Common"
xmlns:enum="clr-namespace:ServerManagerTool.Enums"
+ xmlns:bot="clr-namespace:ServerManagerTool.DiscordBot;assembly=ServerManager.Discord"
MinWidth="900" MinHeight="600" Width="1100" Height="900" Left="50" Top="50" WindowState="Normal"
Loaded="MainWindow_Loaded" SizeChanged="MainWindow_SizeChanged" StateChanged="MainWindow_StateChanged" LocationChanged="MainWindow_LocationChanged"
Name="Main" Icon="../Art/favicon.ico" Title="{DynamicResource MainWindow_Title}">
@@ -128,6 +129,7 @@
+
@@ -253,6 +255,61 @@
+
+
+
+
+
+
diff --git a/src/ConanServerManager/Windows/MainWindow.xaml.cs b/src/ConanServerManager/Windows/MainWindow.xaml.cs
index 1e4f9ecc..67cda009 100644
--- a/src/ConanServerManager/Windows/MainWindow.xaml.cs
+++ b/src/ConanServerManager/Windows/MainWindow.xaml.cs
@@ -30,6 +30,9 @@ namespace ServerManagerTool
private readonly GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
private readonly ActionQueue versionChecker;
private readonly ActionQueue scheduledTaskChecker;
+ private readonly ActionQueue discordBotChecker;
+
+ private bool discordBotStateClicked = false;
public static readonly DependencyProperty AppInstanceProperty = DependencyProperty.Register(nameof(AppInstance), typeof(App), typeof(MainWindow), new PropertyMetadata(null));
public static readonly DependencyProperty ConfigProperty = DependencyProperty.Register(nameof(Config), typeof(Config), typeof(MainWindow), new PropertyMetadata(null));
@@ -40,6 +43,8 @@ namespace ServerManagerTool
public static readonly DependencyProperty AutoUpdateStateProperty = DependencyProperty.Register(nameof(AutoUpdateState), typeof(Microsoft.Win32.TaskScheduler.TaskState), typeof(MainWindow), new PropertyMetadata(Microsoft.Win32.TaskScheduler.TaskState.Unknown));
public static readonly DependencyProperty AutoUpdateStateStringProperty = DependencyProperty.Register(nameof(AutoUpdateStateString), typeof(string), typeof(MainWindow), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty AutoUpdateNextRunTimeProperty = DependencyProperty.Register(nameof(AutoUpdateNextRunTime), typeof(string), typeof(MainWindow), new PropertyMetadata(string.Empty));
+ public static readonly DependencyProperty DiscordBotStateProperty = DependencyProperty.Register(nameof(DiscordBotState), typeof(DiscordBot.Enums.BotState), typeof(MainWindow), new PropertyMetadata(DiscordBot.Enums.BotState.Unknown));
+ public static readonly DependencyProperty DiscordBotStateStringProperty = DependencyProperty.Register(nameof(DiscordBotStateString), typeof(string), typeof(MainWindow), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty IsIpValidProperty = DependencyProperty.Register(nameof(IsIpValid), typeof(bool), typeof(MainWindow), new PropertyMetadata(false));
public static readonly DependencyProperty LatestServerManagerVersionProperty = DependencyProperty.Register(nameof(LatestServerManagerVersion), typeof(Version), typeof(MainWindow), new PropertyMetadata(new Version()));
public static readonly DependencyProperty NewServerManagerAvailableProperty = DependencyProperty.Register(nameof(NewServerManagerAvailable), typeof(bool), typeof(MainWindow), new PropertyMetadata(false));
@@ -57,6 +62,7 @@ namespace ServerManagerTool
this.DataContext = this;
this.versionChecker = new ActionQueue();
this.scheduledTaskChecker = new ActionQueue();
+ this.discordBotChecker = new ActionQueue();
IsAdministrator = SecurityUtils.IsAdministrator();
if (!string.IsNullOrWhiteSpace(App.Instance.Title))
@@ -139,6 +145,18 @@ namespace ServerManagerTool
set { SetValue(AutoUpdateNextRunTimeProperty, value); }
}
+ public DiscordBot.Enums.BotState DiscordBotState
+ {
+ get { return (DiscordBot.Enums.BotState)GetValue(DiscordBotStateProperty); }
+ set { SetValue(DiscordBotStateProperty, value); }
+ }
+
+ public string DiscordBotStateString
+ {
+ get { return (string)GetValue(DiscordBotStateStringProperty); }
+ set { SetValue(DiscordBotStateStringProperty, value); }
+ }
+
public bool IsAdministrator
{
get;
@@ -191,6 +209,7 @@ namespace ServerManagerTool
this.versionChecker.PostAction(CheckForUpdates).DoNotWait();
this.scheduledTaskChecker.PostAction(CheckForScheduledTasks).DoNotWait();
+ this.discordBotChecker.PostAction(CheckForDiscordBot).DoNotWait();
}
private void MainWindow_LocationChanged(object sender, EventArgs e)
@@ -254,6 +273,7 @@ namespace ServerManagerTool
this.Title = _globalizer.GetResourceString("MainWindow_Title");
this.scheduledTaskChecker.PostAction(CheckForScheduledTasks).DoNotWait();
+ this.discordBotChecker.PostAction(CheckForDiscordBot).DoNotWait();
}
private void PatchNotes_Click(object sender, RoutedEventArgs e)
@@ -563,6 +583,36 @@ namespace ServerManagerTool
}
}
+ private async void DiscordBotTaskState_Click(object sender, RoutedEventArgs e)
+ {
+ if (discordBotStateClicked)
+ return;
+ discordBotStateClicked = true;
+
+ try
+ {
+ switch (DiscordBotState)
+ {
+ case DiscordBot.Enums.BotState.Stopped:
+ AppInstance.StartDiscordBot();
+ break;
+ case DiscordBot.Enums.BotState.Running:
+ AppInstance.StopDiscordBot();
+ break;
+ }
+
+ await Task.Delay(5000);
+ }
+ catch (Exception)
+ {
+ // Ignore.
+ }
+ finally
+ {
+ discordBotStateClicked = false;
+ }
+ }
+
public ICommand ShowWindowCommand
{
get
@@ -654,8 +704,8 @@ namespace ServerManagerTool
this.AutoBackupState = backupState;
this.AutoUpdateState = updateState;
- this.AutoBackupStateString = GetTaskStateString(AutoBackupState);
- this.AutoUpdateStateString = GetTaskStateString(AutoUpdateState);
+ this.AutoBackupStateString = GetTaskSchedulerStateString(AutoBackupState);
+ this.AutoUpdateStateString = GetTaskSchedulerStateString(AutoUpdateState);
this.AutoBackupNextRunTime = backupnextRunTime == DateTime.MinValue ? string.Empty : $"{_globalizer.GetResourceString("MainWindow_TaskRunTimeLabel")} {backupnextRunTime:G}";
this.AutoUpdateNextRunTime = updatenextRunTime == DateTime.MinValue ? string.Empty : $"{_globalizer.GetResourceString("MainWindow_TaskRunTimeLabel")} {updatenextRunTime:G}";
@@ -672,7 +722,46 @@ namespace ServerManagerTool
this.scheduledTaskChecker.PostAction(CheckForScheduledTasks).DoNotWait();
}
- private string GetTaskStateString(Microsoft.Win32.TaskScheduler.TaskState taskState)
+ private async Task CheckForDiscordBot()
+ {
+ TaskUtils.RunOnUIThreadAsync(() =>
+ {
+ try
+ {
+ var botState = DiscordBot.Enums.BotState.Unknown;
+ if (AppInstance.DiscordBotStarted)
+ {
+ botState = DiscordBot.Enums.BotState.Running;
+ }
+ else
+ {
+ if (Config.DiscordBotEnabled)
+ {
+ botState = DiscordBot.Enums.BotState.Stopped;
+ }
+ else
+ {
+ botState = DiscordBot.Enums.BotState.Disabled;
+ }
+ }
+
+ this.DiscordBotState = botState;
+
+ this.DiscordBotStateString = GetDiscordBotStateString(botState);
+
+ Logger.Info($"{nameof(CheckForDiscordBot)} performed");
+ }
+ catch (Exception)
+ {
+ // Ignore.
+ }
+ }).DoNotWait();
+
+ await Task.Delay(Config.Default.DiscordBotStatusCheckTime * 1 * 1000);
+ this.discordBotChecker.PostAction(CheckForDiscordBot).DoNotWait();
+ }
+
+ private string GetTaskSchedulerStateString(Microsoft.Win32.TaskScheduler.TaskState taskState)
{
switch (taskState)
{
@@ -691,6 +780,21 @@ namespace ServerManagerTool
}
}
+ private string GetDiscordBotStateString(DiscordBot.Enums.BotState botState)
+ {
+ switch (botState)
+ {
+ case DiscordBot.Enums.BotState.Disabled:
+ return _globalizer.GetResourceString("MainWindow_TaskStateDisabledLabel");
+ case DiscordBot.Enums.BotState.Running:
+ return _globalizer.GetResourceString("MainWindow_TaskStateRunningLabel");
+ case DiscordBot.Enums.BotState.Stopped:
+ return _globalizer.GetResourceString("MainWindow_TaskStateStoppedLabel");
+ default:
+ return _globalizer.GetResourceString("MainWindow_TaskStateUnknownLabel");
+ }
+ }
+
private async Task StartServerAsync(Server server)
{
if (server == null || server.Profile == null || server.Runtime == null || server.Runtime.Status != ServerStatus.Stopped)
diff --git a/src/ServerManager.Discord/Enums/BotStatus.cs b/src/ServerManager.Discord/Enums/BotStatus.cs
new file mode 100644
index 00000000..3ae2f730
--- /dev/null
+++ b/src/ServerManager.Discord/Enums/BotStatus.cs
@@ -0,0 +1,10 @@
+namespace ServerManagerTool.DiscordBot.Enums
+{
+ public enum BotState
+ {
+ Unknown,
+ Disabled,
+ Stopped,
+ Running,
+ }
+}
diff --git a/src/ServerManager.Discord/ServerManagerBot.cs b/src/ServerManager.Discord/ServerManagerBot.cs
index b8896223..08652fdb 100644
--- a/src/ServerManager.Discord/ServerManagerBot.cs
+++ b/src/ServerManager.Discord/ServerManagerBot.cs
@@ -30,17 +30,17 @@ namespace ServerManagerTool.DiscordBot
public async Task StartAsync(LogLevel logLevel, string discordToken, string commandPrefix, string dataDirectory, IEnumerable botWhitelist, HandleCommandDelegate handleCommandCallback, HandleTranslationDelegate handleTranslationCallback, CancellationToken token)
{
- if (Started)
- {
- return;
- }
- Started = true;
-
if (string.IsNullOrWhiteSpace(commandPrefix) || string.IsNullOrWhiteSpace(discordToken) || handleTranslationCallback is null || handleCommandCallback is null)
{
return;
}
+ if (Started)
+ {
+ return;
+ }
+
+ Started = true;
Token = token;
var settings = new Dictionary
@@ -121,6 +121,7 @@ namespace ServerManagerTool.DiscordBot
}
await provider?.GetRequiredService().StopAsync();
+ Started = false;
}
}
}