Added exception throw when token or prefix not valid.

This commit is contained in:
Brett Hewitson 2021-12-17 16:41:48 +10:00
parent 4ad6e4a5e9
commit b6781e1291
3 changed files with 11 additions and 4 deletions

View file

@ -5615,7 +5615,8 @@
<!--#region Discord Bot -->
<sys:String x:Key="DiscordBot_ErrorTitle">Discord Bot Error</sys:String>
<sys:String x:Key="DiscordBot_MissingTokenError">The discord bot requires a valid token so it can log into the discord server\r\nThis can be set in the global settings.</sys:String>
<sys:String x:Key="DiscordBot_MissingTokenError">The discord bot requires a valid token so it can log into the discord server.\r\nThis can be set in the global settings.</sys:String>
<sys:String x:Key="DiscordBot_MissingPrefixError">The discord bot requires a valid prefix.\r\nThis can be set in the global settings.</sys:String>
<sys:String x:Key="DiscordBot_InvalidPrefixError">The discord bot prefix contains invalid characters. Only letters and numbers are allowed.</sys:String>
<sys:String x:Key="DiscordBot_CommandNotEnabled">Command '{0}' has not been enabled.</sys:String>

View file

@ -1263,6 +1263,7 @@
<!--#region Discord Bot -->
<sys:String x:Key="DiscordBot_ErrorTitle">Discord Bot Error</sys:String>
<sys:String x:Key="DiscordBot_MissingTokenError">The discord bot requires a valid token so it can log into the discord server\r\nThis can be set in the global settings.</sys:String>
<sys:String x:Key="DiscordBot_MissingPrefixError">The discord bot requires a valid prefix.\r\nThis can be set in the global settings.</sys:String>
<sys:String x:Key="DiscordBot_InvalidPrefixError">The discord bot prefix contains invalid characters. Only letters and numbers are allowed.</sys:String>
<sys:String x:Key="DiscordBot_CommandNotEnabled">Command '{0}' has not been enabled.</sys:String>

View file

@ -30,12 +30,17 @@ namespace ServerManagerTool.DiscordBot
public async Task StartAsync(LogLevel logLevel, string discordToken, string commandPrefix, string dataDirectory, bool allowAllBots, IEnumerable<string> botWhitelist, HandleCommandDelegate handleCommandCallback, HandleTranslationDelegate handleTranslationCallback, CancellationToken token)
{
if (string.IsNullOrWhiteSpace(commandPrefix) || string.IsNullOrWhiteSpace(discordToken) || handleTranslationCallback is null || handleCommandCallback is null)
if (string.IsNullOrWhiteSpace(discordToken))
{
return;
throw new Exception("#DiscordBot_MissingTokenError");
}
if (Started)
if (string.IsNullOrWhiteSpace(commandPrefix))
{
throw new Exception("#DiscordBot_MissingPrefixError");
}
if (Started || handleTranslationCallback is null || handleCommandCallback is null)
{
return;
}