Added a checkbox to allow all bots.

This commit is contained in:
Brett Hewitson 2021-12-17 14:09:47 +10:00
parent 13713b7092
commit 06551d3c8e
22 changed files with 137 additions and 50 deletions

View file

@ -629,6 +629,9 @@
<setting name="DiscordBotLogLevel" serializeAs="String">
<value>Info</value>
</setting>
<setting name="DiscordBotAllowAllBots" serializeAs="String">
<value>False</value>
</setting>
</ServerManagerTool.Config>
</userSettings>
</configuration>

View file

@ -593,7 +593,7 @@ namespace ServerManagerTool
discordWhiteList.AddRange(Config.Default.DiscordBotWhitelist.Cast<string>());
}
await ServerManagerBotFactory.GetServerManagerBot()?.StartAsync(Config.Default.DiscordBotLogLevel, Config.Default.DiscordBotToken, Config.Default.DiscordBotPrefix, Config.Default.DataPath, discordWhiteList, DiscordBotHelper.HandleDiscordCommand, DiscordBotHelper.HandleTranslation, _tokenSourceDiscordBot.Token);
await ServerManagerBotFactory.GetServerManagerBot()?.StartAsync(Config.Default.DiscordBotLogLevel, Config.Default.DiscordBotToken, Config.Default.DiscordBotPrefix, Config.Default.DataPath, Config.Default.DiscordBotAllowAllBots, discordWhiteList, DiscordBotHelper.HandleDiscordCommand, DiscordBotHelper.HandleTranslation, _tokenSourceDiscordBot.Token);
if (_tokenSourceDiscordBot != null)
{

View file

@ -2185,5 +2185,17 @@ namespace ServerManagerTool {
return ((int)(this["DiscordBotStatusCheckTime"]));
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool DiscordBotAllowAllBots {
get {
return ((bool)(this["DiscordBotAllowAllBots"]));
}
set {
this["DiscordBotAllowAllBots"] = value;
}
}
}
}

View file

@ -603,5 +603,8 @@
<Setting Name="DiscordBotStatusCheckTime" Type="System.Int32" Scope="Application">
<Value Profile="(Default)">10</Value>
</Setting>
<Setting Name="DiscordBotAllowAllBots" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>

View file

@ -798,6 +798,8 @@
<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="ServerSettings_DiscordBotAllowAllBotsLabel">Allow All Bots</sys:String>
<sys:String x:Key="ServerSettings_DiscordBotAllowAllBotsTooltip">If enabled, the server manager bot will respond to all other bots, otherwise they will be ignored unless they are in the whitelist.</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>

View file

@ -534,12 +534,14 @@
<Grid IsEnabled="{Binding Config.DiscordBotEnabled}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto" MinHeight="25"/>
<RowDefinition Height="Auto" MinHeight="20"/>
<RowDefinition Height="Auto" MinHeight="20"/>
<RowDefinition Height="Auto" MinHeight="20"/>
<RowDefinition Height="Auto" MinHeight="20"/>
<RowDefinition Height="Auto" MinHeight="20"/>
<RowDefinition Height="Auto" MinHeight="20"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="60"/>
@ -577,7 +579,7 @@
<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 Grid.Row="5" Grid.Column="3" Grid.RowSpan="3" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" MinHeight="200" IsEnabled="{Binding Config.DiscordBotAllowAllBots, Converter={StaticResource InvertBooleanConverter}}">
<GroupBox.Header>
<StackPanel Orientation="Horizontal">
<Label Content="{DynamicResource GlobalSettings_DiscordBotWhitelistLabel}"/>
@ -625,6 +627,8 @@
</DataGrid.Columns>
</DataGrid>
</GroupBox>
<CheckBox Grid.Row="6" Grid.Column="1" Margin="0,5,0,5" IsChecked="{Binding Config.DiscordBotAllowAllBots}" Content="{DynamicResource ServerSettings_DiscordBotAllowAllBotsLabel}" HorizontalAlignment="Left" ToolTip="{DynamicResource ServerSettings_DiscordBotAllowAllBotsTooltip}"/>
</Grid>
</GroupBox>

View file

@ -165,7 +165,9 @@ namespace ServerManagerTool.Utils
else
{
var mapName = _globalizer.GetResourceString($"Map_{info.Map}") ?? info.Map;
response.Add($"```{info.Name}\n{_globalizer.GetResourceString("DiscordBot_MapLabel")} {mapName}\n{_globalizer.GetResourceString("ServerSettings_PlayersLabel")} {info.Players} / {info.MaxPlayers}```");
response.Add($"```{info.Name}\n" +
$"{_globalizer.GetResourceString("DiscordBot_MapLabel")} {mapName}\n" +
$"{_globalizer.GetResourceString("ServerSettings_PlayersLabel")} {info.Players} / {info.MaxPlayers}```");
}
}
}
@ -193,7 +195,10 @@ namespace ServerManagerTool.Utils
response.Add($"**{_globalizer.GetResourceString("DiscordBot_CountLabel")}** {serverList.Count()}");
foreach (var server in serverList)
{
response.Add($"```{_globalizer.GetResourceString("ServerSettings_ProfileIdLabel")} {server.Profile.ProfileID}\n{_globalizer.GetResourceString("ServerSettings_DiscordAliasLabel")} {server.Profile.DiscordAlias}\n{_globalizer.GetResourceString("ServerSettings_ProfileLabel")} {server.Profile.ProfileName}\n{_globalizer.GetResourceString("ServerSettings_ServerNameLabel")} {server.Profile.ServerName}```");
response.Add($"```{_globalizer.GetResourceString("ServerSettings_ProfileLabel")} {server.Profile.ProfileName}\n" +
$"{_globalizer.GetResourceString("ServerSettings_ProfileIdLabel")} {server.Profile.ProfileID}\n" +
(string.IsNullOrWhiteSpace(server.Profile.DiscordAlias) ? "" : $"{_globalizer.GetResourceString("ServerSettings_DiscordAliasLabel")} {server.Profile.DiscordAlias}\n") +
$"{_globalizer.GetResourceString("ServerSettings_ServerNameLabel")} {server.Profile.ServerName}```");
}
}).Wait();
@ -212,7 +217,12 @@ namespace ServerManagerTool.Utils
response.Add($"**{_globalizer.GetResourceString("DiscordBot_CountLabel")}** {serverList.Count()}");
foreach (var server in serverList)
{
response.Add($"```{_globalizer.GetResourceString("ServerSettings_ProfileLabel")} {server.Profile.ProfileName}\n{_globalizer.GetResourceString("ServerSettings_ServerNameLabel")} {server.Profile.ServerName}\n{_globalizer.GetResourceString("ServerSettings_StatusLabel")} {server.Runtime.StatusString}\n{_globalizer.GetResourceString("ServerSettings_AvailabilityLabel")} {_globalizer.GetResourceString($"ServerSettings_Availability_{server.Runtime.Availability}")}```");
response.Add($"```{_globalizer.GetResourceString("ServerSettings_ProfileLabel")} {server.Profile.ProfileName}\n" +
$"{_globalizer.GetResourceString("ServerSettings_ProfileIdLabel")} {server.Profile.ProfileID}\n" +
(string.IsNullOrWhiteSpace(server.Profile.DiscordAlias) ? "" : $"{_globalizer.GetResourceString("ServerSettings_DiscordAliasLabel")} {server.Profile.DiscordAlias}\n") +
$"{_globalizer.GetResourceString("ServerSettings_ServerNameLabel")} {server.Profile.ServerName}\n" +
$"{_globalizer.GetResourceString("ServerSettings_StatusLabel")} {server.Runtime.StatusString}\n" +
$"{_globalizer.GetResourceString("ServerSettings_AvailabilityLabel")} {_globalizer.GetResourceString($"ServerSettings_Availability_{server.Runtime.Availability}")}```");
}
}).Wait();

View file

@ -19,16 +19,17 @@
<u style="font-size: .9em;">NEW</u>
<br/>
<ul>
<li>Main Window - Added Discord Bot Status and a button to Stop/Start the discord bot.</li>
<li>Global Settings - Discord Bot section - Added a log level droplist.</li>
<li>Global Settings - Discord Bot section - Added a checkbox to allow all bots.</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>
<li>Main Window - Added Discord Bot Status and a button to Stop/Start the discord bot.</li>
</ul>
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>Made changes to the code to help improve performance.</li>
<li>Removed the mandatory requirement to enter the '!' after the discord prefix. The '!' has been added to the existing prefix so no change the existing functionality, but you can now change it.</li>
<li>Removed the mandatory requirement to enter the '!' after the discord prefix. The '!' has been added to the existing prefix so no change to existing functionality, but you can now change it.</li>
</ul>
</p>
</div>

View file

@ -20,6 +20,7 @@
<br/>
<ul>
<li>Main Window - Added Discord Bot Status and a button to Stop/Start the discord bot.</li>
<li>Global Settings - Discord Bot section - Added a checkbox to allow all bots.</li>
</ul>
</p>
</div>
@ -116,7 +117,7 @@
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>Removed the mandatory requirement to enter the '!' after the discord prefix. The '!' has been added to the existing prefix so no change the existing functionality, but you can now change it.</li>
<li>Removed the mandatory requirement to enter the '!' after the discord prefix. The '!' has been added to the existing prefix so no change to existing functionality, but you can now change it.</li>
</ul>
</p>
</div>