mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
Global Settings - Discord Bot section - Added a whitelist to allow bots to send commands to the server manager.
This commit is contained in:
parent
213a90e072
commit
461221294a
27 changed files with 413 additions and 15 deletions
|
|
@ -849,6 +849,13 @@
|
|||
<setting name="ServerMonitorWindow_Top" serializeAs="String">
|
||||
<value>50</value>
|
||||
</setting>
|
||||
<setting name="DiscordBotWhitelist" serializeAs="Xml">
|
||||
<value>
|
||||
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<string />
|
||||
</ArrayOfString>
|
||||
</value>
|
||||
</setting>
|
||||
</ServerManagerTool.Config>
|
||||
</userSettings>
|
||||
</configuration>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ using ServerManagerTool.Plugin.Common;
|
|||
using ServerManagerTool.Utils;
|
||||
using ServerManagerTool.Windows;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
|
@ -493,7 +494,13 @@ namespace ServerManagerTool
|
|||
|
||||
Task discordTask = Task.Run(async () =>
|
||||
{
|
||||
await ServerManagerBotFactory.GetServerManagerBot()?.StartAsync(Config.Default.DiscordBotToken, Config.Default.DiscordBotPrefix, Config.Default.DataDir, DiscordBotHelper.HandleDiscordCommand, DiscordBotHelper.HandleTranslation, _tokenSource.Token);
|
||||
var discordWhiteList = new List<string>();
|
||||
if (Config.Default.DiscordBotWhitelist != null)
|
||||
{
|
||||
discordWhiteList.AddRange(Config.Default.DiscordBotWhitelist.Cast<string>());
|
||||
}
|
||||
|
||||
await ServerManagerBotFactory.GetServerManagerBot()?.StartAsync(Config.Default.DiscordBotToken, Config.Default.DiscordBotPrefix, Config.Default.DataDir, discordWhiteList, DiscordBotHelper.HandleDiscordCommand, DiscordBotHelper.HandleTranslation, _tokenSource.Token);
|
||||
}, _tokenSource.Token)
|
||||
.ContinueWith(t => {
|
||||
var message = t.Exception.InnerException is null ? t.Exception.Message : t.Exception.InnerException.Message;
|
||||
|
|
|
|||
14
src/ARKServerManager/Config.Designer.cs
generated
14
src/ARKServerManager/Config.Designer.cs
generated
|
|
@ -2986,5 +2986,19 @@ namespace ServerManagerTool {
|
|||
this["ServerMonitorWindow_Top"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<ArrayOfString xmlns:xsd=\"http://www.w3." +
|
||||
"org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n <s" +
|
||||
"tring />\r\n</ArrayOfString>")]
|
||||
public global::System.Collections.Specialized.StringCollection DiscordBotWhitelist {
|
||||
get {
|
||||
return ((global::System.Collections.Specialized.StringCollection)(this["DiscordBotWhitelist"]));
|
||||
}
|
||||
set {
|
||||
this["DiscordBotWhitelist"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -824,5 +824,11 @@
|
|||
<Setting Name="ServerMonitorWindow_Top" Type="System.Double" Scope="User">
|
||||
<Value Profile="(Default)">50</Value>
|
||||
</Setting>
|
||||
<Setting Name="DiscordBotWhitelist" Type="System.Collections.Specialized.StringCollection" Scope="User">
|
||||
<Value Profile="(Default)"><?xml version="1.0" encoding="utf-16"?>
|
||||
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<string />
|
||||
</ArrayOfString></Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
|
|
@ -624,6 +624,12 @@
|
|||
<sys:String x:Key="GlobalSettings_DiscordBotPrefixTooltip">The prefix that must be used when sending a command via discord.</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DiscordBotApplyButtonLabel">Get Token...</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DiscordBotHelpButtonLabel">Help...</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DiscordBotWhitelistLabel">Bot Whitelist</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DiscordBotWhitelistIdLabel">Bot ID</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DiscordBotWhitelistIdTooltip">The id of the bot to whitelist.</sys:String>
|
||||
<sys:String x:Key="ServerSettings_AddDiscordBotWhitelistTooltip">Add Whitelist</sys:String>
|
||||
<sys:String x:Key="ServerSettings_ClearDiscordBotWhitelistTooltip">Clear Whitelists</sys:String>
|
||||
<sys:String x:Key="ServerSettings_RemoveDiscordBotWhitelistTooltip">Delete Whitelist</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DiscordBotAllowBackupTooltip">If enabled, the backup command can be sent from discord.</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DiscordBotAllowRestartTooltip">If enabled, the restart command can be sent from discord.</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DiscordBotAllowShutdownTooltip">If enabled, the shutdown command can be sent from discord.</sys:String>
|
||||
|
|
|
|||
|
|
@ -591,6 +591,7 @@
|
|||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" MinWidth="60"/>
|
||||
|
|
@ -625,6 +626,55 @@
|
|||
<CheckBox Grid.Row="4" Grid.Column="1" Margin="0,5,0,5" IsChecked="{Binding Config.AllowDiscordRestart}" Content="{DynamicResource ServerSettings_AllowDiscordRestartLabel}" HorizontalAlignment="Left" ToolTip="{DynamicResource GlobalSettings_DiscordBotAllowRestartTooltip}"/>
|
||||
<CheckBox Grid.Row="4" Grid.Column="4" Margin="0,5,0,5" IsChecked="{Binding Config.AllowDiscordShutdown}" Content="{DynamicResource ServerSettings_AllowDiscordShutdownLabel}" HorizontalAlignment="Left" ToolTip="{DynamicResource GlobalSettings_DiscordBotAllowShutdownTooltip}"/>
|
||||
<CheckBox Grid.Row="4" Grid.Column="7" Margin="0,5,0,5" IsChecked="{Binding Config.AllowDiscordStop}" Content="{DynamicResource ServerSettings_AllowDiscordStopLabel}" HorizontalAlignment="Left" ToolTip="{DynamicResource GlobalSettings_DiscordBotAllowStopTooltip}"/>
|
||||
|
||||
<GroupBox Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="4" HorizontalAlignment="Stretch" MinHeight="200">
|
||||
<GroupBox.Header>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label Content="{DynamicResource GlobalSettings_DiscordBotWhitelistLabel}"/>
|
||||
<Button Click="AddDiscordBotWhitelist_Click" Margin="20,0,0,0" ToolTip="{DynamicResource ServerSettings_AddDiscordBotWhitelistTooltip}" Style="{StaticResource ButtonStyle1}">
|
||||
<Image Source="../Art/Add.ico"/>
|
||||
</Button>
|
||||
<Button Click="ClearDiscordBotWhitelists_Click" Margin="5,0,0,0" ToolTip="{DynamicResource ServerSettings_ClearDiscordBotWhitelistTooltip}" Style="{StaticResource ButtonStyle1}">
|
||||
<Image Source="../Art/Delete.ico"/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</GroupBox.Header>
|
||||
|
||||
<DataGrid x:Name="DiscordBotWhitelistGrid" ItemsSource="{Binding DiscordBotWhitelist, ElementName=GlobalSettings}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserSortColumns="true" SelectionMode="Single" CanUserResizeColumns="False" CanUserResizeRows="False" RowHeaderWidth="25" IsReadOnly="False">
|
||||
<DataGrid.Resources>
|
||||
<Style TargetType="{x:Type DataGridRow}">
|
||||
<Style.Resources>
|
||||
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{x:Static SystemColors.HighlightColor}"/>
|
||||
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="{x:Static SystemColors.HighlightTextColor}"/>
|
||||
</Style.Resources>
|
||||
</Style>
|
||||
</DataGrid.Resources>
|
||||
|
||||
<DataGrid.HorizontalGridLinesBrush>
|
||||
<SolidColorBrush Color="#FFB4B4B4"/>
|
||||
</DataGrid.HorizontalGridLinesBrush>
|
||||
<DataGrid.VerticalGridLinesBrush>
|
||||
<SolidColorBrush Color="#FFB4B4B4"/>
|
||||
</DataGrid.VerticalGridLinesBrush>
|
||||
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Width="*" Binding="{Binding BotId}">
|
||||
<DataGridTextColumn.Header>
|
||||
<TextBlock Text="{DynamicResource GlobalSettings_DiscordBotWhitelistIdLabel}" />
|
||||
</DataGridTextColumn.Header>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTemplateColumn Width="30" CanUserReorder="False" IsReadOnly="True">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Button Width="22" Height="22" Margin="0" IsTabStop="False" HorizontalAlignment="Center" VerticalAlignment="Center" Click="RemoveDiscordBotWhitelist_Click" ToolTip="{DynamicResource ServerSettings_RemoveDiscordBotWhitelistTooltip}">
|
||||
<Image Source="../Art/Delete.ico"/>
|
||||
</Button>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,16 @@ using ServerManagerTool.Common.Lib;
|
|||
using ServerManagerTool.Common.Model;
|
||||
using ServerManagerTool.Common.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Xml;
|
||||
using WPFSharp.Globalizer;
|
||||
|
|
@ -24,12 +27,13 @@ namespace ServerManagerTool
|
|||
public partial class GlobalSettingsControl : UserControl
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
|
||||
private readonly GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
|
||||
|
||||
public static readonly DependencyProperty IsAdministratorProperty = DependencyProperty.Register(nameof(IsAdministrator), typeof(bool), typeof(GlobalSettingsControl), new PropertyMetadata(false));
|
||||
public static readonly DependencyProperty ConfigProperty = DependencyProperty.Register(nameof(Config), typeof(Config), typeof(GlobalSettingsControl), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty CommonConfigProperty = DependencyProperty.Register(nameof(CommonConfig), typeof(CommonConfig), typeof(GlobalSettingsControl), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty WindowStatesProperty = DependencyProperty.Register(nameof(WindowStates), typeof(ComboBoxItemList), typeof(GlobalSettingsControl), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty DiscordBotWhitelistProperty = DependencyProperty.Register(nameof(DiscordBotWhitelist), typeof(List<DiscordBotWhitelist>), typeof(GlobalSettingsControl), new PropertyMetadata(null));
|
||||
|
||||
public GlobalSettingsControl()
|
||||
{
|
||||
|
|
@ -41,6 +45,15 @@ namespace ServerManagerTool
|
|||
|
||||
PopulateWindowsStatesComboBox();
|
||||
|
||||
DiscordBotWhitelist = new List<DiscordBotWhitelist>();
|
||||
if (Config.DiscordBotWhitelist != null)
|
||||
{
|
||||
foreach (var item in Config.DiscordBotWhitelist)
|
||||
{
|
||||
DiscordBotWhitelist.Add(new DiscordBotWhitelist() { BotId = item });
|
||||
}
|
||||
}
|
||||
|
||||
InitializeComponent();
|
||||
WindowUtils.RemoveDefaultResourceDictionary(this, Config.Default.DefaultGlobalizationFile);
|
||||
|
||||
|
|
@ -77,6 +90,21 @@ namespace ServerManagerTool
|
|||
set { SetValue(WindowStatesProperty, value); }
|
||||
}
|
||||
|
||||
public List<DiscordBotWhitelist> DiscordBotWhitelist
|
||||
{
|
||||
get { return (List<DiscordBotWhitelist>)GetValue(DiscordBotWhitelistProperty); }
|
||||
set { SetValue(DiscordBotWhitelistProperty, value); }
|
||||
}
|
||||
|
||||
public void ApplyChangesToConfig()
|
||||
{
|
||||
if (Config.DiscordBotWhitelist is null)
|
||||
Config.DiscordBotWhitelist = new System.Collections.Specialized.StringCollection();
|
||||
|
||||
Config.DiscordBotWhitelist.Clear();
|
||||
Config.DiscordBotWhitelist.AddRange(DiscordBotWhitelist.Select(i => i.BotId).ToArray());
|
||||
}
|
||||
|
||||
private string GetDeployedVersion()
|
||||
{
|
||||
XmlDocument xmlDoc = new XmlDocument();
|
||||
|
|
@ -462,5 +490,35 @@ namespace ServerManagerTool
|
|||
this.WindowStateComboBox.SelectedValue = selectedValue;
|
||||
}
|
||||
}
|
||||
|
||||
#region Discord Bot Whitelist
|
||||
private void AddDiscordBotWhitelist_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
DiscordBotWhitelist.Add(new DiscordBotWhitelist());
|
||||
|
||||
CollectionViewSource.GetDefaultView(DiscordBotWhitelistGrid.ItemsSource).Refresh();
|
||||
}
|
||||
|
||||
private void ClearDiscordBotWhitelists_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (MessageBox.Show(_globalizer.GetResourceString("ServerSettings_ClearLabel"), _globalizer.GetResourceString("ServerSettings_ClearTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
||||
return;
|
||||
|
||||
DiscordBotWhitelist.Clear();
|
||||
|
||||
CollectionViewSource.GetDefaultView(DiscordBotWhitelistGrid.ItemsSource).Refresh();
|
||||
}
|
||||
|
||||
private void RemoveDiscordBotWhitelist_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (MessageBox.Show(_globalizer.GetResourceString("ServerSettings_DeleteLabel"), _globalizer.GetResourceString("ServerSettings_DeleteTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
||||
return;
|
||||
|
||||
var item = ((DiscordBotWhitelist)((Button)e.Source).DataContext);
|
||||
DiscordBotWhitelist.Remove(item);
|
||||
|
||||
CollectionViewSource.GetDefaultView(DiscordBotWhitelistGrid.ItemsSource).Refresh();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,13 +9,18 @@
|
|||
|
||||
<entry>
|
||||
<id>urn:uuid:3E33DCB2-ECFE-4489-B1A4-56F5D386F9DC</id>
|
||||
<title>1.1.413 (1.1.413.1)</title>
|
||||
<summary>1.1.413.1</summary>
|
||||
<title>1.1.413 (1.1.413.2)</title>
|
||||
<summary>1.1.413.2</summary>
|
||||
<link href="" />
|
||||
<updated>2021-12-16T00:00:00Z</updated>
|
||||
<content type="xhtml">
|
||||
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
|
||||
<p>
|
||||
<u style="font-size: .9em;">NEW</u>
|
||||
<br/>
|
||||
<ul>
|
||||
<li>Global Settings - Discord Bot section - Added a whitelist to allow bots to send commands to the server manager.</li>
|
||||
</ul>
|
||||
<u style="font-size: .9em;">CHANGE</u>
|
||||
<br/>
|
||||
<ul>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,29 @@
|
|||
<link href="http://arkservermanager.freeforums.net/" />
|
||||
<updated>2021-12-16T00:00:00Z</updated>
|
||||
|
||||
<entry>
|
||||
<id>urn:uuid:8958A494-DE13-4F6F-ACA2-10026D5FB8A9</id>
|
||||
<title>1.1.413 (1.1.413.2)</title>
|
||||
<summary>1.1.413.2</summary>
|
||||
<link href="" />
|
||||
<updated>2021-12-16T00:00:00Z</updated>
|
||||
<content type="xhtml">
|
||||
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
|
||||
<p>
|
||||
<u style="font-size: .9em;">NEW</u>
|
||||
<br/>
|
||||
<ul>
|
||||
<li>Global Settings - Discord Bot section - Added a whitelist to allow bots to send commands to the server manager.</li>
|
||||
</ul>
|
||||
</p>
|
||||
</div>
|
||||
</content>
|
||||
<author>
|
||||
<name>bletch</name>
|
||||
<email>bletch1971@hotmail.com</email>
|
||||
</author>
|
||||
</entry>
|
||||
|
||||
<entry>
|
||||
<id>urn:uuid:3E33DCB2-ECFE-4489-B1A4-56F5D386F9DC</id>
|
||||
<title>1.1.413 (1.1.413.1)</title>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,6 @@
|
|||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<local:GlobalSettingsControl HorizontalAlignment="Stretch" VerticalContentAlignment="Stretch" Background="{StaticResource BeigeGradient}"/>
|
||||
<local:GlobalSettingsControl x:Name="globalSettingsControl" HorizontalAlignment="Stretch" VerticalContentAlignment="Stretch" Background="{StaticResource BeigeGradient}"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ namespace ServerManagerTool
|
|||
|
||||
protected override void OnClosed(EventArgs e)
|
||||
{
|
||||
globalSettingsControl.ApplyChangesToConfig();
|
||||
|
||||
if (SecurityUtils.IsAdministrator())
|
||||
{
|
||||
// check if the Auto Update has been enabled.
|
||||
|
|
|
|||
|
|
@ -615,6 +615,13 @@
|
|||
<setting name="ServerMonitorWindow_Top" serializeAs="String">
|
||||
<value>50</value>
|
||||
</setting>
|
||||
<setting name="DiscordBotWhitelist" serializeAs="Xml">
|
||||
<value>
|
||||
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<string />
|
||||
</ArrayOfString>
|
||||
</value>
|
||||
</setting>
|
||||
</ServerManagerTool.Config>
|
||||
</userSettings>
|
||||
</configuration>
|
||||
|
|
@ -10,6 +10,7 @@ using ServerManagerTool.Plugin.Common;
|
|||
using ServerManagerTool.Utils;
|
||||
using ServerManagerTool.Windows;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
|
@ -474,7 +475,13 @@ namespace ServerManagerTool
|
|||
|
||||
Task discordTask = Task.Run(async () =>
|
||||
{
|
||||
await ServerManagerBotFactory.GetServerManagerBot()?.StartAsync(Config.Default.DiscordBotToken,Config.Default.DiscordBotPrefix, Config.Default.DataPath, DiscordBotHelper.HandleDiscordCommand, DiscordBotHelper.HandleTranslation, _tokenSource.Token);
|
||||
var discordWhiteList = new List<string>();
|
||||
if (Config.Default.DiscordBotWhitelist != null)
|
||||
{
|
||||
discordWhiteList.AddRange(Config.Default.DiscordBotWhitelist.Cast<string>());
|
||||
}
|
||||
|
||||
await ServerManagerBotFactory.GetServerManagerBot()?.StartAsync(Config.Default.DiscordBotToken,Config.Default.DiscordBotPrefix, Config.Default.DataPath, discordWhiteList, DiscordBotHelper.HandleDiscordCommand, DiscordBotHelper.HandleTranslation, _tokenSource.Token);
|
||||
}, _tokenSource.Token)
|
||||
.ContinueWith(t => {
|
||||
var message = t.Exception.InnerException is null ? t.Exception.Message : t.Exception.InnerException.Message;
|
||||
|
|
|
|||
14
src/ConanServerManager/Config.Designer.cs
generated
14
src/ConanServerManager/Config.Designer.cs
generated
|
|
@ -2139,5 +2139,19 @@ namespace ServerManagerTool {
|
|||
this["ServerMonitorWindow_Top"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<ArrayOfString xmlns:xsd=\"http://www.w3." +
|
||||
"org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n <s" +
|
||||
"tring />\r\n</ArrayOfString>")]
|
||||
public global::System.Collections.Specialized.StringCollection DiscordBotWhitelist {
|
||||
get {
|
||||
return ((global::System.Collections.Specialized.StringCollection)(this["DiscordBotWhitelist"]));
|
||||
}
|
||||
set {
|
||||
this["DiscordBotWhitelist"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -590,5 +590,11 @@
|
|||
<Setting Name="ServerMonitorWindow_Top" Type="System.Double" Scope="User">
|
||||
<Value Profile="(Default)">50</Value>
|
||||
</Setting>
|
||||
<Setting Name="DiscordBotWhitelist" Type="System.Collections.Specialized.StringCollection" Scope="User">
|
||||
<Value Profile="(Default)"><?xml version="1.0" encoding="utf-16"?>
|
||||
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<string />
|
||||
</ArrayOfString></Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
|
|
@ -782,6 +782,12 @@
|
|||
<sys:String x:Key="GlobalSettings_DiscordBotPrefixTooltip">The prefix that must be used when sending a command via discord.</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DiscordBotApplyButtonLabel">Get Token...</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DiscordBotHelpButtonLabel">Help...</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DiscordBotWhitelistLabel">Bot Whitelist</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DiscordBotWhitelistIdLabel">Bot ID</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DiscordBotWhitelistIdTooltip">The id of the bot to whitelist.</sys:String>
|
||||
<sys:String x:Key="ServerSettings_AddDiscordBotWhitelistTooltip">Add Whitelist</sys:String>
|
||||
<sys:String x:Key="ServerSettings_ClearDiscordBotWhitelistTooltip">Clear Whitelists</sys:String>
|
||||
<sys:String x:Key="ServerSettings_RemoveDiscordBotWhitelistTooltip">Delete Whitelist</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DiscordBotAllowBackupTooltip">If enabled, the backup command can be sent from discord.</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DiscordBotAllowRestartTooltip">If enabled, the restart command can be sent from discord.</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DiscordBotAllowShutdownTooltip">If enabled, the shutdown command can be sent from discord.</sys:String>
|
||||
|
|
|
|||
|
|
@ -539,6 +539,7 @@
|
|||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" MinWidth="60"/>
|
||||
|
|
@ -573,6 +574,55 @@
|
|||
<CheckBox Grid.Row="4" Grid.Column="1" Margin="0,5,0,5" IsChecked="{Binding Config.AllowDiscordRestart}" Content="{DynamicResource ServerSettings_AllowDiscordRestartLabel}" HorizontalAlignment="Left" ToolTip="{DynamicResource GlobalSettings_DiscordBotAllowRestartTooltip}"/>
|
||||
<CheckBox Grid.Row="4" Grid.Column="4" Margin="0,5,0,5" IsChecked="{Binding Config.AllowDiscordShutdown}" Content="{DynamicResource ServerSettings_AllowDiscordShutdownLabel}" HorizontalAlignment="Left" ToolTip="{DynamicResource GlobalSettings_DiscordBotAllowShutdownTooltip}"/>
|
||||
<CheckBox Grid.Row="4" Grid.Column="7" Margin="0,5,0,5" IsChecked="{Binding Config.AllowDiscordStop}" Content="{DynamicResource ServerSettings_AllowDiscordStopLabel}" HorizontalAlignment="Left" ToolTip="{DynamicResource GlobalSettings_DiscordBotAllowStopTooltip}"/>
|
||||
|
||||
<GroupBox Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="4" HorizontalAlignment="Stretch" MinHeight="200">
|
||||
<GroupBox.Header>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label Content="{DynamicResource GlobalSettings_DiscordBotWhitelistLabel}"/>
|
||||
<Button Click="AddDiscordBotWhitelist_Click" Margin="20,0,0,0" ToolTip="{DynamicResource ServerSettings_AddDiscordBotWhitelistTooltip}" Style="{StaticResource ButtonStyle1}">
|
||||
<Image Source="../Art/Add.ico"/>
|
||||
</Button>
|
||||
<Button Click="ClearDiscordBotWhitelists_Click" Margin="5,0,0,0" ToolTip="{DynamicResource ServerSettings_ClearDiscordBotWhitelistTooltip}" Style="{StaticResource ButtonStyle1}">
|
||||
<Image Source="../Art/Delete.ico"/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</GroupBox.Header>
|
||||
|
||||
<DataGrid x:Name="DiscordBotWhitelistGrid" ItemsSource="{Binding DiscordBotWhitelist, ElementName=GlobalSettings}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserSortColumns="true" SelectionMode="Single" CanUserResizeColumns="False" CanUserResizeRows="False" RowHeaderWidth="25" IsReadOnly="False">
|
||||
<DataGrid.Resources>
|
||||
<Style TargetType="{x:Type DataGridRow}">
|
||||
<Style.Resources>
|
||||
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{x:Static SystemColors.HighlightColor}"/>
|
||||
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="{x:Static SystemColors.HighlightTextColor}"/>
|
||||
</Style.Resources>
|
||||
</Style>
|
||||
</DataGrid.Resources>
|
||||
|
||||
<DataGrid.HorizontalGridLinesBrush>
|
||||
<SolidColorBrush Color="#FFB4B4B4"/>
|
||||
</DataGrid.HorizontalGridLinesBrush>
|
||||
<DataGrid.VerticalGridLinesBrush>
|
||||
<SolidColorBrush Color="#FFB4B4B4"/>
|
||||
</DataGrid.VerticalGridLinesBrush>
|
||||
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Width="*" Binding="{Binding BotId}">
|
||||
<DataGridTextColumn.Header>
|
||||
<TextBlock Text="{DynamicResource GlobalSettings_DiscordBotWhitelistIdLabel}" />
|
||||
</DataGridTextColumn.Header>
|
||||
</DataGridTextColumn>
|
||||
<DataGridTemplateColumn Width="30" CanUserReorder="False" IsReadOnly="True">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Button Width="22" Height="22" Margin="0" IsTabStop="False" HorizontalAlignment="Center" VerticalAlignment="Center" Click="RemoveDiscordBotWhitelist_Click" ToolTip="{DynamicResource ServerSettings_RemoveDiscordBotWhitelistTooltip}">
|
||||
<Image Source="../Art/Delete.ico"/>
|
||||
</Button>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,16 @@ using ServerManagerTool.Common.Lib;
|
|||
using ServerManagerTool.Common.Model;
|
||||
using ServerManagerTool.Common.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Xml;
|
||||
using WPFSharp.Globalizer;
|
||||
|
|
@ -24,11 +27,12 @@ namespace ServerManagerTool
|
|||
public partial class GlobalSettingsControl : UserControl
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
|
||||
private readonly GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
|
||||
|
||||
public static readonly DependencyProperty AppInstanceProperty = DependencyProperty.Register(nameof(AppInstance), typeof(App), typeof(GlobalSettingsControl), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty IsAdministratorProperty = DependencyProperty.Register(nameof(IsAdministrator), typeof(bool), typeof(GlobalSettingsControl), new PropertyMetadata(false));
|
||||
public static readonly DependencyProperty WindowStatesProperty = DependencyProperty.Register(nameof(WindowStates), typeof(ComboBoxItemList), typeof(GlobalSettingsControl), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty DiscordBotWhitelistProperty = DependencyProperty.Register(nameof(DiscordBotWhitelist), typeof(List<DiscordBotWhitelist>), typeof(GlobalSettingsControl), new PropertyMetadata(null));
|
||||
|
||||
public GlobalSettingsControl()
|
||||
{
|
||||
|
|
@ -40,6 +44,15 @@ namespace ServerManagerTool
|
|||
|
||||
PopulateWindowsStatesComboBox();
|
||||
|
||||
DiscordBotWhitelist = new List<DiscordBotWhitelist>();
|
||||
if (Config.DiscordBotWhitelist != null)
|
||||
{
|
||||
foreach (var item in Config.DiscordBotWhitelist)
|
||||
{
|
||||
DiscordBotWhitelist.Add(new DiscordBotWhitelist() { BotId = item });
|
||||
}
|
||||
}
|
||||
|
||||
InitializeComponent();
|
||||
WindowUtils.RemoveDefaultResourceDictionary(this, Config.Default.DefaultGlobalizationFile);
|
||||
|
||||
|
|
@ -82,6 +95,21 @@ namespace ServerManagerTool
|
|||
set;
|
||||
}
|
||||
|
||||
public List<DiscordBotWhitelist> DiscordBotWhitelist
|
||||
{
|
||||
get { return (List<DiscordBotWhitelist>)GetValue(DiscordBotWhitelistProperty); }
|
||||
set { SetValue(DiscordBotWhitelistProperty, value); }
|
||||
}
|
||||
|
||||
public void ApplyChangesToConfig()
|
||||
{
|
||||
if (Config.DiscordBotWhitelist is null)
|
||||
Config.DiscordBotWhitelist = new System.Collections.Specialized.StringCollection();
|
||||
|
||||
Config.DiscordBotWhitelist.Clear();
|
||||
Config.DiscordBotWhitelist.AddRange(DiscordBotWhitelist.Select(i => i.BotId).ToArray());
|
||||
}
|
||||
|
||||
private string GetDeployedVersion()
|
||||
{
|
||||
XmlDocument xmlDoc = new XmlDocument();
|
||||
|
|
@ -471,5 +499,35 @@ namespace ServerManagerTool
|
|||
this.WindowStateComboBox.SelectedValue = selectedValue;
|
||||
}
|
||||
}
|
||||
|
||||
#region Discord Bot Whitelist
|
||||
private void AddDiscordBotWhitelist_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
DiscordBotWhitelist.Add(new DiscordBotWhitelist());
|
||||
|
||||
CollectionViewSource.GetDefaultView(DiscordBotWhitelistGrid.ItemsSource).Refresh();
|
||||
}
|
||||
|
||||
private void ClearDiscordBotWhitelists_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (MessageBox.Show(_globalizer.GetResourceString("ServerSettings_ClearLabel"), _globalizer.GetResourceString("ServerSettings_ClearTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
||||
return;
|
||||
|
||||
DiscordBotWhitelist.Clear();
|
||||
|
||||
CollectionViewSource.GetDefaultView(DiscordBotWhitelistGrid.ItemsSource).Refresh();
|
||||
}
|
||||
|
||||
private void RemoveDiscordBotWhitelist_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (MessageBox.Show(_globalizer.GetResourceString("ServerSettings_DeleteLabel"), _globalizer.GetResourceString("ServerSettings_DeleteTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
||||
return;
|
||||
|
||||
var item = ((DiscordBotWhitelist)((Button)e.Source).DataContext);
|
||||
DiscordBotWhitelist.Remove(item);
|
||||
|
||||
CollectionViewSource.GetDefaultView(DiscordBotWhitelistGrid.ItemsSource).Refresh();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,13 +9,18 @@
|
|||
|
||||
<entry>
|
||||
<id>urn:uuid:19B09A66-43F2-4D5F-AF33-5C77D7EA9A6B</id>
|
||||
<title>1.1.58 (1.1.58.1)</title>
|
||||
<summary>1.1.58.1</summary>
|
||||
<title>1.1.58 (1.1.58.2)</title>
|
||||
<summary>1.1.58.2</summary>
|
||||
<link href="" />
|
||||
<updated>2021-12-16T00:00:00Z</updated>
|
||||
<content type="xhtml">
|
||||
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
|
||||
<p>
|
||||
<u style="font-size: .9em;">NEW</u>
|
||||
<br/>
|
||||
<ul>
|
||||
<li>Global Settings - Discord Bot section - Added a whitelist to allow bots to send commands to the server manager.</li>
|
||||
</ul>
|
||||
<u style="font-size: .9em;">CHANGE</u>
|
||||
<br/>
|
||||
<ul>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,29 @@
|
|||
<link href="http://servermanagers.freeforums.net/" />
|
||||
<updated>2021-12-16T00:00:00Z</updated>
|
||||
|
||||
<entry>
|
||||
<id>urn:uuid:C566D9D2-3566-46DF-8AD4-39F5FC0FFEF2</id>
|
||||
<title>1.1.58 (1.1.58.2)</title>
|
||||
<summary>1.1.58.2</summary>
|
||||
<link href="" />
|
||||
<updated>2021-12-16T00:00:00Z</updated>
|
||||
<content type="xhtml">
|
||||
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
|
||||
<p>
|
||||
<u style="font-size: .9em;">NEW</u>
|
||||
<br/>
|
||||
<ul>
|
||||
<li>Global Settings - Discord Bot section - Added a whitelist to allow bots to send commands to the server manager.</li>
|
||||
</ul>
|
||||
</p>
|
||||
</div>
|
||||
</content>
|
||||
<author>
|
||||
<name>bletch</name>
|
||||
<email>bletch1971@hotmail.com</email>
|
||||
</author>
|
||||
</entry>
|
||||
|
||||
<entry>
|
||||
<id>urn:uuid:19B09A66-43F2-4D5F-AF33-5C77D7EA9A6B</id>
|
||||
<title>1.1.58 (1.1.58.1)</title>
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ namespace ServerManagerTool
|
|||
|
||||
protected override void OnClosed(EventArgs e)
|
||||
{
|
||||
globalSettingsControl.ApplyChangesToConfig();
|
||||
|
||||
if (SecurityUtils.IsAdministrator())
|
||||
{
|
||||
// check if the Auto Update has been enabled.
|
||||
|
|
|
|||
15
src/ServerManager.Common/Model/DiscordBotWhitelist.cs
Normal file
15
src/ServerManager.Common/Model/DiscordBotWhitelist.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using System.Windows;
|
||||
|
||||
namespace ServerManagerTool.Common.Model
|
||||
{
|
||||
public class DiscordBotWhitelist : DependencyObject
|
||||
{
|
||||
public static readonly DependencyProperty BotIdProperty = DependencyProperty.Register(nameof(BotId), typeof(string), typeof(DiscordBotWhitelist), new PropertyMetadata(""));
|
||||
|
||||
public string BotId
|
||||
{
|
||||
get { return (string)GetValue(BotIdProperty); }
|
||||
set { SetValue(BotIdProperty, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using ServerManagerTool.DiscordBot.Delegates;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
|
@ -8,6 +9,6 @@ namespace ServerManagerTool.DiscordBot.Interfaces
|
|||
{
|
||||
CancellationToken Token { get; }
|
||||
|
||||
Task StartAsync(string discordToken, string commandPrefix, string dataDirectory, HandleCommandDelegate handleCommandCallback, HandleTranslationDelegate handleTranslationCallback, CancellationToken token);
|
||||
Task StartAsync(string discordToken, string commandPrefix, string dataDirectory, IEnumerable<string> botWhitelist, HandleCommandDelegate handleCommandCallback, HandleTranslationDelegate handleTranslationCallback, CancellationToken token);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
7
src/ServerManager.Discord/Models/DiscordBotWhitelist.cs
Normal file
7
src/ServerManager.Discord/Models/DiscordBotWhitelist.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
namespace ServerManagerTool.DiscordBot.Models
|
||||
{
|
||||
public class DiscordBotWhitelist
|
||||
{
|
||||
public string BotId { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace ServerManagerTool.DiscordBot.Models
|
||||
{
|
||||
public class DiscordBotWhitelistConfig
|
||||
{
|
||||
public List<DiscordBotWhitelist> DiscordBotWhitelists { get; set; } = new List<DiscordBotWhitelist>();
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ using Microsoft.Extensions.Configuration;
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ServerManagerTool.DiscordBot.Delegates;
|
||||
using ServerManagerTool.DiscordBot.Interfaces;
|
||||
using ServerManagerTool.DiscordBot.Models;
|
||||
using ServerManagerTool.DiscordBot.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -27,7 +28,7 @@ namespace ServerManagerTool.DiscordBot
|
|||
public CancellationToken Token { get; private set; }
|
||||
public bool Started { get; private set; }
|
||||
|
||||
public async Task StartAsync(string discordToken, string commandPrefix, string dataDirectory, HandleCommandDelegate handleCommandCallback, HandleTranslationDelegate handleTranslationCallback, CancellationToken token)
|
||||
public async Task StartAsync(string discordToken, string commandPrefix, string dataDirectory, IEnumerable<string> botWhitelist, HandleCommandDelegate handleCommandCallback, HandleTranslationDelegate handleTranslationCallback, CancellationToken token)
|
||||
{
|
||||
if (Started)
|
||||
{
|
||||
|
|
@ -91,6 +92,11 @@ namespace ServerManagerTool.DiscordBot
|
|||
#endif
|
||||
};
|
||||
|
||||
var discordBotWhitelistConfig = new DiscordBotWhitelistConfig
|
||||
{
|
||||
DiscordBotWhitelists = new List<DiscordBotWhitelist> ( botWhitelist.Select(i => new DiscordBotWhitelist { BotId = i }) )
|
||||
};
|
||||
|
||||
// Build the service provider
|
||||
var services = new ServiceCollection()
|
||||
// Add the discord client to the service provider
|
||||
|
|
@ -105,6 +111,7 @@ namespace ServerManagerTool.DiscordBot
|
|||
.AddSingleton<ShutdownService>()
|
||||
.AddSingleton<Random>()
|
||||
.AddSingleton(config)
|
||||
.AddSingleton(discordBotWhitelistConfig)
|
||||
.AddSingleton(handleCommandCallback)
|
||||
.AddSingleton(handleTranslationCallback)
|
||||
.AddSingleton<IServerManagerBot>(this);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using ServerManagerTool.DiscordBot.Models;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServerManagerTool.DiscordBot.Services
|
||||
|
|
@ -12,14 +14,15 @@ namespace ServerManagerTool.DiscordBot.Services
|
|||
private readonly CommandService _commands;
|
||||
private readonly IConfigurationRoot _config;
|
||||
private readonly IServiceProvider _provider;
|
||||
private readonly DiscordBotWhitelistConfig _botWhitelist;
|
||||
|
||||
public CommandHandlerService(DiscordSocketClient discord, CommandService commands, IConfigurationRoot config, IServiceProvider provider)
|
||||
public CommandHandlerService(DiscordSocketClient discord, CommandService commands, IConfigurationRoot config, IServiceProvider provider, DiscordBotWhitelistConfig botWhitelist)
|
||||
{
|
||||
_discord = discord;
|
||||
_commands = commands;
|
||||
_config = config;
|
||||
_provider = provider;
|
||||
|
||||
_botWhitelist = botWhitelist ?? new DiscordBotWhitelistConfig();
|
||||
_discord.MessageReceived += OnMessageReceivedAsync;
|
||||
}
|
||||
|
||||
|
|
@ -38,8 +41,8 @@ namespace ServerManagerTool.DiscordBot.Services
|
|||
return;
|
||||
}
|
||||
|
||||
//Tell bot to ignore itself.
|
||||
if (msg.Author.IsBot)
|
||||
// Tell bot to ignore itself, unless on the whitelist
|
||||
if (msg.Author.IsBot && !_botWhitelist.DiscordBotWhitelists.Any(b => b.BotId.Equals(msg.Author.Id)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue