From fe5e2cb80fbe29b1598bff9fc5fb22eb6677c63c Mon Sep 17 00:00:00 2001 From: runebaas Date: Sun, 6 May 2018 02:00:45 +0200 Subject: [PATCH] Create Enum for exit codes --- Geekbot.net/Lib/GeekbotExitCode.cs | 19 +++++++++++++++++++ .../Lib/Localization/TranslationHandler.cs | 8 ++++---- Geekbot.net/Program.cs | 8 ++++---- 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 Geekbot.net/Lib/GeekbotExitCode.cs diff --git a/Geekbot.net/Lib/GeekbotExitCode.cs b/Geekbot.net/Lib/GeekbotExitCode.cs new file mode 100644 index 0000000..e9e1210 --- /dev/null +++ b/Geekbot.net/Lib/GeekbotExitCode.cs @@ -0,0 +1,19 @@ +namespace Geekbot.net.Lib +{ + public enum GeekbotExitCode : int + { + // General + Clean = 0, + InvalidArguments = 1, + + // Geekbot Internals + TranslationsFailed = 201, + + // Dependent Services + RedisConnectionFailed = 301, + + // Discord Related + CouldNotLogin = 401 + + } +} \ No newline at end of file diff --git a/Geekbot.net/Lib/Localization/TranslationHandler.cs b/Geekbot.net/Lib/Localization/TranslationHandler.cs index e4af1e0..550759d 100644 --- a/Geekbot.net/Lib/Localization/TranslationHandler.cs +++ b/Geekbot.net/Lib/Localization/TranslationHandler.cs @@ -72,7 +72,7 @@ namespace Geekbot.net.Lib.Localization catch (Exception e) { _logger.Error(LogSource.Geekbot, "Failed to load Translations", e); - Environment.Exit(110); + Environment.Exit(GeekbotExitCode.TranslationsFailed.GetHashCode()); } } @@ -114,8 +114,8 @@ namespace Geekbot.net.Lib.Localization } catch (Exception e) { - _logger.Error(LogSource.Geekbot, "lol nope", e); - return new Dictionary(); + _logger.Error(LogSource.Geekbot, "No translations for command found", e); + return new Dictionary(); } } @@ -127,7 +127,7 @@ namespace Geekbot.net.Lib.Localization } catch (Exception e) { - _logger.Error(LogSource.Geekbot, "lol nope", e); + _logger.Error(LogSource.Geekbot, "No translations for command found", e); return new Dictionary(); } } diff --git a/Geekbot.net/Program.cs b/Geekbot.net/Program.cs index bc90b4f..3a35d19 100755 --- a/Geekbot.net/Program.cs +++ b/Geekbot.net/Program.cs @@ -43,7 +43,7 @@ namespace Geekbot.net RunParameters runParameters = null; Parser.Default.ParseArguments(args) .WithParsed(e => runParameters = e) - .WithNotParsed(_ => Environment.Exit(1)); + .WithNotParsed(_ => Environment.Exit(GeekbotExitCode.InvalidArguments.GetHashCode())); var logo = new StringBuilder(); logo.AppendLine(@" ____ _____ _____ _ ______ ___ _____"); @@ -90,10 +90,10 @@ namespace Geekbot.net catch (Exception e) { logger.Error(LogSource.Redis, "Redis Connection Failed", e); - Environment.Exit(102); + Environment.Exit(GeekbotExitCode.RedisConnectionFailed.GetHashCode()); } - _token = runParameters.Token ??_redis.StringGet("discordToken"); + _token = runParameters.Token ?? _redis.StringGet("discordToken"); if (_token.IsNullOrEmpty) { Console.Write("Your bot Token: "); @@ -187,7 +187,7 @@ namespace Geekbot.net catch (Exception e) { _logger.Error(LogSource.Geekbot, "Could not connect...", e); - Environment.Exit(103); + Environment.Exit(GeekbotExitCode.CouldNotLogin.GetHashCode()); } }