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
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue