Code cleanup & improvements of previous pull request

This commit is contained in:
JustArchi 2015-11-18 22:10:24 +01:00
parent 499e55c473
commit fb2437d75d
2 changed files with 37 additions and 46 deletions

View file

@ -272,40 +272,29 @@ namespace ArchiSteamFarm {
}
private void ResponseStatus(ulong steamID) {
private void ResponseStatus(ulong steamID, string botName = null) {
if (steamID == 0) {
return;
}
if (CardsFarmer.CurrentGame > 0) {
SendMessageToUser(steamID, "Farming " + CardsFarmer.CurrentGame + " now");
SendMessageToUser(steamID, CardsFarmer.GamesLeft + " games left");
}
SendMessageToUser(steamID, "Currently " + Bots.Count + " bots are running");
Bot bot;
if (string.IsNullOrEmpty(botName)) {
bot = this;
} else {
if (!Bots.TryGetValue(botName, out bot)) {
SendMessageToUser(steamID, "Couldn't find any bot named " + botName + "!");
return;
}
}
if (bot.CardsFarmer.CurrentGame > 0) {
SendMessageToUser(steamID, "Bot " + bot.BotName + " is currently farming appID " + bot.CardsFarmer.CurrentGame + " and has total of " + bot.CardsFarmer.GamesLeft + " games left to farm");
}
SendMessageToUser(steamID, "Currently " + Bots.Count + " bots are running");
}
private void ResponseStatus(ulong steamID, string botName)
{
if (steamID == 0 || string.IsNullOrEmpty(botName))
{
return;
}
Bot botToGet;
if (!Bots.TryGetValue(botName, out botToGet))
{
SendMessageToUser(steamID, "Running bot with this name not found!");
return;
}
if (botToGet.CardsFarmer.CurrentGame > 0)
{
SendMessageToUser(steamID, "Bot " + botName + " farming " + botToGet.CardsFarmer.CurrentGame +" now");
SendMessageToUser(steamID, "Bot " + botName + " has " + botToGet.CardsFarmer.GamesLeft + " games left");
}
SendMessageToUser(steamID, "Currently " + Bots.Count + " bots are running");
}
private void ResponseStart(ulong steamID, string botNameToStart) {
private void ResponseStart(ulong steamID, string botNameToStart) {
if (steamID == 0 || string.IsNullOrEmpty(botNameToStart)) {
return;
}
@ -479,10 +468,10 @@ namespace ArchiSteamFarm {
case "!stop":
await ResponseStop(steamID, args[1]).ConfigureAwait(false);
break;
case "!status":
ResponseStatus(steamID, args[1]);
break;
}
case "!status":
ResponseStatus(steamID, args[1]);
break;
}
}
}

View file

@ -29,14 +29,15 @@ using System.Threading.Tasks;
namespace ArchiSteamFarm {
internal class CardsFarmer {
internal ulong CurrentGame { get; private set; } = 0;
internal int GamesLeft { get; private set; } = 0;
private const byte StatusCheckSleep = 5; // In minutes, how long to wait before checking the appID again
private readonly ManualResetEvent FarmResetEvent = new ManualResetEvent(false);
private readonly SemaphoreSlim Semaphore = new SemaphoreSlim(1);
private readonly Bot Bot;
internal uint CurrentGame { get; private set; } = 0;
internal int GamesLeft { get; private set; } = 0;
private volatile bool NowFarming = false;
internal CardsFarmer(Bot bot) {
@ -111,25 +112,26 @@ namespace ArchiSteamFarm {
NowFarming = appIDs.Count > 0;
Semaphore.Release();
GamesLeft = appIDs.Count;
// Start farming
while (appIDs.Count > 0) {
GamesLeft = appIDs.Count;
uint appID = appIDs[0];
uint appID = appIDs[0];
CurrentGame = appID;
Logging.LogGenericInfo(Bot.BotName, "Now farming: " + appID);
CurrentGame = appID;
if (await Farm(appID).ConfigureAwait(false)) {
if (await Farm(appID).ConfigureAwait(false)) {
appIDs.Remove(appID);
GamesLeft--;
} else {
GamesLeft = 0;
CurrentGame = 0;
NowFarming = false;
GamesLeft = 0;
CurrentGame = 0;
NowFarming = false;
return;
}
}
GamesLeft = 0;
CurrentGame = 0;
NowFarming = false;
CurrentGame = 0;
NowFarming = false;
Logging.LogGenericInfo(Bot.BotName, "Farming finished!");
await Bot.OnFarmingFinished().ConfigureAwait(false);
}
@ -183,5 +185,5 @@ namespace ArchiSteamFarm {
Logging.LogGenericInfo(Bot.BotName, "Stopped farming: " + appID);
return success;
}
}
}
}