Never register bot with broken database, closes #265

This commit is contained in:
JustArchi
2016-06-27 00:38:38 +02:00
parent 788f5c94a2
commit 82c2d3ec15

View File

@@ -135,10 +135,15 @@ namespace ArchiSteamFarm {
throw new ArgumentNullException(nameof(botName));
}
BotName = botName;
if (Bots.ContainsKey(botName)) {
throw new Exception("That bot is already defined!");
}
string botPath = Path.Combine(Program.ConfigDirectory, botName);
BotName = botName;
SentryFile = botPath + ".bin";
BotConfig = BotConfig.Load(botPath + ".json");
if (BotConfig == null) {
Logging.LogGenericError("Your bot config is invalid, refusing to start this bot instance!", botName);
@@ -150,14 +155,6 @@ namespace ArchiSteamFarm {
return;
}
if (Bots.ContainsKey(botName)) {
throw new Exception("That bot is already defined!");
}
Bots[botName] = this;
SentryFile = botPath + ".bin";
BotDatabase = BotDatabase.Load(botPath + ".db");
if (BotDatabase == null) {
Logging.LogGenericError("Bot database could not be loaded, refusing to start this bot instance!", botName);
@@ -248,6 +245,9 @@ namespace ArchiSteamFarm {
);
}
// Register bot as available for ASF
Bots[botName] = this;
if (!BotConfig.StartOnLaunch) {
return;
}
@@ -993,6 +993,7 @@ namespace ArchiSteamFarm {
if (Bots.TryGetValue(botName, out bot)) {
return await bot.ResponseRedeem(steamID, message, validate).ConfigureAwait(false);
}
if (IsOwner(steamID)) {
return "Couldn't find any bot named " + botName + "!";
}