Added a log level droplist

This commit is contained in:
Brett Hewitson 2021-12-16 23:08:31 +10:00
parent 708031dcbb
commit 430bfe7bbb
21 changed files with 224 additions and 59 deletions

View file

@ -580,7 +580,7 @@
<value>False</value>
</setting>
<setting name="DiscordBotPrefix" serializeAs="String">
<value>csm</value>
<value>csm!</value>
</setting>
<setting name="DiscordBotToken" serializeAs="String">
<value />
@ -617,14 +617,15 @@
</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>
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
</value>
</setting>
<setting name="DiscordBotPrefixFixed" serializeAs="String">
<value>False</value>
</setting>
<setting name="DiscordBotLogLevel" serializeAs="String">
<value>Info</value>
</setting>
</ServerManagerTool.Config>
</userSettings>
</configuration>

View file

@ -280,7 +280,8 @@ namespace ServerManagerTool
}
if (!Config.Default.DiscordBotPrefixFixed)
{
Config.Default.DiscordBotPrefix += "!";
if (!Config.Default.DiscordBotPrefix.EndsWith("!"))
Config.Default.DiscordBotPrefix += "!";
Config.Default.DiscordBotPrefixFixed = true;
Config.Default.Save();
Config.Default.Reload();
@ -488,7 +489,7 @@ namespace ServerManagerTool
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);
await ServerManagerBotFactory.GetServerManagerBot()?.StartAsync(Config.Default.DiscordBotLogLevel, 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;

View file

@ -1980,7 +1980,7 @@ namespace ServerManagerTool {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("csm")]
[global::System.Configuration.DefaultSettingValueAttribute("csm!")]
public string DiscordBotPrefix {
get {
return ((string)(this["DiscordBotPrefix"]));
@ -2143,8 +2143,7 @@ namespace ServerManagerTool {
[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>")]
"org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" />")]
public global::System.Collections.Specialized.StringCollection DiscordBotWhitelist {
get {
return ((global::System.Collections.Specialized.StringCollection)(this["DiscordBotWhitelist"]));
@ -2165,5 +2164,17 @@ namespace ServerManagerTool {
this["DiscordBotPrefixFixed"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("Info")]
public global::ServerManagerTool.DiscordBot.Enums.LogLevel DiscordBotLogLevel {
get {
return ((global::ServerManagerTool.DiscordBot.Enums.LogLevel)(this["DiscordBotLogLevel"]));
}
set {
this["DiscordBotLogLevel"] = value;
}
}
}
}

View file

@ -549,7 +549,7 @@
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="DiscordBotPrefix" Type="System.String" Scope="User">
<Value Profile="(Default)">csm</Value>
<Value Profile="(Default)">csm!</Value>
</Setting>
<Setting Name="DiscordBotToken" Type="System.String" Scope="User">
<Value Profile="(Default)" />
@ -592,12 +592,13 @@
</Setting>
<Setting Name="DiscordBotWhitelist" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
&lt;string /&gt;
&lt;/ArrayOfString&gt;</Value>
&lt;ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" /&gt;</Value>
</Setting>
<Setting Name="DiscordBotPrefixFixed" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="DiscordBotLogLevel" Type="ServerManagerTool.DiscordBot.Enums.LogLevel" Scope="User">
<Value Profile="(Default)">Info</Value>
</Setting>
</Settings>
</SettingsFile>

View file

@ -57,12 +57,21 @@
<sys:String x:Key="ProcessorAffinity_All">All</sys:String>
<!--#endregion-->
<!--#region Processor Window States -->
<!--#region Window States -->
<sys:String x:Key="WindowState_Normal">Normal</sys:String>
<sys:String x:Key="WindowState_Minimized">Minimized</sys:String>
<sys:String x:Key="WindowState_Maximized">Maximized</sys:String>
<!--#endregion-->
<!--#region Discord Bot Log Levels -->
<sys:String x:Key="DiscordBotLogLevel_Critical">Critical</sys:String>
<sys:String x:Key="DiscordBotLogLevel_Error">Error</sys:String>
<sys:String x:Key="DiscordBotLogLevel_Warning">Warning</sys:String>
<sys:String x:Key="DiscordBotLogLevel_Info">Info</sys:String>
<sys:String x:Key="DiscordBotLogLevel_Verbose">Verbose</sys:String>
<sys:String x:Key="DiscordBotLogLevel_Debug">Debug</sys:String>
<!--#endregion-->
<!--#region Unit strings -->
<sys:String x:Key="SliderUnits_Multiplier">x</sys:String>
<sys:String x:Key="SliderUnits_Percentage">%</sys:String>
@ -780,6 +789,7 @@
<sys:String x:Key="GlobalSettings_DiscordBotServerTooltip">The id of the discord server the bot will listen to.</sys:String>
<sys:String x:Key="GlobalSettings_DiscordBotPrefixLabel">Prefix:</sys:String>
<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_DiscordBotLogLevelLabel">Log Level:</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>

View file

@ -566,6 +566,8 @@
<TextBox Grid.Row="2" Grid.Column="1" Margin="1" Text="{Binding Config.DiscordBotServerId}" IsReadOnlyCaretVisible="True" VerticalContentAlignment="Center" ToolTip="{DynamicResource GlobalSettings_DiscordBotServerTooltip}"/>
<Label Grid.Row="2" Grid.Column="3" Content="{DynamicResource GlobalSettings_DiscordBotPrefixLabel}" VerticalAlignment="Center"/>
<TextBox Grid.Row="2" Grid.Column="4" Margin="1" Text="{Binding Config.DiscordBotPrefix}" IsReadOnlyCaretVisible="True" VerticalContentAlignment="Center" ToolTip="{DynamicResource GlobalSettings_DiscordBotPrefixTooltip}"/>
<Label Grid.Row="2" Grid.Column="6" Margin="1" Content="{DynamicResource GlobalSettings_DiscordBotLogLevelLabel}" VerticalAlignment="Center"/>
<ComboBox Name="DiscordBotLogLevelComboBox" Grid.Row="2" Grid.Column="7" Margin="1" ItemsSource="{Binding ElementName=GlobalSettings, Path=DiscordBotLogLevels}" SelectedValue="{Binding Config.DiscordBotLogLevel}" SelectedValuePath="ValueMember" DisplayMemberPath="DisplayMember" VerticalContentAlignment="Center" PreviewMouseWheel="ComboBox_PreviewMouseWheel"/>
<CheckBox Grid.Row="3" Grid.Column="1" Margin="0,5,0,0" IsChecked="{Binding Config.AllowDiscordBackup}" Content="{DynamicResource ServerSettings_AllowDiscordBackupLabel}" HorizontalAlignment="Left" ToolTip="{DynamicResource GlobalSettings_DiscordBotAllowBackupTooltip}"/>
<CheckBox Grid.Row="3" Grid.Column="4" Margin="0,5,0,0" IsChecked="{Binding Config.AllowDiscordUpdate}" Content="{DynamicResource ServerSettings_AllowDiscordUpdateLabel}" HorizontalAlignment="Left" ToolTip="{DynamicResource GlobalSettings_DiscordBotAllowUpdateTooltip}"/>

View file

@ -32,6 +32,7 @@ namespace ServerManagerTool
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 DiscordBotLogLevelsProperty = DependencyProperty.Register(nameof(DiscordBotLogLevels), 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()
@ -42,7 +43,11 @@ namespace ServerManagerTool
this.IsAdministrator = SecurityUtils.IsAdministrator();
this.Version = GetDeployedVersion();
InitializeComponent();
WindowUtils.RemoveDefaultResourceDictionary(this, Config.Default.DefaultGlobalizationFile);
PopulateWindowsStatesComboBox();
PopulateDiscordBotLogLevelsComboBox();
DiscordBotWhitelist = new List<DiscordBotWhitelist>();
if (Config.DiscordBotWhitelist != null)
@ -53,9 +58,6 @@ namespace ServerManagerTool
}
}
InitializeComponent();
WindowUtils.RemoveDefaultResourceDictionary(this, Config.Default.DefaultGlobalizationFile);
this.DataContext = this;
}
@ -95,6 +97,12 @@ namespace ServerManagerTool
set;
}
public ComboBoxItemList DiscordBotLogLevels
{
get { return (ComboBoxItemList)GetValue(DiscordBotLogLevelsProperty); }
set { SetValue(DiscordBotLogLevelsProperty, value); }
}
public List<DiscordBotWhitelist> DiscordBotWhitelist
{
get { return (List<DiscordBotWhitelist>)GetValue(DiscordBotWhitelistProperty); }
@ -500,6 +508,24 @@ namespace ServerManagerTool
}
}
private void PopulateDiscordBotLogLevelsComboBox()
{
var selectedValue = this.DiscordBotLogLevelComboBox?.SelectedValue ?? Config.DiscordBotLogLevel;
var comboBoxList = new ComboBoxItemList();
foreach (DiscordBot.Enums.LogLevel logLevel in Enum.GetValues(typeof(DiscordBot.Enums.LogLevel)))
{
var displayMember = _globalizer.GetResourceString($"DiscordBotLogLevel_{logLevel}") ?? logLevel.ToString();
comboBoxList.Add(new Common.Model.ComboBoxItem(logLevel.ToString(), displayMember));
}
this.DiscordBotLogLevels = comboBoxList;
if (this.DiscordBotLogLevelComboBox != null)
{
this.DiscordBotLogLevelComboBox.SelectedValue = selectedValue;
}
}
#region Discord Bot Whitelist
private void AddDiscordBotWhitelist_Click(object sender, RoutedEventArgs e)
{

View file

@ -9,8 +9,8 @@
<entry>
<id>urn:uuid:19B09A66-43F2-4D5F-AF33-5C77D7EA9A6B</id>
<title>1.1.58 (1.1.58.4)</title>
<summary>1.1.58.4</summary>
<title>1.1.58 (1.1.58.5)</title>
<summary>1.1.58.5</summary>
<link href="" />
<updated>2021-12-16T00:00:00Z</updated>
<content type="xhtml">
@ -19,6 +19,7 @@
<u style="font-size: .9em;">NEW</u>
<br/>
<ul>
<li>Global Settings - Discord Bot section - Added a log level droplist.</li>
<li>Global Settings - Discord Bot section - Added a whitelist to allow bots to send commands to the server manager.</li>
<li>Server Settings - Discord Bot section - Added an alias that can be used with the discord command instead of the profile id.</li>
</ul>

View file

@ -7,6 +7,29 @@
<link href="http://servermanagers.freeforums.net/" />
<updated>2021-12-16T00:00:00Z</updated>
<entry>
<id>urn:uuid:A189668E-DA03-471A-9C5A-7FF2A7264F9C</id>
<title>1.1.58 (1.1.58.5)</title>
<summary>1.1.58.5</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 log level droplist.</li>
</ul>
</p>
</div>
</content>
<author>
<name>bletch</name>
<email>bletch1971@hotmail.com</email>
</author>
</entry>
<entry>
<id>urn:uuid:F3C22842-A089-46F7-AB1A-5D3DED105412</id>
<title>1.1.58 (1.1.58.4)</title>